@Frank @jasonl
1_quantize_model.sh中只有四个值,前三个是mean,第四个是std
–channel-mean-value ‘114.5 114.5 114.5 57.63’
实际:
mean:{123.675,116.280,103.530}
std:{58.395, 57.120, 57.375}
@Frank @jasonl
1_quantize_model.sh中只有四个值,前三个是mean,第四个是std
–channel-mean-value ‘114.5 114.5 114.5 57.63’
实际:
mean:{123.675,116.280,103.530}
std:{58.395, 57.120, 57.375}
@Frank @jasonl
我现在有一个onnx模型通过acuity-toolkit转nb后,c++推理结果与cpu下网络输出结果差的挺大的,不知道什么原因?
$convert_onnx \
--onnx-model ./model/vargfacenet.onnx \
--net-output ${NAME}.json \
--data-output ${NAME}.data
$tensorzone \
--action quantization \
--dtype float32 \
--source text \
--source-file data/validation_onnx.txt \
--channel-mean-value '127.5 127.5 127.5 127.5' \
--reorder-channel '0 1 2' \
--model-input ${NAME}.json \
--model-data ${NAME}.data \
--model-quantize ${NAME}.quantize \
--quantized-dtype asymmetric_affine-u8 \
--quantized-rebuild \
$export_ovxlib \
--model-input ${NAME}.json \
--data-input ${NAME}.data \
--reorder-channel '0 1 2' \
--channel-mean-value '127.5 127.5 127.5 127.5' \
--export-dtype quantized \
--model-quantize ${NAME}.quantize \
--optimize VIPNANOQI_PID0X88 \
--viv-sdk ${ACUITY_PATH}vcmdtools \
--pack-nbg-unify \
cpu下
image = cv2.imread(img_path) # H,W,C, BGR, numpy
if image.shape[0] != 112 or image.shape[1] != 112:
image = cv2.resize(image, (112,112))
#if image.shape[0] != 80 or image.shape[1] != 144:
# image = cv2.resize(image, (144,80))
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # H,W,C, RGB, numpy
image = image.transpose(2, 0, 1).astype(np.float32) / 255 # C,H,W, RGB, (0,1)
image[0,:,:] = (image[0,:,:] - 0.5) / 0.5 # R
image[1,:,:] = (image[1,:,:] - 0.5) / 0.5 # G
image[2,:,:] = (image[2,:,:] - 0.5) / 0.5 # B
image = image[np.newaxis, :] # 1,C,H,W,numpy
image = torch.from_numpy(image) # 1,C,H,W, tensor
这些地方应该都对得上
c++推理:
config.modelType = ONNX
inData.input_type = RGB24_RAW_DATA;
outconfig.format = AML_OUTDATA_FLOAT32;
onnx网络输出前四位:
1.84245333e-02 -4.22798276e-01 7.84602523e-01 -7.89071247e-02
c++网络输出前四位:
0.122210 -0.058842 -0.063368 -0.004526
这个是网络直接输出,没有到后处理那里!前处理应该是什么问题呀!
按照推荐步骤去分析,float类型的精度和原始cpu平台下测试结果就差的很大(有没有onnx模型的转换demo?)
(1)确认float类型的精度和原始cpu平台下测试结果相差很多
原始cpu平台下跑onnx模型网络输出:
0.0184245333
-0.422798276
0.784602523
-0.0789071247
-0.0164997458
-0.326351434
0.180208728
0.124262467
-0.239654392
-0.121204361
量化前:执行完import导入模型之后,使用inference.sh脚本(执行0_import_model.sh后执行inference.sh)
root@50d4581267c4:/test/aml_npu_sdk_6.4.4.3/acuity-toolkit/nomask_face_feature# head -10 before_quant_512.tensor
0.10576270520687103
-0.07041622698307037
-0.08786770701408386
-0.03913433849811554
-0.14785173535346985
0.04474426060914993
0.14684905111789703
0.1447640359401703
-0.2373252809047699
0.05276653915643692
上面说差很多,下面说相近,是不是哪里打错字了?
@Frank
原本模型是pytorch,由于acuity-toolkit工具支持的pytorch版本最大1.2.0,我们pytorch模型训练的大于1.2.0,没办法才把pytorch模型转成onnx再去转成nb文件!