Skip to content

Commit e9b6fc2

Browse files
committed
quantize all models to fp16
1 parent af2b8cb commit e9b6fc2

File tree

25 files changed

+130
-0
lines changed

25 files changed

+130
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:1263d26b9e56d9e7431e4f868b4c4caa362653fb220f2aff240dc5270091a50b
3+
size 126333
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:f6abbfff9575e3041db692c1e29d782e995191888477fd59ebc81202d99fc63b
3+
size 24227283
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:a6bd51e7dca0c2bfb3755e7884e69f6c6810fbad9e53f9d75a597add3baed1a8
3+
size 2413209
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:febfac55f789674c38eee023c369de4f1c57ab592a699781e87d89b54a6d4189
3+
size 2076178
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:c9f359bc3d50bf0bcf20762076b1cd174a431bb404149f482a2fccb8e5131628
3+
size 3099693
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:de99f3c6c92af11876ee21545701010876c9c0ec4f75d9bfbd5b5adccd516f8e
3+
size 8449898
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:823ed99e25277696d79279f5866c138d1a04722409b02869c512d4a7a64d6006
3+
size 6992958
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:17f32c5716fe2d6073164a3e677981e5e2b82f57e61d8fa49ee779f6a0fef7b8
3+
size 65414918
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:31a621b3f88b90fade3f51e6060883e65d5410e6de53a6dea1888f6569f07bf4
3+
size 2080376
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:4d26642c6c74864504fb5487821ca93dcb6a497629da4556ead4c51b7a52edcd
3+
size 1917291
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:5ccec6eb86a17cf88f161aaf26dd56d333e3fbeb1b370eb9cb70c3dd12432d36
3+
size 17944560
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:62114adf1dbe41461593ea4aa435ce4b7cd4a8ee3a12a01e383698e1f4817620
3+
size 11801998
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:5fba5bee6ed8c907b194594ad04c82385cd8076a2361170a41dbccafec05b55b
3+
size 23603586
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:069198aff29984c381dcea84558ba60a75d851aac9310ebe52db5f9dda105608
3+
size 45524342
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:d0843d197c6820c489e71081021823d57849032269b497994bef8682c530701d
3+
size 1985511
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:4fd42391028c48039af68baceae5733f3a3bd31241f887770b96678228e151df
3+
size 6060089
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:756e85946fe83d8269c8543f7b46290c87a43477758b08097cbcae7c4d654132
3+
size 53466034
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:449de123d2157d94db1a123e5943ba28e54ae50ffd72b13d9154f447f65f1836
3+
size 2831020
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:62324d714056a4ce621e3ca5458c83be12ce8ba3cb0114ce2ee4fb29e616c7b8
3+
size 24404916
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:a52ff8fb7c1a3bd56463ad997ca845a80451adfc5421da43f61e540ae6aafe98
3+
size 24404916
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:a51fa1e4155f9a68439869c7187f0ccda3a8ffce7abdb23da75c225b1c9b5fe4
3+
size 32472431
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:acff153535e41702c14c62a41f5d09df7e28459b46525372e1a60c4cd309285d
3+
size 36422522
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:1269b01d544cccb4e4c61b8a7a209b6643ef4ce969432ca963ce78f093138c2a
3+
size 16918127

tools/quantize/fp16-quantize-ort.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import sys
2+
import onnx
3+
from onnxconverter_common import float16
4+
5+
op_block_list = ['ArrayFeatureExtractor', 'Binarizer', 'CastMap', 'CategoryMapper', 'DictVectorizer',
6+
'FeatureVectorizer', 'Imputer', 'LabelEncoder', 'LinearClassifier', 'LinearRegressor',
7+
'Normalizer', 'OneHotEncoder', 'RandomUniformLike', 'SVMClassifier', 'SVMRegressor', 'Scaler',
8+
'TreeEnsembleClassifier', 'TreeEnsembleRegressor', 'ZipMap', 'NonMaxSuppression', 'TopK',
9+
'RoiAlign', 'Range', 'CumSum', 'Min', 'Max', 'Upsample']
10+
11+
12+
class Quantize:
13+
def __init__(self, model_path):
14+
self.model_path = model_path
15+
16+
def run(self):
17+
model = onnx.load(self.model_path)
18+
model_fp16 = float16.convert_float_to_float16(model, op_block_list=op_block_list)
19+
output_name = '{}_fp16.onnx'.format(self.model_path[:-5])
20+
onnx.save(model_fp16, output_name)
21+
22+
23+
models = dict(
24+
yunet=Quantize(model_path='../../models/face_detection_yunet/face_detection_yunet_2023mar.onnx'),
25+
sface=Quantize(model_path='../../models/face_recognition_sface/face_recognition_sface_2021dec.onnx'),
26+
fer=Quantize(model_path='../../models/facial_expression_recognition/facial_expression_recognition_mobilefacenet_2022july.onnx'),
27+
pphumanseg=Quantize(model_path='../../models/human_segmentation_pphumanseg/human_segmentation_pphumanseg_2023mar.onnx'),
28+
mobilenetv1=Quantize(model_path='../../models/image_classification_mobilenet/image_classification_mobilenetv1_2022apr.onnx'),
29+
mobilenetv2=Quantize(model_path='../../models/image_classification_mobilenet/image_classification_mobilenetv2_2022apr.onnx'),
30+
ppresnet50=Quantize(model_path='../../models/image_classification_ppresnet/image_classification_ppresnet50_2022jan.onnx'),
31+
nanodet=Quantize(model_path='../../models/object_detection_nanodet/object_detection_nanodet_2022nov.onnx'),
32+
yolox=Quantize(model_path='../../models/object_detection_yolox/object_detection_yolox_2022nov.onnx'),
33+
dasiamrpn=Quantize(model_path='../../models/object_tracking_dasiamrpn/object_tracking_dasiamrpn_model_2021nov.onnx'),
34+
dasiamrpn_cls1=Quantize(model_path='../../models/object_tracking_dasiamrpn/object_tracking_dasiamrpn_kernel_cls1_2021nov.onnx'),
35+
dasiamrpn_r1=Quantize(model_path='../../models/object_tracking_dasiamrpn/object_tracking_dasiamrpn_kernel_r1_2021nov.onnx'),
36+
youtureid=Quantize(model_path='../../models/person_reid_youtureid/person_reid_youtu_2021nov.onnx'),
37+
mp_palmdet=Quantize(model_path='../../models/palm_detection_mediapipe/palm_detection_mediapipe_2023feb.onnx'),
38+
mp_handpose=Quantize(model_path='../../models/handpose_estimation_mediapipe/handpose_estimation_mediapipe_2023feb.onnx'),
39+
lpd_yunet=Quantize(model_path='../../models/license_plate_detection_yunet/license_plate_detection_lpd_yunet_2023mar.onnx'),
40+
mp_persondet=Quantize(model_path='../../models/person_detection_mediapipe/person_detection_mediapipe_2023mar.onnx'),
41+
mp_pose=Quantize(model_path='../../models/pose_estimation_mediapipe/pose_estimation_mediapipe_2023mar.onnx'),
42+
db_en=Quantize(model_path='../../models/text_detection_db/text_detection_DB_IC15_resnet18_2021sep.onnx'),
43+
db_ch=Quantize(model_path='../../models/text_detection_db/text_detection_DB_TD500_resnet18_2021sep.onnx'),
44+
crnn_en=Quantize(model_path='../../models/text_recognition_crnn/text_recognition_CRNN_EN_2021sep.onnx'),
45+
crnn_ch=Quantize(model_path='../../models/text_recognition_crnn/text_recognition_CRNN_CH_2021sep.onnx'),
46+
crnn_cn=Quantize(model_path='../../models/text_recognition_crnn/text_recognition_CRNN_CN_2021nov.onnx')
47+
)
48+
49+
if __name__ == '__main__':
50+
selected_models = []
51+
for i in range(1, len(sys.argv)):
52+
selected_models.append(sys.argv[i])
53+
if not selected_models:
54+
selected_models = list(models.keys())
55+
print('Models to be quantized to fp16: {}'.format(str(selected_models)))
56+
57+
for selected_model_name in selected_models:
58+
q = models[selected_model_name]
59+
print("------------------{}------------------".format(selected_model_name))
60+
q.run()

tools/quantize/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ onnx
33
onnxruntime
44
onnxruntime-extensions
55
neural-compressor
6+
onnxconverter-common

0 commit comments

Comments
 (0)