frotms / PaddleOCR2Pytorch

PaddleOCR inference in PyTorch. Converted from [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR)
Apache License 2.0
860 stars 168 forks source link

PP-OCRv3的识别模型配置文件和paddleocr不一样 #86

Closed JinXuan0604 closed 5 months ago

JinXuan0604 commented 5 months ago

PaddleOCR/configs/rec/PP-OCRv3/ch_PP-OCRv3_rec.yml使用的算法是algorithm: SVTR_LCNet,链接:https://github.com/PaddlePaddle/PaddleOCR/blob/dygraph/configs/rec/PP-OCRv3/ch_PP-OCRv3_rec.yml 而PaddleOCR2Pytorch/configs/rec/PP-OCRv3/ch_PP-OCRv3_rec.yml使用的算法是algorithm: SVTR,链接:https://github.com/frotms/PaddleOCR2Pytorch/blob/main/configs/rec/PP-OCRv3/ch_PP-OCRv3_rec.yml

请问这是怎么回事,我还能成功转换模型吗?

JinXuan0604 commented 5 months ago

检测模型已经导出且预测成功了,但是识别模型我发现配置文件不一样,无法导出成功 // 导出检测模型 python3 ./converter/det_converter.py --yaml_path ./configs/det/ch_PP-OCRv3/ch_PP-OCRv3_det.yml --src_model_path /home/output/CCPD/det/

// 检测模型预测 python ./tools/infer/predict_det.py --det_model_path infer.pth --image_dir '/home/vlpRecognition/CCPD2020/ccpd_green/val/3025-96_108-271&444_511&549-511&549_293&523_271&444_495&459-0_0_3_24_32_32_32_33-81-159.jpg' --det_yaml_path ./configs/det/ch_PP-OCRv3/ch_PP-OCRv3_det.yml

// 导出识别模型,模型配置文件不一样导致导出失败 image

frotms commented 5 months ago

@JinXuan0604 请使用以下两个脚本试试:

./converter/ch_ppocr_v3_det_converter.py

./converter/ch_ppocr_v3_rec_converter.py 
JinXuan0604 commented 5 months ago

@JinXuan0604 请使用以下两个脚本试试:

./converter/ch_ppocr_v3_det_converter.py

./converter/ch_ppocr_v3_rec_converter.py 

这个脚本我昨天试过,识别模型可以转换成功,但是有2个问题,1个是ch_ppocr_v3_rec_converter.py脚本代码中第78行'algorithm':'CRNN',这与原paddleocr的算法(algorithm: SVTR_LCNet)并不一致,另1个问题是我使用导出的模型进行识别,输出都是空。 图片1:模型转换成功 image

图片2:导出后的模型试了很多张图片,输出都是空 image

frotms commented 5 months ago

@JinXuan0604 1、paddleocr的之前也是CRNN,可能更新的时候调整了代码和配置,但算法是一样的 2、更新代码时哪里没有对齐,晚点看下

frotms commented 5 months ago

@JinXuan0604 试一下:

python ./converter/ch_ppocr_v3_rec_converter.py --src_model_path ch_PP-OCRv3_rec_train

python ./tools/infer/predict_rec.py  --rec_model_path ./ch_ptocr_v3_rec_infer.pth --rec_image_shape 3,48,320 --image_dir ./doc/imgs_words/ch/word_1.jpg

我这里是可以正常推理的。如果还不行可以加QQ私聊下

JinXuan0604 commented 5 months ago

@JinXuan0604 试一下:

python ./converter/ch_ppocr_v3_rec_converter.py --src_model_path ch_PP-OCRv3_rec_train

python ./tools/infer/predict_rec.py  --rec_model_path ./ch_ptocr_v3_rec_infer.pth --rec_image_shape 3,48,320 --image_dir ./doc/imgs_words/ch/word_1.jpg

我这里是可以正常推理的。如果还不行可以加QQ私聊下

我找到原因了,我对预训练模型提取了学生模型的权重,然后基于这个权重使用CCPD车牌数据集进行了微调,使用python ./converter/ch_ppocr_v3_rec_converter.py --src_model_path /home/PaddleOCR/output/CCPD/rec/命令进行转换时报错KeyError: 'Student.backbone.conv1._conv.weight',这时候我修改了ch_ppocr_v3_rec_converter.py文件中的load_paddle_weights函数,将节点名称转换代码注释掉了,这时候转换预训练模型和我微调后的预训练模型都可以成功,但是推理时输出时空的。

那么问题来了,我想要的是转换微调后的预训练模型,为什么可以成功转换而推理为空呢?

我的qq是459754206,很感谢你的解答