【无标题】

works:

  1. .dec/rec :parameters --> inference -->onnx
  2. deal srt contrast
  3. cls+ocr
  4. flask
    1+2 要求:图像输入 → 输出文本 + 文本框 + 文本比对
    检测 ONNX:输入图像 → 输出 文本框坐标
    识别 ONNX(端到端内嵌字典 + 解码):输入裁剪文本行图 → 直接输出字符串文本
    上层业务:拿到 框坐标 + 文本 → 执行文本比对

Start

1.1 从训练权重 → Paddle 推理模型 → ONNX 模型

bash 复制代码
python3 tools/export_model.py -c ./configs/det/PP-OCRv5/PP-OCRv5_mobile_det.yml -o Global.pretrained_model=./output/PP-OCRv5_mobile_det/first_train/best_accuracy.pdparams -o  Global.save_inference_dir=output/infer/PP-OCRv5_mobile_det_infer/first_det_0610
'''
(paddle) root@autodl-container-d8dlmpu3b9-2023ec6b:~/PaddleOCR-main# python3 tools/export_model.py -c ./configs/det/PP-OCRv5/PP-OCRv5_mobile_det.yml -o Global.pretrained_model=./output/PP-OCRv5_mobile_det/first_train/best_accuracy.pdparams -o  Global.save_inference_dir=output/infer/PP-OCRv5_mobile_det_infer/first_det
/root/miniconda3/envs/paddle/lib/python3.10/site-packages/paddle/utils/cpp_extension/extension_utils.py:715: UserWarning: No ccache found. Please be aware that recompiling all source files may be required. You can download and install ccache from: https://github.com/ccache/ccache/blob/master/doc/INSTALL.md
  warnings.warn(warning_message)
Skipping import of the encryption module.
W0610 15:23:09.306272  1993 gpu_resources.cc:114] Please NOTE: device: 0, GPU Compute Capability: 8.9, Driver API Version: 13.0, Runtime API Version: 11.8
[2026/06/10 15:23:09] ppocr INFO: load pretrain successful from ./output/PP-OCRv5_mobile_det/first_train/best_accuracy
[2026/06/10 15:23:09] ppocr INFO: Export inference config file to output/infer/PP-OCRv5_mobile_det_infer/first_det/inference.yml
Skipping import of the encryption module
[2026/06/10 15:23:12] ppocr INFO: inference model is saved to output/infer/PP-OCRv5_mobile_det_infer/first_det/inference
'''
python 复制代码
python3 tools/export_model.py -c ./configs/rec/PP-OCRv5/PP-OCRv5_mobile_rec.yml -o Global.pretrained_model=./output/PP-OCRv5_mobile_rec/first/best_accuracy.pdparams -o  Global.save_inference_dir=output/infer/PP-OCRv5_mobile_rec_infer/first_rec_0610

(paddle) root@autodl-container-d8dlmpu3b9-2023ec6b:~/PaddleOCR-main# python3 tools/export_model.py -c ./configs/rec/PP-OCRv5/PP-OCRv5_mobile_rec.yml -o Global.pretrained_model=./output/PP-OCRv5_mobile_rec/first/best_accuracy.pdparams -o  Global.save_inference_dir=output/infer/PP-OCRv5_mobile_rec_infer/first_rec                                         Skipping import of the encryption module.
W0610 15:28:27.813534  2532 gpu_resources.cc:114] Please NOTE: device: 0, GPU Compute Capability: 8.9, Driver API Version: 13.0, Runtime API Version: 11.8
[2026/06/10 15:28:28] ppocr INFO: load pretrain successful from ./output/PP-OCRv5_mobile_rec/first/best_accuracy
[2026/06/10 15:28:28] ppocr INFO: Export inference config file to output/infer/PP-OCRv5_mobile_rec_infer/first_rec/inference.yml
Skipping import of the encryption module
[2026/06/10 15:28:31] ppocr INFO: inference model is saved to output/infer/PP-OCRv5_mobile_rec_infer/first_rec/inference

export_model.py生成ONNX

python 复制代码
import paddle
from paddle.static import InputSpec
from ppocr.modeling.architectures import build_model
from ppocr.postprocess import build_post_process
from ppocr.utils.save_load import load_pretrained_params
import yaml

# 1. 加载配置文件
config_path = './configs/det/PP-OCRv5/PP-OCRv5_mobile_det.yml'
with open(config_path, 'r') as f:
    config = yaml.safe_load(f)

# 2. 构建模型并加载权重
model = build_model(config['Architecture'])
load_pretrained_params(model, './output/PP-OCRv5_mobile_det/first_train/best_accuracy.pdparams')
model.eval()  # 切换到评估模式

# 3. 定义输入张量的形状(根据你的模型实际输入调整)
# OCR 检测模型通常输入为 [batch_size, channels, height, width]
input_spec = [InputSpec(shape=[1, 3, 640, 640], dtype='float32', name='image')]

# 4. 导出为 ONNX 格式
paddle.onnx.export(
    layer=model,
    path='./output/infer/PP-OCRv5_mobile_det_infer/first_det_0610/model',
    input_spec=input_spec,
    opset_version=13,  # 推荐使用 13 或更高版本以支持现代算子
    enable_onnx_checker=True
)

print("✅ ONNX 模型已成功导出!")

REC 导出ONNX

python 复制代码
import paddle
from paddle.static import InputSpec
from ppocr.modeling.architectures import build_model
from ppocr.utils.save_load import load_pretrained_params
# 导入官方的配置解析工具
from tools.program import get_config 

# 1. 使用官方工具加载配置(会自动读取你修改的字典路径并补全参数)
config_path = './configs/rec/PP-OCRv5/PP-OCRv5_mobile_rec.yml'
config, _, _ = get_config(config_path, show=False)

# 2. 构建模型并加载权重
model = build_model(config['Architecture'])
load_pretrained_params(model, './output/PP-OCRv5_mobile_rec/first/best_accuracy.pdparams')
model.eval()

# 3. 定义输入张量的形状(识别模型标准尺寸)
input_spec = [InputSpec(shape=[1, 3, 48, 320], dtype='float32', name='image')]

# 4. 导出为 ONNX 格式
paddle.onnx.export(
    layer=model,
    path='./output/infer/PP-OCRv5_mobile_rec_infer/first_rec_0610/model',
    input_spec=input_spec,
    opset_version=13,
    enable_onnx_checker=True
)

print("✅ 识别模型 ONNX 已成功导出!")
bash 复制代码
相关推荐
驴友花雕13 分钟前
【花雕动手做】行空板 K10 系列实验之人工智能语音识别小车的10个参考案例
人工智能·单片机·嵌入式硬件·语音识别·行空板 k10 系列实验·花雕动手做·小车的10个参考案例
火山引擎开发者社区2 小时前
DeepSeek-V4 Pro 发布,veStack Day 0 完成模型适配
人工智能
2501_926978332 小时前
AGI 的四种瓶颈:资源型还是发现型--以及DSH的位置
人工智能·经验分享·笔记·ai写作
Q463913492 小时前
线下销售复盘难落地,AI 会话设备能帮上啥忙
人工智能·自然语言处理
ebok.2 小时前
国产大模型落地业务系统的优选载体:京微智枢信创 AI 业务支撑平台
大数据·人工智能·低代码·ai
wujian83112 小时前
怎么用文心生成word文档?从格式错乱到智能导出,AI导出鸭让创作再无后顾之忧
人工智能·ai·word·豆包·deepseek·ai导出鸭
动物园猫3 小时前
猪危险行为目标检测数据集:3类别、5,000+张图像 | 目标检测
人工智能·目标检测·计算机视觉
ai产品老杨3 小时前
AI视频分析并发优化完整流程:解决多路视频并发不足与高延迟排查指南
人工智能·音视频
why技术3 小时前
AI 写的文章,可能都带着手敲一遍都去不掉的“隐形水印”。
前端·人工智能·后端
罗西的思考3 小时前
【Agent OS / AIOS】AOHP 深度解读:当 OS 开始为 Agent 而设计
人工智能·算法·机器学习