Skip to content

将pytorch模型转为onnx,将来文本框分类、检测、识别#308

Open
ZhangXinNan wants to merge 4 commits intoWenmuZhou:devfrom
ZhangXinNan:dev_onnx
Open

将pytorch模型转为onnx,将来文本框分类、检测、识别#308
ZhangXinNan wants to merge 4 commits intoWenmuZhou:devfrom
ZhangXinNan:dev_onnx

Conversation

@ZhangXinNan
Copy link
Contributor

@ZhangXinNan ZhangXinNan commented Jan 5, 2026

模型转换

# cls
python tools/export.py -c configs/cls/cls_mv3.yml -o Global.pretrained_model=weights/ch_ppocr_mobile_v2.0_cls_train/best_accuracy.pth
# ./output/cls/mv3/export/model.onnx

# det
python tools/export.py -c configs/det/ch_PP-OCRv3/ch_PP-OCRv3_det_student.yml -o Global.pretrained_model=weights/ch_PP-OCRv3_det_distill/student.pth
# ./output/det/ch_PP-OCR_V3_det/export/model.onnx

python tools/export.py -c configs/det/ch_PP-OCRv4/ch_PP-OCRv4_det_student.yml -o Global.pretrained_model=weights/ch_PP-OCRv4_det_train/best_accuracy.pth
# ./output/det/ch_PP-OCRv4/export/model.onnx

python tools/export.py -c configs/det/ch_PP-OCRv4/ch_PP-OCRv4_det_teacher.yml -o Global.pretrained_model=weights/ch_PP-OCRv4_det_server_train/best_accuracy.pth
# ./output/det/h_PP-OCRv4_hgnet/export/model.onnx

python tools/export.py -c configs/det/PP-OCRv5/PP-OCRv5_mobile_det.yml -o Global.pretrained_model=/Users/zhangxin/github/PaddleOCR2Pytorch/models/ptocrv5/ptocr_v5_mobile_det.pth  Global.output_dir=./output/det/PP-OCRv5_mobile_det
# ./output/det/PP-OCRv5_mobile_det/export/model.onnx

python tools/export.py -c configs/det/PP-OCRv5/PP-OCRv5_server_det.yml -o Global.pretrained_model=/Users/zhangxin/github/PaddleOCR2Pytorch/models/ptocrv5/ptocr_v5_server_det.pth Global.output_dir=./output/det/PP-OCRv5_server_det
# ./output/det/PP-OCRv5_server_det/export/model.onnx


# rec
python tools/export.py -c configs/rec/PP-OCRv3/ch_PP-OCRv3_rec.yml -o Global.pretrained_model=weights/ch_PP-OCRv3_rec/student.pth
# ./output/rec/rec_ppocr_v3/export/model.onnx

python tools/export.py -c configs/rec/PP-OCRv4/ch_PP-OCRv4_rec.yml -o Global.pretrained_model=weights/ch_PP-OCRv4_rec_train/student.pth
# ./output/rec/rec_ppocr_v4/export/model.onnx

python tools/export.py -c configs/rec/PP-OCRv4/ch_PP-OCRv4_rec_hgnet.yml -o Global.pretrained_model=weights/ch_PP-OCRv4_rec_server_train/best_accuracy.pth
# ./output/rec/rec_ppocr_v4_hgnet/export/model.onnx

python tools/export.py -c configs/rec/PP-OCRv5/PP-OCRv5_mobile_rec.yml -o Global.pretrained_model=/Users/zhangxin/github/PaddleOCR2Pytorch/models/ptocrv5/ptocr_v5_mobile_rec.pth Global.output_dir=./output/rec/PP-OCRv5_mobile_rec
# ./output/rec/PP-OCRv5_mobile_rec/export/model.onnx

python tools/export.py -c configs/rec/PP-OCRv5/PP-OCRv5_server_rec.yml -o Global.pretrained_model=/Users/zhangxin/github/PaddleOCR2Pytorch/models/ptocrv5/ptocr_v5_server_rec.pth Global.output_dir=./output/rec/PP-OCRv5_server_rec
# ./output/rec/PP-OCRv5_server_rec/export/model.onnx

@ZhangXinNan
Copy link
Contributor Author

ZhangXinNan commented Jan 5, 2026

使用onnx推理:

# cls
python tools/infer/predict_cls.py --cls_model_dir=./output/cls/mv3/export --image_dir=doc/imgs_words/en

# det
python tools/infer/predict_det.py --det_model_dir=./output/det/ch_PP-OCR_V3_det/export --image_dir=doc/imgs/1.jpg
python tools/infer/predict_det.py --det_model_dir=./output/det/ch_PP-OCRv4/export --image_dir=doc/imgs/11.jpg
python tools/infer/predict_det.py --det_model_dir=./output/det/h_PP-OCRv4_hgnet/export --image_dir=doc/imgs/12.jpg
python tools/infer/predict_det.py --det_model_dir=./output/det/PP-OCRv5_mobile_det/export --image_dir=doc/imgs/00006737.jpg
python tools/infer/predict_det.py --det_model_dir=./output/det/PP-OCRv5_server_det/export --image_dir=doc/imgs/00009282.jpg


# rec
python tools/infer/predict_rec.py --rec_model_dir=./output/rec/rec_ppocr_v3/export --image_dir=doc/imgs_words/ch --rec_batch_num=1
python tools/infer/predict_rec.py --rec_model_dir=./output/rec/rec_ppocr_v4/export --image_dir=doc/imgs_words/ch --rec_batch_num=1
python tools/infer/predict_rec.py --rec_model_dir=./output/rec/rec_ppocr_v4_hgnet/export --image_dir=doc/imgs_words/ch --rec_batch_num=1
python tools/infer/predict_rec.py --rec_model_dir=./output/rec/PP-OCRv5_mobile_rec/export --image_dir=doc/imgs_words/ch --rec_batch_num=1
python tools/infer/predict_rec.py --rec_model_dir=./output/rec/PP-OCRv5_server_rec/export --image_dir=doc/imgs_words/ch --rec_batch_num=1

# det + cls + rec
python tools/infer/predict_system.py \
    --cls_model_dir=./output/cls/mv3/export \
    --det_model_dir=./output/det/PP-OCRv5_mobile_det/export  \
    --rec_model_dir=./output/rec/PP-OCRv5_mobile_rec/export \
    --image_dir=doc/imgs/1.jpg \
    --use_angle_cls=true \
    --rec_batch_num=1

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

Successfully merging this pull request may close these issues.

1 participant