Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onnx模型使用paddlelit opt量化后推理结果错误,windows x86平台 #10612

Open
Lizuole007 opened this issue Dec 10, 2024 · 2 comments
Open
Assignees

Comments

@Lizuole007
Copy link

使用https://github.com/[AnthonyF333/PFLD_GhostOne](https://github.com/AnthonyF333/PFLD_GhostOne)中的onnx人脸关键点检测onnx模型,使用paddlelit opt量化后推理结果错误,但通过paddleslim量化,不量化matmul_v2推理结果没有问题,量化matmul_v2后推理结果仍有问题。

@Lizuole007 Lizuole007 changed the title onnx模型使用paddlelit opt量化后推理结果错误 onnx模型使用paddlelit opt量化后推理结果错误,windows x86平台 Dec 10, 2024
@ddchenhao66
Copy link
Collaborator

ddchenhao66 commented Dec 11, 2024

请贴上opt工具转后的详细报错日志。onnx模型需要通过X2Paddle工具转成PadddlePaddle模型后,在用opt工具转成优化模型推理。详细过程见https://www.paddlepaddle.org.cn/lite/v2.12/quick_start/tutorial.html 。关于量化部分也可以参考 https://www.paddlepaddle.org.cn/lite/v2.12/user_guides/quant_aware.html

@Lizuole007
Copy link
Author

Lizuole007 commented Dec 12, 2024

请贴上opt工具转后的详细报错日志。onnx模型需要通过X2Paddle工具转成PadddlePaddle模型后,在用opt工具转成优化模型推理。详细过程见https://www.paddlepaddle.org.cn/lite/v2.12/quick_start/tutorial.html 。关于量化部分也可以参考 https://www.paddlepaddle.org.cn/lite/v2.12/user_guides/quant_aware.html

推理脚本:
paddleslim:
paddleslim.quant.quant_post_dynamic(
model_dir=model_dir, # 输入模型路径
model_filename=model_filename, # 输入模型计算图文件名称
params_filename=params_filename, # 输入模型参数文件名称
save_model_dir=save_dir, # 输出模型路径
save_model_filename=model_filename, # 输出模型计算图名称
save_params_filename=params_filename, # 输出模型参数文件名称
weight_bits=8, # 量化比特数 8/16 对应 INT8/16 类型
quantizable_op_type=['conv2d', 'mul', 'depthwise_conv2d'],
# generate_test_model=True
)

paddlelite:
opt=Opt()
opt.set_model_file(os.path.join(save_dir + "/quantized_model/model.pdmodel"))
opt.set_param_file(os.path.join(save_dir + "/quantized_model/model.pdiparams"))
#opt.set_model_dir("./pdmodel/inference_model")
#opt.set_model_dir("./pdmodel_infer_quant_dynamic16/quantized_model")
opt.set_valid_places(platform)
opt.set_model_type("naive_buffer")
opt.set_optimize_out("**_arm")
opt.set_quant_model(False) #采用paddleslim量化,全连接层(matmul_v2)未量化,设置True后,matmul_v2会被量化,推理结果有误。
opt.set_quant_type("QUANT_INT8")
opt.run()

推理结果如下:matmul_v2量化,推理结果错误,未量化,推理正确
false_29_Students_Schoolkids_Students_Schoolkids_29_148
right_29_Students_Schoolkids_Students_Schoolkids_29_148

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants