Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
model_name: ssd-10.onnx
|
| 5 |
+
tags:
|
| 6 |
+
- validated
|
| 7 |
+
- vision
|
| 8 |
+
- object_detection_segmentation
|
| 9 |
+
- ssd
|
| 10 |
+
---
|
| 11 |
+
<!--- SPDX-License-Identifier: Apache-2.0 -->
|
| 12 |
+
|
| 13 |
+
# Single Stage Detector
|
| 14 |
+
|
| 15 |
+
## Description
|
| 16 |
+
This model is a real-time neural network for object detection that detects 80 different classes.
|
| 17 |
+
|
| 18 |
+
## Model
|
| 19 |
+
|
| 20 |
+
|Model |Download | Download (with sample test data)|ONNX version|Opset version|Accuracy |
|
| 21 |
+
|-------------|:--------------|:--------------|:--------------|:--------------|:--------------|
|
| 22 |
+
|SSD |[80.4 MB](model/ssd-10.onnx) | [78.5 MB](model/ssd-10.tar.gz) |1.5 |10 |mAP of 0.195 |
|
| 23 |
+
|SSD |[77.6 MB](model/ssd-12.onnx) | [86.4 MB](model/ssd-12.tar.gz) |1.9 |12 |mAP of 0.1898 |
|
| 24 |
+
|SSD-int8|[20 MB](model/ssd-12-int8.onnx) | [31 MB](model/ssd-12-int8.tar.gz) |1.9 |12 |mAP of 0.1892 |
|
| 25 |
+
|SSD-qdq|[20 MB](model/ssd-12-qdq.onnx) | [26 MB](model/ssd-12-qdq.tar.gz) |1.9 |12 |mAP of 0.1863 |
|
| 26 |
+
|
| 27 |
+
> Compared with the fp32 SSD, SSD-int8's mAP drop ratio is 0.32% and performance improvement is 3.49x.
|
| 28 |
+
>
|
| 29 |
+
> **Note**
|
| 30 |
+
>
|
| 31 |
+
> The performance depends on the test hardware. Performance data here is collected with Intel® Xeon® Platinum 8280 Processor, 1s 4c per instance, CentOS Linux 8.3, data batch size is 1.
|
| 32 |
+
|
| 33 |
+
<hr>
|
| 34 |
+
|
| 35 |
+
## Inference
|
| 36 |
+
|
| 37 |
+
### Input to model
|
| 38 |
+
Image shape `(1x3x1200x1200)`
|
| 39 |
+
|
| 40 |
+
### Preprocessing steps
|
| 41 |
+
The images have to be loaded in to a range of [0, 1], resized to (1200, 1200) with bilinear interpolation and then normalized using mean = [0.485, 0.456, 0.406] and std = [0.229, 0.224, 0.225]. The transformation should preferrably happen at preprocessing.
|
| 42 |
+
|
| 43 |
+
The following code shows how to preprocess a NCHW tensor:
|
| 44 |
+
|
| 45 |
+
```python
|
| 46 |
+
import numpy as np
|
| 47 |
+
from PIL import Image
|
| 48 |
+
|
| 49 |
+
def preprocess(img_path):
|
| 50 |
+
input_shape = (1, 3, 1200, 1200)
|
| 51 |
+
img = Image.open(img_path)
|
| 52 |
+
img = img.resize((1200, 1200), Image.BILINEAR)
|
| 53 |
+
img_data = np.array(img)
|
| 54 |
+
img_data = np.transpose(img_data, [2, 0, 1])
|
| 55 |
+
img_data = np.expand_dims(img_data, 0)
|
| 56 |
+
mean_vec = np.array([0.485, 0.456, 0.406])
|
| 57 |
+
stddev_vec = np.array([0.229, 0.224, 0.225])
|
| 58 |
+
norm_img_data = np.zeros(img_data.shape).astype('float32')
|
| 59 |
+
for i in range(img_data.shape[1]):
|
| 60 |
+
norm_img_data[:,i,:,:] = (img_data[:,i,:,:]/255 - mean_vec[i]) / stddev_vec[i]
|
| 61 |
+
return norm_img_data
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
### Output of model
|
| 65 |
+
The model has 3 outputs.
|
| 66 |
+
boxes: `(1x'nbox'x4)`
|
| 67 |
+
labels: `(1x'nbox')`
|
| 68 |
+
scores: `(1x'nbox')`
|
| 69 |
+
|
| 70 |
+
<!-- ### Postprocessing steps
|
| 71 |
+
Post processing and meaning of output
|
| 72 |
+
<hr> -->
|
| 73 |
+
|
| 74 |
+
## Dataset (Train and validation)
|
| 75 |
+
The SSD model was trained on 2017 COCO train data set - using mlperf/training/single_stage_detector repo , compute mAP on 2017 COCO val data set.
|
| 76 |
+
<hr>
|
| 77 |
+
|
| 78 |
+
## Validation accuracy
|
| 79 |
+
Metric is COCO box mAP (averaged over IoU of 0.5:0.95), computed over 2017 COCO val data.
|
| 80 |
+
mAP of 0.195
|
| 81 |
+
<hr>
|
| 82 |
+
|
| 83 |
+
## Publication/Attribution
|
| 84 |
+
Wei Liu, Dragomir Anguelov, Dumitru Erhan, Christian Szegedy, Scott Reed, Cheng-Yang Fu, Alexander C. Berg. SSD: Single Shot MultiBox Detector. In the Proceedings of the European Conference on Computer Vision (ECCV), 2016.
|
| 85 |
+
|
| 86 |
+
Backbone is ResNet34 pretrained on ILSVRC 2012 (from torchvision). Modifications to the backbone networks: remove conv_5x residual blocks, change the first 3x3 convolution of the conv_4x block from stride 2 to stride1 (this increases the resolution of the feature map to which detector heads are attached), attach all 6 detector heads to the output of the last conv_4x residual block. Thus detections are attached to 38x38, 19x19, 10x10, 5x5, 3x3, and 1x1 feature maps. Convolutions in the detector layers are followed by batch normalization layers.
|
| 87 |
+
<hr>
|
| 88 |
+
|
| 89 |
+
## Quantization
|
| 90 |
+
SSD-int8 and SSD-qdq are obtained by quantizing fp32 SSD 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/ssd/quantization/ptq/README.md) to understand how to use Intel® Neural Compressor for quantization.
|
| 91 |
+
|
| 92 |
+
### Environment
|
| 93 |
+
onnx: 1.9.0
|
| 94 |
+
onnxruntime: 1.8.0
|
| 95 |
+
|
| 96 |
+
### Prepare model
|
| 97 |
+
```shell
|
| 98 |
+
wget https://github.com/onnx/models/raw/main/vision/object_detection_segmentation/ssd/model/ssd-12.onnx
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
### Model quantize
|
| 102 |
+
Make sure to specify the appropriate dataset path in the configuration file.
|
| 103 |
+
```bash
|
| 104 |
+
bash run_tuning.sh --input_model=path/to/model \ # model path as *.onnx
|
| 105 |
+
--config=ssd.yaml \
|
| 106 |
+
--output_model=path/to/save
|
| 107 |
+
```
|
| 108 |
+
<hr>
|
| 109 |
+
|
| 110 |
+
## References
|
| 111 |
+
* This model is converted from mlperf/inference [repository](https://github.com/mlperf/inference/tree/master/others/cloud/single_stage_detector) with modifications in [repository](https://github.com/BowenBao/inference/tree/master/cloud/single_stage_detector/pytorch).
|
| 112 |
+
|
| 113 |
+
* [Intel® Neural Compressor](https://github.com/intel/neural-compressor)
|
| 114 |
+
<hr>
|
| 115 |
+
|
| 116 |
+
## Contributors
|
| 117 |
+
* [mengniwang95](https://github.com/mengniwang95) (Intel)
|
| 118 |
+
* [yuwenzho](https://github.com/yuwenzho) (Intel)
|
| 119 |
+
* [airMeng](https://github.com/airMeng) (Intel)
|
| 120 |
+
* [ftian1](https://github.com/ftian1) (Intel)
|
| 121 |
+
* [hshen14](https://github.com/hshen14) (Intel)
|
| 122 |
+
<hr>
|
| 123 |
+
|
| 124 |
+
## License
|
| 125 |
+
Apache License 2.0
|
| 126 |
+
<hr>
|
| 127 |
+
|