ytfeng commited on
Commit
9408415
·
2 Parent(s): 6c778a5 d33294b

Merge pull request #46 from fengyuentau/add_mobilenet_v1_v2

Browse files
README.md CHANGED
@@ -23,6 +23,8 @@ Guidelines:
23
  | [CRNN-EN](./models/text_recognition_crnn) | 100x32 | 50.21 | 234.32 | 196.15 | 125.30 | --- |
24
  | [CRNN-CN](./models/text_recognition_crnn) | 100x32 | 73.52 | 322.16 | 239.76 | 166.79 | --- |
25
  | [PP-ResNet](./models/image_classification_ppresnet) | 224x224 | 56.05 | 602.58 | 98.64 | 75.45 | --- |
 
 
26
  | [PP-HumanSeg](./models/human_segmentation_pphumanseg) | 192x192 | 19.92 | 105.32 | 67.97 | 74.77 | --- |
27
  | [WeChatQRCode](./models/qrcode_wechatqrcode) | 100x100 | 7.04 | 37.68 | --- | --- | --- |
28
  | [DaSiamRPN](./models/object_tracking_dasiamrpn) | 1280x720 | 36.15 | 705.48 | 76.82 | --- | --- |
 
23
  | [CRNN-EN](./models/text_recognition_crnn) | 100x32 | 50.21 | 234.32 | 196.15 | 125.30 | --- |
24
  | [CRNN-CN](./models/text_recognition_crnn) | 100x32 | 73.52 | 322.16 | 239.76 | 166.79 | --- |
25
  | [PP-ResNet](./models/image_classification_ppresnet) | 224x224 | 56.05 | 602.58 | 98.64 | 75.45 | --- |
26
+ | [MobileNet-V1](./models/image_classification_mobilenet)| 224x224 | 7.76 | 85.09 | 20.78 | 45.78 | --- |
27
+ | [MobileNet-V2](./models/image_classification_mobilenet)| 224x224 | 7.48 | 74.45 | 23.92 | 104.05 | --- |
28
  | [PP-HumanSeg](./models/human_segmentation_pphumanseg) | 192x192 | 19.92 | 105.32 | 67.97 | 74.77 | --- |
29
  | [WeChatQRCode](./models/qrcode_wechatqrcode) | 100x100 | 7.04 | 37.68 | --- | --- | --- |
30
  | [DaSiamRPN](./models/object_tracking_dasiamrpn) | 1280x720 | 36.15 | 705.48 | 76.82 | --- | --- |
benchmark/config/image_classification_mobilenetv1.yaml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Benchmark:
2
+ name: "Image Classification Benchmark"
3
+ type: "Classification"
4
+ data:
5
+ path: "benchmark/data/image_classification"
6
+ files: ["coffee_mug.jpg", "umbrella.jpg", "wall_clock.jpg"]
7
+ sizes: [[256, 256]]
8
+ toRGB: True
9
+ centerCrop: 224
10
+ metric:
11
+ warmup: 30
12
+ repeat: 10
13
+ reduction: "median"
14
+ backend: "default"
15
+ target: "cpu"
16
+
17
+ Model:
18
+ name: "MobileNetV1"
19
+ modelPath: "models/image_classification_mobilenet/mobilenet_v1.onnx"
20
+ labelPath: "models/image_classification_mobilenet/imagenet_labels.txt"
benchmark/config/image_classification_mobilenetv2.yaml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Benchmark:
2
+ name: "Image Classification Benchmark"
3
+ type: "Classification"
4
+ data:
5
+ path: "benchmark/data/image_classification"
6
+ files: ["coffee_mug.jpg", "umbrella.jpg", "wall_clock.jpg"]
7
+ sizes: [[256, 256]]
8
+ toRGB: True
9
+ centerCrop: 224
10
+ metric:
11
+ warmup: 30
12
+ repeat: 10
13
+ reduction: "median"
14
+ backend: "default"
15
+ target: "cpu"
16
+
17
+ Model:
18
+ name: "MobileNetV2"
19
+ modelPath: "models/image_classification_mobilenet/mobilenet_v2.onnx"
20
+ labelPath: "models/image_classification_mobilenet/imagenet_labels.txt"
models/__init__.py CHANGED
@@ -7,6 +7,8 @@ from .human_segmentation_pphumanseg.pphumanseg import PPHumanSeg
7
  from .qrcode_wechatqrcode.wechatqrcode import WeChatQRCode
8
  from .object_tracking_dasiamrpn.dasiamrpn import DaSiamRPN
9
  from .person_reid_youtureid.youtureid import YoutuReID
 
 
10
 
11
  class Registery:
12
  def __init__(self, name):
@@ -28,4 +30,7 @@ MODELS.register(PPResNet)
28
  MODELS.register(PPHumanSeg)
29
  MODELS.register(WeChatQRCode)
30
  MODELS.register(DaSiamRPN)
31
- MODELS.register(YoutuReID)
 
 
 
 
7
  from .qrcode_wechatqrcode.wechatqrcode import WeChatQRCode
8
  from .object_tracking_dasiamrpn.dasiamrpn import DaSiamRPN
9
  from .person_reid_youtureid.youtureid import YoutuReID
10
+ from .image_classification_mobilenet.mobilenet_v1 import MobileNetV1
11
+ from .image_classification_mobilenet.mobilenet_v2 import MobileNetV2
12
 
13
  class Registery:
14
  def __init__(self, name):
 
30
  MODELS.register(PPHumanSeg)
31
  MODELS.register(WeChatQRCode)
32
  MODELS.register(DaSiamRPN)
33
+ MODELS.register(YoutuReID)
34
+ MODELS.register(MobileNetV1)
35
+ MODELS.register(MobileNetV2)
36
+
models/image_classification_mobilenet/LICENSE ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2017-, Shicai Yang
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ * Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
models/image_classification_mobilenet/README.md ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # MobileNets
2
+
3
+ MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications
4
+
5
+ MobileNetV2: Inverted Residuals and Linear Bottlenecks
6
+
7
+ Models are taken from https://github.com/shicai/MobileNet-Caffe and converted to ONNX format using [caffe2onnx](https://github.com/asiryan/caffe2onnx):
8
+ ```
9
+ python -m caffe2onnx.convert --prototxt mobilenet_deploy.prototxt --caffemodel mobilenet.caffemodel --onnx mobilenet_v1.onnx
10
+ python -m caffe2onnx.convert --prototxt mobilenet_v2_deploy.prototxt --caffemodel mobilenet_v2.caffemodel --onnx mobilenet_v2.onnx
11
+ ```
12
+
13
+ NOTE: Quantized MobileNet V1 & V2 have a great drop in accuracy. We are working on producing higher accuracy MobileNets.
14
+
15
+ ## Demo
16
+
17
+ Run the following command to try the demo:
18
+ ```shell
19
+ # MobileNet V1
20
+ python demo.py --input /path/to/image
21
+ # MobileNet V2
22
+ python demo.py --input /path/to/image --model v2
23
+ ```
24
+
25
+ ## License
26
+
27
+ Model weights are licensed under [BSD-3-Clause License](./LICENSE).
28
+ Scripts are licensed unser [Apache 2.0 License](../../LICENSE).
29
+
30
+ ## Reference
31
+
32
+ - MobileNet V1: https://arxiv.org/abs/1704.04861
33
+ - MobileNet V2: https://arxiv.org/abs/1801.04381
34
+ - https://github.com/shicai/MobileNet-Caffe
35
+
models/image_classification_mobilenet/demo.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+
3
+ import numpy as np
4
+ import cv2 as cv
5
+
6
+ from mobilenet_v1 import MobileNetV1
7
+ from mobilenet_v2 import MobileNetV2
8
+
9
+ def str2bool(v):
10
+ if v.lower() in ['on', 'yes', 'true', 'y', 't']:
11
+ return True
12
+ elif v.lower() in ['off', 'no', 'false', 'n', 'f']:
13
+ return False
14
+ else:
15
+ raise NotImplementedError
16
+
17
+ backends = [cv.dnn.DNN_BACKEND_OPENCV, cv.dnn.DNN_BACKEND_CUDA]
18
+ targets = [cv.dnn.DNN_TARGET_CPU, cv.dnn.DNN_TARGET_CUDA, cv.dnn.DNN_TARGET_CUDA_FP16]
19
+ help_msg_backends = "Choose one of the computation backends: {:d}: OpenCV implementation (default); {:d}: CUDA"
20
+ help_msg_targets = "Chose one of the target computation devices: {:d}: CPU (default); {:d}: CUDA; {:d}: CUDA fp16"
21
+ try:
22
+ backends += [cv.dnn.DNN_BACKEND_TIMVX]
23
+ targets += [cv.dnn.DNN_TARGET_NPU]
24
+ help_msg_backends += "; {:d}: TIMVX"
25
+ help_msg_targets += "; {:d}: NPU"
26
+ except:
27
+ print('This version of OpenCV does not support TIM-VX and NPU. Visit https://gist.github.com/fengyuentau/5a7a5ba36328f2b763aea026c43fa45f for more information.')
28
+
29
+ parser = argparse.ArgumentParser(description='Demo for MobileNet V1 & V2.')
30
+ parser.add_argument('--input', '-i', type=str, help='Path to the input image.')
31
+ parser.add_argument('--model', '-m', type=str, choices=['v1', 'v2', 'v1-q', 'v2-q'], default='v1', help='Which model to use, either v1 or v2.')
32
+ parser.add_argument('--backend', '-b', type=int, default=backends[0], help=help_msg_backends.format(*backends))
33
+ parser.add_argument('--target', '-t', type=int, default=targets[0], help=help_msg_targets.format(*targets))
34
+ parser.add_argument('--label', '-l', type=str, default='./imagenet_labels.txt', help='Path to the dataset labels.')
35
+ args = parser.parse_args()
36
+
37
+ if __name__ == '__main__':
38
+ # Instantiate ResNet
39
+ models = {
40
+ 'v1': MobileNetV1(modelPath='./image_classification_mobilenetv1_2022apr.onnx', labelPath=args.label, backendId=args.backend, targetId=args.target),
41
+ 'v2': MobileNetV2(modelPath='./image_classification_mobilenetv2_2022apr.onnx', labelPath=args.label, backendId=args.backend, targetId=args.target),
42
+ 'v1-q': MobileNetV1(modelPath='./image_classification_mobilenetv1_2022apr-act_int8-wt_int8-quantized.onnx', labelPath=args.label, backendId=args.backend, targetId=args.target),
43
+ 'v2-q': MobileNetV2(modelPath='./image_classification_mobilenetv2_2022apr-act_int8-wt_int8-quantized.onnx', labelPath=args.label, backendId=args.backend, targetId=args.target)
44
+
45
+ }
46
+ model = models[args.model]
47
+
48
+ # Read image and get a 224x224 crop from a 256x256 resized
49
+ image = cv.imread(args.input)
50
+ image = cv.cvtColor(image, cv.COLOR_BGR2RGB)
51
+ image = cv.resize(image, dsize=(256, 256))
52
+ image = image[16:240, 16:240, :]
53
+
54
+ # Inference
55
+ result = model.infer(image)
56
+
57
+ # Print result
58
+ print('label: {}'.format(result))
59
+
models/image_classification_mobilenet/imagenet_labels.txt ADDED
@@ -0,0 +1,1000 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ tench
2
+ goldfish
3
+ great white shark
4
+ tiger shark
5
+ hammerhead
6
+ electric ray
7
+ stingray
8
+ cock
9
+ hen
10
+ ostrich
11
+ brambling
12
+ goldfinch
13
+ house finch
14
+ junco
15
+ indigo bunting
16
+ robin
17
+ bulbul
18
+ jay
19
+ magpie
20
+ chickadee
21
+ water ouzel
22
+ kite
23
+ bald eagle
24
+ vulture
25
+ great grey owl
26
+ European fire salamander
27
+ common newt
28
+ eft
29
+ spotted salamander
30
+ axolotl
31
+ bullfrog
32
+ tree frog
33
+ tailed frog
34
+ loggerhead
35
+ leatherback turtle
36
+ mud turtle
37
+ terrapin
38
+ box turtle
39
+ banded gecko
40
+ common iguana
41
+ American chameleon
42
+ whiptail
43
+ agama
44
+ frilled lizard
45
+ alligator lizard
46
+ Gila monster
47
+ green lizard
48
+ African chameleon
49
+ Komodo dragon
50
+ African crocodile
51
+ American alligator
52
+ triceratops
53
+ thunder snake
54
+ ringneck snake
55
+ hognose snake
56
+ green snake
57
+ king snake
58
+ garter snake
59
+ water snake
60
+ vine snake
61
+ night snake
62
+ boa constrictor
63
+ rock python
64
+ Indian cobra
65
+ green mamba
66
+ sea snake
67
+ horned viper
68
+ diamondback
69
+ sidewinder
70
+ trilobite
71
+ harvestman
72
+ scorpion
73
+ black and gold garden spider
74
+ barn spider
75
+ garden spider
76
+ black widow
77
+ tarantula
78
+ wolf spider
79
+ tick
80
+ centipede
81
+ black grouse
82
+ ptarmigan
83
+ ruffed grouse
84
+ prairie chicken
85
+ peacock
86
+ quail
87
+ partridge
88
+ African grey
89
+ macaw
90
+ sulphur-crested cockatoo
91
+ lorikeet
92
+ coucal
93
+ bee eater
94
+ hornbill
95
+ hummingbird
96
+ jacamar
97
+ toucan
98
+ drake
99
+ red-breasted merganser
100
+ goose
101
+ black swan
102
+ tusker
103
+ echidna
104
+ platypus
105
+ wallaby
106
+ koala
107
+ wombat
108
+ jellyfish
109
+ sea anemone
110
+ brain coral
111
+ flatworm
112
+ nematode
113
+ conch
114
+ snail
115
+ slug
116
+ sea slug
117
+ chiton
118
+ chambered nautilus
119
+ Dungeness crab
120
+ rock crab
121
+ fiddler crab
122
+ king crab
123
+ American lobster
124
+ spiny lobster
125
+ crayfish
126
+ hermit crab
127
+ isopod
128
+ white stork
129
+ black stork
130
+ spoonbill
131
+ flamingo
132
+ little blue heron
133
+ American egret
134
+ bittern
135
+ crane
136
+ limpkin
137
+ European gallinule
138
+ American coot
139
+ bustard
140
+ ruddy turnstone
141
+ red-backed sandpiper
142
+ redshank
143
+ dowitcher
144
+ oystercatcher
145
+ pelican
146
+ king penguin
147
+ albatross
148
+ grey whale
149
+ killer whale
150
+ dugong
151
+ sea lion
152
+ Chihuahua
153
+ Japanese spaniel
154
+ Maltese dog
155
+ Pekinese
156
+ Shih-Tzu
157
+ Blenheim spaniel
158
+ papillon
159
+ toy terrier
160
+ Rhodesian ridgeback
161
+ Afghan hound
162
+ basset
163
+ beagle
164
+ bloodhound
165
+ bluetick
166
+ black-and-tan coonhound
167
+ Walker hound
168
+ English foxhound
169
+ redbone
170
+ borzoi
171
+ Irish wolfhound
172
+ Italian greyhound
173
+ whippet
174
+ Ibizan hound
175
+ Norwegian elkhound
176
+ otterhound
177
+ Saluki
178
+ Scottish deerhound
179
+ Weimaraner
180
+ Staffordshire bullterrier
181
+ American Staffordshire terrier
182
+ Bedlington terrier
183
+ Border terrier
184
+ Kerry blue terrier
185
+ Irish terrier
186
+ Norfolk terrier
187
+ Norwich terrier
188
+ Yorkshire terrier
189
+ wire-haired fox terrier
190
+ Lakeland terrier
191
+ Sealyham terrier
192
+ Airedale
193
+ cairn
194
+ Australian terrier
195
+ Dandie Dinmont
196
+ Boston bull
197
+ miniature schnauzer
198
+ giant schnauzer
199
+ standard schnauzer
200
+ Scotch terrier
201
+ Tibetan terrier
202
+ silky terrier
203
+ soft-coated wheaten terrier
204
+ West Highland white terrier
205
+ Lhasa
206
+ flat-coated retriever
207
+ curly-coated retriever
208
+ golden retriever
209
+ Labrador retriever
210
+ Chesapeake Bay retriever
211
+ German short-haired pointer
212
+ vizsla
213
+ English setter
214
+ Irish setter
215
+ Gordon setter
216
+ Brittany spaniel
217
+ clumber
218
+ English springer
219
+ Welsh springer spaniel
220
+ cocker spaniel
221
+ Sussex spaniel
222
+ Irish water spaniel
223
+ kuvasz
224
+ schipperke
225
+ groenendael
226
+ malinois
227
+ briard
228
+ kelpie
229
+ komondor
230
+ Old English sheepdog
231
+ Shetland sheepdog
232
+ collie
233
+ Border collie
234
+ Bouvier des Flandres
235
+ Rottweiler
236
+ German shepherd
237
+ Doberman
238
+ miniature pinscher
239
+ Greater Swiss Mountain dog
240
+ Bernese mountain dog
241
+ Appenzeller
242
+ EntleBucher
243
+ boxer
244
+ bull mastiff
245
+ Tibetan mastiff
246
+ French bulldog
247
+ Great Dane
248
+ Saint Bernard
249
+ Eskimo dog
250
+ malamute
251
+ Siberian husky
252
+ dalmatian
253
+ affenpinscher
254
+ basenji
255
+ pug
256
+ Leonberg
257
+ Newfoundland
258
+ Great Pyrenees
259
+ Samoyed
260
+ Pomeranian
261
+ chow
262
+ keeshond
263
+ Brabancon griffon
264
+ Pembroke
265
+ Cardigan
266
+ toy poodle
267
+ miniature poodle
268
+ standard poodle
269
+ Mexican hairless
270
+ timber wolf
271
+ white wolf
272
+ red wolf
273
+ coyote
274
+ dingo
275
+ dhole
276
+ African hunting dog
277
+ hyena
278
+ red fox
279
+ kit fox
280
+ Arctic fox
281
+ grey fox
282
+ tabby
283
+ tiger cat
284
+ Persian cat
285
+ Siamese cat
286
+ Egyptian cat
287
+ cougar
288
+ lynx
289
+ leopard
290
+ snow leopard
291
+ jaguar
292
+ lion
293
+ tiger
294
+ cheetah
295
+ brown bear
296
+ American black bear
297
+ ice bear
298
+ sloth bear
299
+ mongoose
300
+ meerkat
301
+ tiger beetle
302
+ ladybug
303
+ ground beetle
304
+ long-horned beetle
305
+ leaf beetle
306
+ dung beetle
307
+ rhinoceros beetle
308
+ weevil
309
+ fly
310
+ bee
311
+ ant
312
+ grasshopper
313
+ cricket
314
+ walking stick
315
+ cockroach
316
+ mantis
317
+ cicada
318
+ leafhopper
319
+ lacewing
320
+ dragonfly
321
+ damselfly
322
+ admiral
323
+ ringlet
324
+ monarch
325
+ cabbage butterfly
326
+ sulphur butterfly
327
+ lycaenid
328
+ starfish
329
+ sea urchin
330
+ sea cucumber
331
+ wood rabbit
332
+ hare
333
+ Angora
334
+ hamster
335
+ porcupine
336
+ fox squirrel
337
+ marmot
338
+ beaver
339
+ guinea pig
340
+ sorrel
341
+ zebra
342
+ hog
343
+ wild boar
344
+ warthog
345
+ hippopotamus
346
+ ox
347
+ water buffalo
348
+ bison
349
+ ram
350
+ bighorn
351
+ ibex
352
+ hartebeest
353
+ impala
354
+ gazelle
355
+ Arabian camel
356
+ llama
357
+ weasel
358
+ mink
359
+ polecat
360
+ black-footed ferret
361
+ otter
362
+ skunk
363
+ badger
364
+ armadillo
365
+ three-toed sloth
366
+ orangutan
367
+ gorilla
368
+ chimpanzee
369
+ gibbon
370
+ siamang
371
+ guenon
372
+ patas
373
+ baboon
374
+ macaque
375
+ langur
376
+ colobus
377
+ proboscis monkey
378
+ marmoset
379
+ capuchin
380
+ howler monkey
381
+ titi
382
+ spider monkey
383
+ squirrel monkey
384
+ Madagascar cat
385
+ indri
386
+ Indian elephant
387
+ African elephant
388
+ lesser panda
389
+ giant panda
390
+ barracouta
391
+ eel
392
+ coho
393
+ rock beauty
394
+ anemone fish
395
+ sturgeon
396
+ gar
397
+ lionfish
398
+ puffer
399
+ abacus
400
+ abaya
401
+ academic gown
402
+ accordion
403
+ acoustic guitar
404
+ aircraft carrier
405
+ airliner
406
+ airship
407
+ altar
408
+ ambulance
409
+ amphibian
410
+ analog clock
411
+ apiary
412
+ apron
413
+ ashcan
414
+ assault rifle
415
+ backpack
416
+ bakery
417
+ balance beam
418
+ balloon
419
+ ballpoint
420
+ Band Aid
421
+ banjo
422
+ bannister
423
+ barbell
424
+ barber chair
425
+ barbershop
426
+ barn
427
+ barometer
428
+ barrel
429
+ barrow
430
+ baseball
431
+ basketball
432
+ bassinet
433
+ bassoon
434
+ bathing cap
435
+ bath towel
436
+ bathtub
437
+ beach wagon
438
+ beacon
439
+ beaker
440
+ bearskin
441
+ beer bottle
442
+ beer glass
443
+ bell cote
444
+ bib
445
+ bicycle-built-for-two
446
+ bikini
447
+ binder
448
+ binoculars
449
+ birdhouse
450
+ boathouse
451
+ bobsled
452
+ bolo tie
453
+ bonnet
454
+ bookcase
455
+ bookshop
456
+ bottlecap
457
+ bow
458
+ bow tie
459
+ brass
460
+ brassiere
461
+ breakwater
462
+ breastplate
463
+ broom
464
+ bucket
465
+ buckle
466
+ bulletproof vest
467
+ bullet train
468
+ butcher shop
469
+ cab
470
+ caldron
471
+ candle
472
+ cannon
473
+ canoe
474
+ can opener
475
+ cardigan
476
+ car mirror
477
+ carousel
478
+ carpenters kit
479
+ carton
480
+ car wheel
481
+ cash machine
482
+ cassette
483
+ cassette player
484
+ castle
485
+ catamaran
486
+ CD player
487
+ cello
488
+ cellular telephone
489
+ chain
490
+ chainlink fence
491
+ chain mail
492
+ chain saw
493
+ chest
494
+ chiffonier
495
+ chime
496
+ china cabinet
497
+ Christmas stocking
498
+ church
499
+ cinema
500
+ cleaver
501
+ cliff dwelling
502
+ cloak
503
+ clog
504
+ cocktail shaker
505
+ coffee mug
506
+ coffeepot
507
+ coil
508
+ combination lock
509
+ computer keyboard
510
+ confectionery
511
+ container ship
512
+ convertible
513
+ corkscrew
514
+ cornet
515
+ cowboy boot
516
+ cowboy hat
517
+ cradle
518
+ crane
519
+ crash helmet
520
+ crate
521
+ crib
522
+ Crock Pot
523
+ croquet ball
524
+ crutch
525
+ cuirass
526
+ dam
527
+ desk
528
+ desktop computer
529
+ dial telephone
530
+ diaper
531
+ digital clock
532
+ digital watch
533
+ dining table
534
+ dishrag
535
+ dishwasher
536
+ disk brake
537
+ dock
538
+ dogsled
539
+ dome
540
+ doormat
541
+ drilling platform
542
+ drum
543
+ drumstick
544
+ dumbbell
545
+ Dutch oven
546
+ electric fan
547
+ electric guitar
548
+ electric locomotive
549
+ entertainment center
550
+ envelope
551
+ espresso maker
552
+ face powder
553
+ feather boa
554
+ file
555
+ fireboat
556
+ fire engine
557
+ fire screen
558
+ flagpole
559
+ flute
560
+ folding chair
561
+ football helmet
562
+ forklift
563
+ fountain
564
+ fountain pen
565
+ four-poster
566
+ freight car
567
+ French horn
568
+ frying pan
569
+ fur coat
570
+ garbage truck
571
+ gasmask
572
+ gas pump
573
+ goblet
574
+ go-kart
575
+ golf ball
576
+ golfcart
577
+ gondola
578
+ gong
579
+ gown
580
+ grand piano
581
+ greenhouse
582
+ grille
583
+ grocery store
584
+ guillotine
585
+ hair slide
586
+ hair spray
587
+ half track
588
+ hammer
589
+ hamper
590
+ hand blower
591
+ hand-held computer
592
+ handkerchief
593
+ hard disc
594
+ harmonica
595
+ harp
596
+ harvester
597
+ hatchet
598
+ holster
599
+ home theater
600
+ honeycomb
601
+ hook
602
+ hoopskirt
603
+ horizontal bar
604
+ horse cart
605
+ hourglass
606
+ iPod
607
+ iron
608
+ jack-o-lantern
609
+ jean
610
+ jeep
611
+ jersey
612
+ jigsaw puzzle
613
+ jinrikisha
614
+ joystick
615
+ kimono
616
+ knee pad
617
+ knot
618
+ lab coat
619
+ ladle
620
+ lampshade
621
+ laptop
622
+ lawn mower
623
+ lens cap
624
+ letter opener
625
+ library
626
+ lifeboat
627
+ lighter
628
+ limousine
629
+ liner
630
+ lipstick
631
+ Loafer
632
+ lotion
633
+ loudspeaker
634
+ loupe
635
+ lumbermill
636
+ magnetic compass
637
+ mailbag
638
+ mailbox
639
+ maillot
640
+ maillot
641
+ manhole cover
642
+ maraca
643
+ marimba
644
+ mask
645
+ matchstick
646
+ maypole
647
+ maze
648
+ measuring cup
649
+ medicine chest
650
+ megalith
651
+ microphone
652
+ microwave
653
+ military uniform
654
+ milk can
655
+ minibus
656
+ miniskirt
657
+ minivan
658
+ missile
659
+ mitten
660
+ mixing bowl
661
+ mobile home
662
+ Model T
663
+ modem
664
+ monastery
665
+ monitor
666
+ moped
667
+ mortar
668
+ mortarboard
669
+ mosque
670
+ mosquito net
671
+ motor scooter
672
+ mountain bike
673
+ mountain tent
674
+ mouse
675
+ mousetrap
676
+ moving van
677
+ muzzle
678
+ nail
679
+ neck brace
680
+ necklace
681
+ nipple
682
+ notebook
683
+ obelisk
684
+ oboe
685
+ ocarina
686
+ odometer
687
+ oil filter
688
+ organ
689
+ oscilloscope
690
+ overskirt
691
+ oxcart
692
+ oxygen mask
693
+ packet
694
+ paddle
695
+ paddlewheel
696
+ padlock
697
+ paintbrush
698
+ pajama
699
+ palace
700
+ panpipe
701
+ paper towel
702
+ parachute
703
+ parallel bars
704
+ park bench
705
+ parking meter
706
+ passenger car
707
+ patio
708
+ pay-phone
709
+ pedestal
710
+ pencil box
711
+ pencil sharpener
712
+ perfume
713
+ Petri dish
714
+ photocopier
715
+ pick
716
+ pickelhaube
717
+ picket fence
718
+ pickup
719
+ pier
720
+ piggy bank
721
+ pill bottle
722
+ pillow
723
+ ping-pong ball
724
+ pinwheel
725
+ pirate
726
+ pitcher
727
+ plane
728
+ planetarium
729
+ plastic bag
730
+ plate rack
731
+ plow
732
+ plunger
733
+ Polaroid camera
734
+ pole
735
+ police van
736
+ poncho
737
+ pool table
738
+ pop bottle
739
+ pot
740
+ potters wheel
741
+ power drill
742
+ prayer rug
743
+ printer
744
+ prison
745
+ projectile
746
+ projector
747
+ puck
748
+ punching bag
749
+ purse
750
+ quill
751
+ quilt
752
+ racer
753
+ racket
754
+ radiator
755
+ radio
756
+ radio telescope
757
+ rain barrel
758
+ recreational vehicle
759
+ reel
760
+ reflex camera
761
+ refrigerator
762
+ remote control
763
+ restaurant
764
+ revolver
765
+ rifle
766
+ rocking chair
767
+ rotisserie
768
+ rubber eraser
769
+ rugby ball
770
+ rule
771
+ running shoe
772
+ safe
773
+ safety pin
774
+ saltshaker
775
+ sandal
776
+ sarong
777
+ sax
778
+ scabbard
779
+ scale
780
+ school bus
781
+ schooner
782
+ scoreboard
783
+ screen
784
+ screw
785
+ screwdriver
786
+ seat belt
787
+ sewing machine
788
+ shield
789
+ shoe shop
790
+ shoji
791
+ shopping basket
792
+ shopping cart
793
+ shovel
794
+ shower cap
795
+ shower curtain
796
+ ski
797
+ ski mask
798
+ sleeping bag
799
+ slide rule
800
+ sliding door
801
+ slot
802
+ snorkel
803
+ snowmobile
804
+ snowplow
805
+ soap dispenser
806
+ soccer ball
807
+ sock
808
+ solar dish
809
+ sombrero
810
+ soup bowl
811
+ space bar
812
+ space heater
813
+ space shuttle
814
+ spatula
815
+ speedboat
816
+ spider web
817
+ spindle
818
+ sports car
819
+ spotlight
820
+ stage
821
+ steam locomotive
822
+ steel arch bridge
823
+ steel drum
824
+ stethoscope
825
+ stole
826
+ stone wall
827
+ stopwatch
828
+ stove
829
+ strainer
830
+ streetcar
831
+ stretcher
832
+ studio couch
833
+ stupa
834
+ submarine
835
+ suit
836
+ sundial
837
+ sunglass
838
+ sunglasses
839
+ sunscreen
840
+ suspension bridge
841
+ swab
842
+ sweatshirt
843
+ swimming trunks
844
+ swing
845
+ switch
846
+ syringe
847
+ table lamp
848
+ tank
849
+ tape player
850
+ teapot
851
+ teddy
852
+ television
853
+ tennis ball
854
+ thatch
855
+ theater curtain
856
+ thimble
857
+ thresher
858
+ throne
859
+ tile roof
860
+ toaster
861
+ tobacco shop
862
+ toilet seat
863
+ torch
864
+ totem pole
865
+ tow truck
866
+ toyshop
867
+ tractor
868
+ trailer truck
869
+ tray
870
+ trench coat
871
+ tricycle
872
+ trimaran
873
+ tripod
874
+ triumphal arch
875
+ trolleybus
876
+ trombone
877
+ tub
878
+ turnstile
879
+ typewriter keyboard
880
+ umbrella
881
+ unicycle
882
+ upright
883
+ vacuum
884
+ vase
885
+ vault
886
+ velvet
887
+ vending machine
888
+ vestment
889
+ viaduct
890
+ violin
891
+ volleyball
892
+ waffle iron
893
+ wall clock
894
+ wallet
895
+ wardrobe
896
+ warplane
897
+ washbasin
898
+ washer
899
+ water bottle
900
+ water jug
901
+ water tower
902
+ whiskey jug
903
+ whistle
904
+ wig
905
+ window screen
906
+ window shade
907
+ Windsor tie
908
+ wine bottle
909
+ wing
910
+ wok
911
+ wooden spoon
912
+ wool
913
+ worm fence
914
+ wreck
915
+ yawl
916
+ yurt
917
+ web site
918
+ comic book
919
+ crossword puzzle
920
+ street sign
921
+ traffic light
922
+ book jacket
923
+ menu
924
+ plate
925
+ guacamole
926
+ consomme
927
+ hot pot
928
+ trifle
929
+ ice cream
930
+ ice lolly
931
+ French loaf
932
+ bagel
933
+ pretzel
934
+ cheeseburger
935
+ hotdog
936
+ mashed potato
937
+ head cabbage
938
+ broccoli
939
+ cauliflower
940
+ zucchini
941
+ spaghetti squash
942
+ acorn squash
943
+ butternut squash
944
+ cucumber
945
+ artichoke
946
+ bell pepper
947
+ cardoon
948
+ mushroom
949
+ Granny Smith
950
+ strawberry
951
+ orange
952
+ lemon
953
+ fig
954
+ pineapple
955
+ banana
956
+ jackfruit
957
+ custard apple
958
+ pomegranate
959
+ hay
960
+ carbonara
961
+ chocolate sauce
962
+ dough
963
+ meat loaf
964
+ pizza
965
+ potpie
966
+ burrito
967
+ red wine
968
+ espresso
969
+ cup
970
+ eggnog
971
+ alp
972
+ bubble
973
+ cliff
974
+ coral reef
975
+ geyser
976
+ lakeside
977
+ promontory
978
+ sandbar
979
+ seashore
980
+ valley
981
+ volcano
982
+ ballplayer
983
+ groom
984
+ scuba diver
985
+ rapeseed
986
+ daisy
987
+ yellow ladys slipper
988
+ corn
989
+ acorn
990
+ hip
991
+ buckeye
992
+ coral fungus
993
+ agaric
994
+ gyromitra
995
+ stinkhorn
996
+ earthstar
997
+ hen-of-the-woods
998
+ bolete
999
+ ear
1000
+ toilet tissue
models/image_classification_mobilenet/mobilenet_v1.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import cv2 as cv
3
+
4
+ class MobileNetV1:
5
+ def __init__(self, modelPath, labelPath, backendId=0, targetId=0):
6
+ self.model_path = modelPath
7
+ self.label_path = labelPath
8
+ self.backend_id = backendId
9
+ self.target_id = targetId
10
+
11
+ self.model = cv.dnn.readNet(self.model_path)
12
+ self.model.setPreferableBackend(self.backend_id)
13
+ self.model.setPreferableTarget(self.target_id)
14
+
15
+ self.input_names = ''
16
+ self.output_names = ''
17
+ self.input_size = [224, 224]
18
+ self.mean = [103.94,116.78,123.68]
19
+ self.scale = 0.017
20
+
21
+ # load labels
22
+ self.labels = self._load_labels()
23
+
24
+ def _load_labels(self):
25
+ labels = []
26
+ with open(self.label_path, 'r') as f:
27
+ for line in f:
28
+ labels.append(line.strip())
29
+ return labels
30
+
31
+ @property
32
+ def name(self):
33
+ return self.__class__.__name__
34
+
35
+ def setBackend(self, backendId):
36
+ self.backend_id = backendId
37
+ self.model.setPreferableBackend(self.backend_id)
38
+
39
+ def setTarget(self, targetId):
40
+ self.target_id = targetId
41
+ self.model.setPreferableTarget(self.target_id)
42
+
43
+ def _preprocess(self, image):
44
+ return cv.dnn.blobFromImage(image, scalefactor=self.scale, size=self.input_size, mean=self.mean)
45
+
46
+ def infer(self, image):
47
+ # Preprocess
48
+ input_blob = self._preprocess(image)
49
+
50
+ # Forward
51
+ self.model.setInput(input_blob, self.input_names)
52
+ output_blob = self.model.forward(self.output_names)
53
+
54
+ # Postprocess
55
+ results = self._postprocess(output_blob)
56
+
57
+ return results
58
+
59
+ def _postprocess(self, output_blob):
60
+ predicted_labels = []
61
+ for o in output_blob:
62
+ class_id = np.argmax(o)
63
+ predicted_labels.append(self.labels[class_id])
64
+ return predicted_labels
65
+
models/image_classification_mobilenet/mobilenet_v2.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import cv2 as cv
3
+
4
+ class MobileNetV2:
5
+ def __init__(self, modelPath, labelPath, backendId=0, targetId=0):
6
+ self.model_path = modelPath
7
+ self.label_path = labelPath
8
+ self.backend_id = backendId
9
+ self.target_id = targetId
10
+
11
+ self.model = cv.dnn.readNet(self.model_path)
12
+ self.model.setPreferableBackend(self.backend_id)
13
+ self.model.setPreferableTarget(self.target_id)
14
+
15
+ self.input_names = ''
16
+ self.output_names = ''
17
+ self.input_size = [224, 224]
18
+ self.mean = [103.94,116.78,123.68]
19
+ self.scale = 0.017
20
+
21
+ # load labels
22
+ self.labels = self._load_labels()
23
+
24
+ def _load_labels(self):
25
+ labels = []
26
+ with open(self.label_path, 'r') as f:
27
+ for line in f:
28
+ labels.append(line.strip())
29
+ return labels
30
+
31
+ @property
32
+ def name(self):
33
+ return self.__class__.__name__
34
+
35
+ def setBackend(self, backendId):
36
+ self.backend_id = backendId
37
+ self.model.setPreferableBackend(self.backend_id)
38
+
39
+ def setTarget(self, targetId):
40
+ self.target_id = targetId
41
+ self.model.setPreferableTarget(self.target_id)
42
+
43
+ def _preprocess(self, image):
44
+ return cv.dnn.blobFromImage(image, scalefactor=self.scale, size=self.input_size, mean=self.mean)
45
+
46
+ def infer(self, image):
47
+ # Preprocess
48
+ input_blob = self._preprocess(image)
49
+
50
+ # Forward
51
+ self.model.setInput(input_blob, self.input_names)
52
+ output_blob = self.model.forward(self.output_names)
53
+
54
+ # Postprocess
55
+ results = self._postprocess(output_blob)
56
+
57
+ return results
58
+
59
+ def _postprocess(self, output_blob):
60
+ predicted_labels = []
61
+ for o in output_blob:
62
+ class_id = np.argmax(o)
63
+ predicted_labels.append(self.labels[class_id])
64
+ return predicted_labels
65
+
tools/quantize/quantize.py CHANGED
@@ -14,7 +14,7 @@ from onnx import version_converter
14
  import onnxruntime
15
  from onnxruntime.quantization import quantize_static, CalibrationDataReader, QuantType
16
 
17
- from transform import Compose, Resize, ColorConvert
18
 
19
  class DataReader(CalibrationDataReader):
20
  def __init__(self, model_path, image_dir, transforms):
@@ -30,13 +30,14 @@ class DataReader(CalibrationDataReader):
30
  def get_calibration_data(self, image_dir):
31
  blobs = []
32
  for image_name in os.listdir(image_dir):
33
- if not image_name.endswith('jpg'):
 
34
  continue
35
  img = cv.imread(os.path.join(image_dir, image_name))
36
  img = self.transforms(img)
37
  blob = cv.dnn.blobFromImage(img)
38
  blobs.append(blob)
39
- return blobs
40
 
41
  class Quantize:
42
  def __init__(self, model_path, calibration_image_dir, transforms=Compose(), per_channel=False, act_type='int8', wt_type='int8'):
@@ -90,6 +91,12 @@ models=dict(
90
  ppresnet50=Quantize(model_path='../../models/image_classification_ppresnet/image_classification_ppresnet50_2022jan.onnx',
91
  calibration_image_dir='../../benchmark/data/image_classification',
92
  transforms=Compose([Resize(size=(224, 224))])),
 
 
 
 
 
 
93
  # TBD: DaSiamRPN
94
  youtureid=Quantize(model_path='../../models/person_reid_youtureid/person_reid_youtu_2021nov.onnx',
95
  calibration_image_dir='../../benchmark/data/person_reid',
 
14
  import onnxruntime
15
  from onnxruntime.quantization import quantize_static, CalibrationDataReader, QuantType
16
 
17
+ from transform import Compose, Resize, CenterCrop, Normalize, ColorConvert
18
 
19
  class DataReader(CalibrationDataReader):
20
  def __init__(self, model_path, image_dir, transforms):
 
30
  def get_calibration_data(self, image_dir):
31
  blobs = []
32
  for image_name in os.listdir(image_dir):
33
+ image_name_suffix = image_name.split('.')[-1].lower()
34
+ if image_name_suffix == 'jpg' or image_name_suffix != 'jpeg':
35
  continue
36
  img = cv.imread(os.path.join(image_dir, image_name))
37
  img = self.transforms(img)
38
  blob = cv.dnn.blobFromImage(img)
39
  blobs.append(blob)
40
+ return blobs[:100]
41
 
42
  class Quantize:
43
  def __init__(self, model_path, calibration_image_dir, transforms=Compose(), per_channel=False, act_type='int8', wt_type='int8'):
 
91
  ppresnet50=Quantize(model_path='../../models/image_classification_ppresnet/image_classification_ppresnet50_2022jan.onnx',
92
  calibration_image_dir='../../benchmark/data/image_classification',
93
  transforms=Compose([Resize(size=(224, 224))])),
94
+ mobilenetv1=Quantize(model_path='../../models/image_classification_mobilenet/image_classification_mobilenetv1_2022apr.onnx',
95
+ calibration_image_dir='../../benchmark/data/image_classification',
96
+ transforms=Compose([Resize(size=(256, 256)), CenterCrop(size=(224, 224)), Normalize(mean=[103.94, 116.78, 123.68], std=[0.017, 0.017, 0.017])])),
97
+ mobilenetv2=Quantize(model_path='../../models/image_classification_mobilenet/image_classification_mobilenetv2_2022apr.onnx',
98
+ calibration_image_dir='../../benchmark/data/image_classification',
99
+ transforms=Compose([Resize(size=(256, 256)), CenterCrop(size=(224, 224)), Normalize(mean=[103.94, 116.78, 123.68], std=[0.017, 0.017, 0.017])])),
100
  # TBD: DaSiamRPN
101
  youtureid=Quantize(model_path='../../models/person_reid_youtureid/person_reid_youtu_2021nov.onnx',
102
  calibration_image_dir='../../benchmark/data/person_reid',
tools/quantize/transform.py CHANGED
@@ -4,6 +4,7 @@
4
  # Copyright (C) 2021, Shenzhen Institute of Artificial Intelligence and Robotics for Society, all rights reserved.
5
  # Third party copyrights are property of their respective owners.
6
 
 
7
  import numpy as numpy
8
  import cv2 as cv
9
 
@@ -24,9 +25,35 @@ class Resize:
24
  def __call__(self, img):
25
  return cv.resize(img, self.size)
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  class ColorConvert:
28
  def __init__(self, ctype):
29
  self.ctype = ctype
30
 
31
  def __call__(self, img):
32
- return cv.cvtColor(img, self.ctype)
 
4
  # Copyright (C) 2021, Shenzhen Institute of Artificial Intelligence and Robotics for Society, all rights reserved.
5
  # Third party copyrights are property of their respective owners.
6
 
7
+ import collections
8
  import numpy as numpy
9
  import cv2 as cv
10
 
 
25
  def __call__(self, img):
26
  return cv.resize(img, self.size)
27
 
28
+ class CenterCrop:
29
+ def __init__(self, size):
30
+ self.size = size # w, h
31
+
32
+ def __call__(self, img):
33
+ h, w, _ = img.shape
34
+ ws = int(w / 2 - self.size[0] / 2)
35
+ hs = int(h / 2 - self.size[1] / 2)
36
+ return img[hs:hs+self.size[1], ws:ws+self.size[0], :]
37
+
38
+ class Normalize:
39
+ def __init__(self, mean=None, std=None):
40
+ self.mean = mean
41
+ self.std = std
42
+
43
+ def __call__(self, img):
44
+ if self.mean is not None:
45
+ img[:, :, 0] = img[:, :, 0] - self.mean[0]
46
+ img[:, :, 1] = img[:, :, 1] - self.mean[1]
47
+ img[:, :, 2] = img[:, :, 2] - self.mean[2]
48
+ if self.std is not None:
49
+ img[:, :, 0] = img[:, :, 0] / self.std[0]
50
+ img[:, :, 1] = img[:, :, 1] / self.std[1]
51
+ img[:, :, 2] = img[:, :, 2] / self.std[2]
52
+ return img
53
+
54
  class ColorConvert:
55
  def __init__(self, ctype):
56
  self.ctype = ctype
57
 
58
  def __call__(self, img):
59
+ return cv.cvtColor(img, self.ctype)