PaddlePaddle / Paddle-Lite

PaddlePaddle High Performance Deep Learning Inference Engine for Mobile and Edge (飞桨高性能深度学习端侧推理引擎)
https://www.paddlepaddle.org.cn/lite
Apache License 2.0
6.94k stars 1.61k forks source link

使用PaddleLite转.nb模型并部署到Android端后精度下降 #7676

Closed lexiaoyuan closed 8 months ago

lexiaoyuan commented 2 years ago

基于PaddleOCR项目,使用自定义数据集和字典训练的识别模型,inference模型识别效果很好,参考文档在Linux环境编译Paddle-Lite得到预测库和opt工具,使用opt工具将inference模型转为.nb模型后,在android_demo中使用,发现识别效果变差。 同一张图,同一个字典,inference模型识别效果: Android端识别效果:

paddle-bot-old[bot] commented 2 years ago

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网文档常见问题历史Issue来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQ and Github Issue to get the answer.Have a nice day!

lexiaoyuan commented 2 years ago

这个问题目前是解决了(解决详情参考https://github.com/PaddlePaddle/PaddleOCR/issues/3876#issuecomment-953445141),但是,是通过使用PaddleOCR中的原始字典,而没有用自定义的字典,仅仅做了这一个改变。所以我推测会不会是使用自定义字典训练的识别模型,通过Paddle Lite转模型后,精度会下降。究竟是因为使用了自定义的字典训练的原因(但是推理模型表现良好啊),还是使用Paddle Lite转模型出现问题(但是转换使用原始字典ppocr/utils/ppocr_keys_v1.txt训练的模型就没有问题啊),目前确实还没有确定。

LDOUBLEV commented 2 years ago

所以我推测会不会是使用自定义字典训练的识别模型,通过Paddle Lite转模型后,精度会下降。究竟是因为使用了自定义的字典训练的原因(但是推理模型表现良好啊),还是使用Paddle Lite转模型出现问题

使用android的时候是否修改了 android demo里的默认字典? image

如果原模型转nb模型没问题,更换字典重新训练模型,再转nb模型部署时注意修改字典;

lexiaoyuan commented 2 years ago

所以我推测会不会是使用自定义字典训练的识别模型,通过Paddle Lite转模型后,精度会下降。究竟是因为使用了自定义的字典训练的原因(但是推理模型表现良好啊),还是使用Paddle Lite转模型出现问题

使用android的时候是否修改了 android demo里的默认字典? image

修改过,预处理和后处理的参数都检查过,字典都是一样的。字典不一样的话,识别结果的那个索引取出来的会是汉字。

LDOUBLEV commented 2 years ago

有用这个demo调试过吗: https://github.com/PaddlePaddle/PaddleOCR/tree/release%2F2.3/deploy/lite

android demo是基于这个做的,如果lite demo换字典后运行没问题的话,可以先排除模型的问题

lexiaoyuan commented 2 years ago

有用这个demo调试过吗: https://github.com/PaddlePaddle/PaddleOCR/tree/release%2F2.3/deploy/lite

android demo是基于这个做的,如果lite demo换字典后运行没问题的话,可以先排除模型的问题

10张图片测试结果和在安卓端的效果一样。 (没有方向分类,相关配置已改过。这里就给出一张图片的测试结果)

lexiaoyuan commented 2 years ago

补充:使用自定义字典训练的模型,在Android demo中,lite demo中pdserving(详情见https://github.com/PaddlePaddle/Serving/issues/1530)中,10张图片的输出都是一样的,(只识别了前一两个字符)。

dium6i commented 2 years ago

遇到了同样的问题,换用自己的字典训练的模型转nb后在Android平台识别效果很差,使用inference模型就一点问题都没有,如下图1,图2。 图1 Android平台识别结果: 2 10识别结果

图2 使用inference模型识别结果: 服务器识别结果

图3 修改predict_rec.py前的inference模型识别结果: 服务器修改

换用自己的字典的模型在刚训练好的时候,出现了如下 issue 中提到的模型转inference前后,识别结果有差异的问题,见上图3。 https://github.com/PaddlePaddle/PaddleOCR/issues/3758

根据官方建议,将下列代码注释

https://github.com/PaddlePaddle/PaddleOCR/blob/ebd266656b344b16e38a3299e3e77014aba337de/tools/infer/predict_rec.py#L89-L90

之后问题得以解决。有没有可能在Android Demo的代码里也有类似的数据预处理不一致问题呢?@LDOUBLEV