Image Classification
Transformers
resnet
Inference Endpoints
mchochowski commited on
Commit
2d3a875
1 Parent(s): cc5ac51

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +99 -0
README.md CHANGED
@@ -14,3 +14,102 @@ widget:
14
  - src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/palace.jpg
15
  example_title: Palace
16
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  - src: https://huggingface.co/datasets/mishig/sample_images/resolve/main/palace.jpg
15
  example_title: Palace
16
  ---
17
+
18
+ ### Model Description
19
+
20
+ The ***ResNet50 v1.5*** model is a modified version of the [original ResNet50 v1 model](https://arxiv.org/abs/1512.03385).
21
+
22
+ The difference between v1 and v1.5 is that, in the bottleneck blocks which requires
23
+ downsampling, v1 has stride = 2 in the first 1x1 convolution, whereas v1.5 has stride = 2 in the 3x3 convolution.
24
+
25
+ This difference makes ResNet50 v1.5 slightly more accurate (\~0.5% top1) than v1, but comes with a smallperformance drawback (\~5% imgs/sec).
26
+
27
+ The model is initialized as described in [Delving deep into rectifiers: Surpassing human-level performance on ImageNet classification](https://arxiv.org/pdf/1502.01852.pdf)
28
+
29
+ This model is trained with mixed precision using Tensor Cores on Volta, Turing, and the NVIDIA Ampere GPU architectures. Therefore, researchers can get results over 2x faster than training without Tensor Cores, while experiencing the benefits of mixed precision training. This model is tested against each NGC monthly container release to ensure consistent accuracy and performance over time.
30
+
31
+ Note that the ResNet50 v1.5 model can be deployed for inference on the [NVIDIA Triton Inference Server](https://github.com/NVIDIA/trtis-inference-server) using TorchScript, ONNX Runtime or TensorRT as an execution backend. For details check [NGC](https://ngc.nvidia.com/catalog/resources/nvidia:resnet_for_triton_from_pytorch)
32
+
33
+
34
+ ### Example
35
+
36
+ In the example below we will use the pretrained ***ResNet50 v1.5*** model to perform inference on ***image*** and present the result.
37
+
38
+ To run the example you need some extra python packages installed. These are needed for preprocessing images and visualization.
39
+ ```python
40
+ !pip install validators matplotlib
41
+ ```
42
+
43
+ ```python
44
+ import torch
45
+ from PIL import Image
46
+ import torchvision.transforms as transforms
47
+ import numpy as np
48
+ import json
49
+ import requests
50
+ import matplotlib.pyplot as plt
51
+ import warnings
52
+ warnings.filterwarnings('ignore')
53
+ %matplotlib inline
54
+
55
+ device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
56
+ print(f'Using {device} for inference')
57
+ ```
58
+
59
+ Load the model pretrained on IMAGENET dataset.
60
+ ```python
61
+ resnet50 = torch.hub.load('NVIDIA/DeepLearningExamples:torchhub', 'nvidia_resnet50', pretrained=True)
62
+ utils = torch.hub.load('NVIDIA/DeepLearningExamples:torchhub', 'nvidia_convnets_processing_utils')
63
+
64
+ resnet50.eval().to(device)
65
+ ```
66
+
67
+ Prepare sample input data.
68
+ ```python
69
+ uris = [
70
+ 'http://images.cocodataset.org/test-stuff2017/000000024309.jpg',
71
+ 'http://images.cocodataset.org/test-stuff2017/000000028117.jpg',
72
+ 'http://images.cocodataset.org/test-stuff2017/000000006149.jpg',
73
+ 'http://images.cocodataset.org/test-stuff2017/000000004954.jpg',
74
+ ]
75
+
76
+ batch = torch.cat(
77
+ [utils.prepare_input_from_uri(uri) for uri in uris]
78
+ ).to(device)
79
+ ```
80
+
81
+ Run inference. Use `pick_n_best(predictions=output, n=topN)` helepr function to pick N most probably hypothesis according to the model.
82
+ ```python
83
+ with torch.no_grad():
84
+ output = torch.nn.functional.softmax(resnet50(batch), dim=1)
85
+
86
+ results = utils.pick_n_best(predictions=output, n=5)
87
+ ```
88
+
89
+ Display the result.
90
+ ```python
91
+ for uri, result in zip(uris, results):
92
+ img = Image.open(requests.get(uri, stream=True).raw)
93
+ img.thumbnail((256,256), Image.ANTIALIAS)
94
+ plt.imshow(img)
95
+ plt.show()
96
+ print(result)
97
+
98
+ ```
99
+
100
+ ### Details
101
+ For detailed information on model input and output, training recipies, inference and performance visit:
102
+ [github](https://github.com/NVIDIA/DeepLearningExamples/tree/master/PyTorch/Classification/ConvNets/resnet50v1.5)
103
+ and/or [NGC](https://ngc.nvidia.com/catalog/resources/nvidia:resnet_50_v1_5_for_pytorch)
104
+
105
+ ### References
106
+
107
+ - [Original ResNet50 v1 paper](https://arxiv.org/abs/1512.03385)
108
+ - [Delving deep into rectifiers: Surpassing human-level performance on ImageNet classification](https://arxiv.org/pdf/1502.01852.pdf)
109
+ - [model on github](https://github.com/NVIDIA/DeepLearningExamples/tree/master/PyTorch/Classification/ConvNets/resnet50v1.5)
110
+ - [model on NGC](https://ngc.nvidia.com/catalog/resources/nvidia:resnet_50_v1_5_for_pytorch)
111
+ - [pretrained model on NGC](https://ngc.nvidia.com/catalog/models/nvidia:resnet50_pyt_amp)
112
+
113
+ ```python
114
+
115
+ ```