未验证 提交 c5c7f1aa 编写于 作者: Y Yuantao Feng 提交者: GitHub

Add the missing yaml config for quantizing MP-PalmDet and improve quantized MP-PalmDet (#60)

上级 4fb59105
......@@ -17,8 +17,6 @@ python demo.py
python demo.py -i /path/to/image
```
NOTE: For the quantized model, you will need to install OpenCV 4.6.0 to have asymmetric paddings support for quantized convolution layer in OpenCV. Score threshold needs to be adjusted as well for the quantized model, which is empirically 0.49.
### Example outputs
![webcam demo](./examples/mppalmdet_demo.gif)
......
#
# Copyright (c) 2021 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
version: 1.0
model: # mandatory. used to specify model specific information.
name: mp_palmdet
framework: onnxrt_qlinearops # mandatory. supported values are tensorflow, pytorch, pytorch_ipex, onnxrt_integer, onnxrt_qlinear or mxnet; allow new framework backend extension.
quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space.
approach: post_training_static_quant # optional. default value is post_training_static_quant.
calibration:
dataloader:
batch_size: 1
dataset:
dummy:
shape: [1, 256, 256, 3]
low: -1.0
high: 1.0
dtype: float32
label: True
tuning:
accuracy_criterion:
relative: 0.02 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%.
exit_policy:
timeout: 0 # optional. tuning timeout (seconds). default value is 0 which means early stop. combine with max_trials field to decide when to exit.
random_seed: 9527 # optional. random seed for deterministic tuning.
......@@ -28,10 +28,14 @@ class Quantize:
q_model.save(output_name)
class Dataset:
def __init__(self, root, size=None, toTensor=False):
def __init__(self, root, size=None, dim='chw', mean=0.0, std=1.0, swapRB=False, toFP32=False):
self.root = root
self.size = size
self.toTensor = toTensor
self.dim = dim
self.mean = mean
self.std = std
self.swapRB = swapRB
self.toFP32 = toFP32
self.image_list = self.load_image_list(self.root)
......@@ -45,11 +49,22 @@ class Dataset:
def __getitem__(self, idx):
img = cv.imread(self.image_list[idx])
if self.swapRB:
img = cv.cvtColor(img, cv.COLOR_BGR2RGB)
if self.size:
img = cv.resize(img, dsize=self.size)
if self.toTensor:
img = img.transpose(2, 0, 1) # hwc -> chw
if self.toFP32:
img = img.astype(np.float32)
img = img - self.mean
img = img / self.std
if self.dim == 'chw':
img = img.transpose(2, 0, 1) # hwc -> chw
return img, 1
def __len__(self):
......@@ -57,15 +72,15 @@ class Dataset:
models=dict(
mobilenetv1=Quantize(model_path='../../models/image_classification_mobilenet/image_classification_mobilenetv1_2022apr.onnx',
config_path='./inc_configs/mobilenet.yaml'),
config_path='./inc_configs/mobilenet.yaml'),
mobilenetv2=Quantize(model_path='../../models/image_classification_mobilenet/image_classification_mobilenetv2_2022apr.onnx',
config_path='./inc_configs/mobilenet.yaml'),
mppalm_det=Quantize(model_path='../../models/palm_detection_mediapipe/palm_detection_mediapipe_2022may.onnx',
config_path='./inc_configs/mppalmdet.yaml',
custom_dataset=Dataset(root='../../benchmark/data/palm_detection')),
config_path='./inc_configs/mobilenet.yaml'),
mp_palmdet=Quantize(model_path='../../models/palm_detection_mediapipe/palm_detection_mediapipe_2022may.onnx',
config_path='./inc_configs/mp_palmdet.yaml',
custom_dataset=Dataset(root='../../benchmark/data/palm_detection', dim='hwc', swapRB=True, mean=127.5, std=127.5, toFP32=True)),
lpd_yunet=Quantize(model_path='../../models/license_plate_detection_yunet/license_plate_detection_lpd_yunet_2022may.onnx',
config_path='./inc_configs/lpd_yunet.yaml',
custom_dataset=Dataset(root='../../benchmark/data/license_plate_detection', size=(320, 240), toTensor=True)),
custom_dataset=Dataset(root='../../benchmark/data/license_plate_detection', size=(320, 240), dim='chw', toFP32=True)),
)
if __name__ == '__main__':
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册