jemartin commited on
Commit
c6b1810
·
verified ·
1 Parent(s): cd59f67

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +176 -0
README.md ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: apache-2.0
4
+ model_name: FasterRCNN-10.onnx
5
+ tags:
6
+ - validated
7
+ - vision
8
+ - object_detection_segmentation
9
+ - faster-rcnn
10
+ ---
11
+ <!--- SPDX-License-Identifier: MIT -->
12
+
13
+ # Faster R-CNN
14
+
15
+ ## Description
16
+ This model is a real-time neural network for object detection that detects 80 different [classes](dependencies/coco_classes.txt).
17
+
18
+ ## Model
19
+
20
+ |Model |Download | Download (with sample test data)|ONNX version|Opset version|Accuracy |
21
+ |-------------|:--------------|:--------------|:--------------|:--------------|:--------------|
22
+ |Faster R-CNN R-50-FPN |[167.3 MB](model/FasterRCNN-10.onnx) |[158.0 MB](model/FasterRCNN-10.tar.gz) |1.5 |10 |mAP of 0.35 |
23
+ |Faster R-CNN R-50-FPN-fp32 |[168.5 MB](model/FasterRCNN-12.onnx) |[156.2 MB](model/FasterRCNN-12.tar.gz) |1.9 |12 |mAP of 0.3437 |
24
+ |Faster R-CNN R-50-FPN-int8 |[42.6 MB](model/FasterRCNN-12-int8.onnx) |[36.2 MB](model/FasterRCNN-12-int8.tar.gz) |1.9 |12 |mAP of 0.3409 |
25
+ |Faster R-CNN R-50-FPN-qdq |[43 MB](model/FasterRCNN-12-qdq.onnx) |[29 MB](model/FasterRCNN-12-qdq.tar.gz) |1.9 |12 |mAP of 0.3390 |
26
+ > Compared with the fp32 FasterRCNN-12, int8 FasterRCNN-12's mAP decline ratio is 0.81% and performance improvement is 1.43x.
27
+ >
28
+ > Note the performance depends on the test hardware.
29
+ >
30
+ > Performance data here is collected with Intel® Xeon® Platinum 8280 Processor, 1s 4c per instance, CentOS Linux 8.3, data batch size is 1.
31
+
32
+
33
+ <hr>
34
+
35
+ ## Inference
36
+
37
+ ### Input to model
38
+ Image shape `(3x'height'x'width')`
39
+
40
+ ### Preprocessing steps
41
+ The images have to be loaded in to a range of [0, 255], resized, converted to BGR and then normalized using mean = [102.9801, 115.9465, 122.7717]. The transformation should preferably happen at preprocessing.
42
+
43
+ This model can take images of different sizes as input. However, to achieve best performance, it is recommended to resize the image such that both height and width are within the range of [800, 1333], and then pad the image with zeros such that both height and width are divisible by 32.
44
+
45
+ The following code shows how to preprocess the [demo image](dependencies/demo.jpg):
46
+
47
+ ```python
48
+ import numpy as np
49
+ from PIL import Image
50
+
51
+ def preprocess(image):
52
+ # Resize
53
+ ratio = 800.0 / min(image.size[0], image.size[1])
54
+ image = image.resize((int(ratio * image.size[0]), int(ratio * image.size[1])), Image.BILINEAR)
55
+
56
+ # Convert to BGR
57
+ image = np.array(image)[:, :, [2, 1, 0]].astype('float32')
58
+
59
+ # HWC -> CHW
60
+ image = np.transpose(image, [2, 0, 1])
61
+
62
+ # Normalize
63
+ mean_vec = np.array([102.9801, 115.9465, 122.7717])
64
+ for i in range(image.shape[0]):
65
+ image[i, :, :] = image[i, :, :] - mean_vec[i]
66
+
67
+ # Pad to be divisible of 32
68
+ import math
69
+ padded_h = int(math.ceil(image.shape[1] / 32) * 32)
70
+ padded_w = int(math.ceil(image.shape[2] / 32) * 32)
71
+
72
+ padded_image = np.zeros((3, padded_h, padded_w), dtype=np.float32)
73
+ padded_image[:, :image.shape[1], :image.shape[2]] = image
74
+ image = padded_image
75
+
76
+ return image
77
+
78
+ img = Image.open('dependencies/demo.jpg')
79
+ img_data = preprocess(img)
80
+ ```
81
+
82
+ ### Output of model
83
+ The model has 3 outputs.
84
+
85
+ boxes: `('nbox'x4)`, in `(xmin, ymin, xmax, ymax)`.
86
+
87
+ labels: `('nbox')`.
88
+
89
+ scores: `('nbox')`.
90
+
91
+ ### Postprocessing steps
92
+
93
+ The following code shows how to patch the original image with detections and class annotations, filtered by scores:
94
+
95
+ ```python
96
+ import matplotlib.pyplot as plt
97
+ import matplotlib.patches as patches
98
+
99
+ classes = [line.rstrip('\n') for line in open('coco_classes.txt')]
100
+
101
+ def display_objdetect_image(image, boxes, labels, scores, score_threshold=0.7):
102
+ # Resize boxes
103
+ ratio = 800.0 / min(image.size[0], image.size[1])
104
+ boxes /= ratio
105
+
106
+ _, ax = plt.subplots(1, figsize=(12,9))
107
+ image = np.array(image)
108
+ ax.imshow(image)
109
+
110
+ # Showing boxes with score > 0.7
111
+ for box, label, score in zip(boxes, labels, scores):
112
+ if score > score_threshold:
113
+ rect = patches.Rectangle((box[0], box[1]), box[2] - box[0], box[3] - box[1], linewidth=1, edgecolor='b', facecolor='none')
114
+ ax.annotate(classes[label] + ':' + str(np.round(score, 2)), (box[0], box[1]), color='w', fontsize=12)
115
+ ax.add_patch(rect)
116
+ plt.show()
117
+
118
+ display_objdetect_image(img, boxes, labels, scores)
119
+ ```
120
+
121
+
122
+
123
+ ## Dataset (Train and validation)
124
+ The original pretrained Faster R-CNN model is from [facebookresearch/maskrcnn-benchmark](https://github.com/facebookresearch/maskrcnn-benchmark), compute mAP the same as [Detectron](https://github.com/facebookresearch/Detectron) on `coco_2014_minival` dataset from COCO, which is exactly equivalent to the `coco_2017_val` dataset.
125
+ <hr>
126
+
127
+ ## Validation accuracy
128
+ Metric is COCO box mAP (averaged over IoU of 0.5:0.95), computed over 2017 COCO val data.
129
+ mAP of 0.353
130
+ <hr>
131
+
132
+ ## Quantization
133
+ Faster R-CNN R-50-FPN-int8 and Faster R-CNN R-50-FPN-qdq are obtained by quantizing Faster R-CNN R-50-FPN-fp32 model. We use [Intel® Neural Compressor](https://github.com/intel/neural-compressor) with onnxruntime backend to perform quantization. View the [instructions](https://github.com/intel/neural-compressor/blob/master/examples/onnxrt/object_detection/onnx_model_zoo/faster_rcnn/quantization/ptq/README.md) to understand how to use Intel® Neural Compressor for quantization.
134
+
135
+ ### Environment
136
+ onnx: 1.9.0
137
+ onnxruntime: 1.8.0
138
+
139
+ ### Prepare model
140
+ ```shell
141
+ wget https://github.com/onnx/models/raw/main/vision/object_detection_segmentation/faster-rcnn/model/FasterRCNN-12.onnx
142
+ ```
143
+
144
+ ### Model quantize
145
+ ```bash
146
+ bash run_tuning.sh --input_model=path/to/model \ # model path as *.onnx
147
+ --config=faster_rcnn.yaml \
148
+ --data_path=path/to/COCO2017 \
149
+ --output_model=path/to/save
150
+ ```
151
+ <hr>
152
+
153
+ ## Publication/Attribution
154
+ Shaoqing Ren, Kaiming He, Ross Girshick, and Jian Sun. Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks. Conference on Neural Information Processing Systems (NIPS), 2015.
155
+
156
+ Massa, Francisco and Girshick, Ross. maskrcnn-benchmark: Fast, modular reference implementation of Instance Segmentation and Object Detection algorithms in PyTorch. [facebookresearch/maskrcnn-benchmark](https://github.com/facebookresearch/maskrcnn-benchmark).
157
+ <hr>
158
+
159
+ ## References
160
+ * This model is converted from [facebookresearch/maskrcnn-benchmark](https://github.com/facebookresearch/maskrcnn-benchmark) with modifications in [repository](https://github.com/BowenBao/maskrcnn-benchmark/tree/onnx_stage).
161
+
162
+ * [Intel® Neural Compressor](https://github.com/intel/neural-compressor)
163
+ <hr>
164
+
165
+ ## Contributors
166
+ * [mengniwang95](https://github.com/mengniwang95) (Intel)
167
+ * [yuwenzho](https://github.com/yuwenzho) (Intel)
168
+ * [airMeng](https://github.com/airMeng) (Intel)
169
+ * [ftian1](https://github.com/ftian1) (Intel)
170
+ * [hshen14](https://github.com/hshen14) (Intel)
171
+ <hr>
172
+
173
+ ## License
174
+ MIT License
175
+ <hr>
176
+