PaddleOCR icon indicating copy to clipboard operation
PaddleOCR copied to clipboard

paddleocr3.0.0本地模型问题

Open wqw0806 opened this issue 6 months ago • 9 comments

🔎 Search before asking

  • [x] I have searched the PaddleOCR Docs and found no similar bug report.
  • [x] I have searched the PaddleOCR Issues and found no similar bug report.
  • [x] I have searched the PaddleOCR Discussions and found no similar bug report.

🐛 Bug (问题描述)

使用paddleocr3.0.0读取本地下载的模型,总是不使用自己下载的模型,报错Creating model: ('PP-OCRv5_server_det', 'models/v5/PP-OCRv5_mobile_det_infer') Traceback (most recent call last): File "E:\PythonCode\PaddleOCR\测试ppocrv5.py", line 48, in ocr = PaddleOCR( File "E:\PythonCode\PaddleOCR\paddleocr_pipelines\ocr.py", line 144, in init super().init(**base_params) File "E:\PythonCode\PaddleOCR\paddleocr_pipelines\base.py", line 73, in init self.paddlex_pipeline = self._create_paddlex_pipeline() File "E:\PythonCode\PaddleOCR\paddleocr_pipelines\base.py", line 107, in _create_paddlex_pipeline return create_pipeline(config=self.merged_paddlex_config, **kwargs) File "D:\Anaconda\anaconda3\envs\paddleocr3.0.0\lib\site-packages\paddlex\inference\pipelines_init.py", line 165, in create_pipeline pipeline = BasePipeline.get(pipeline_name)( File "D:\Anaconda\anaconda3\envs\paddleocr3.0.0\lib\site-packages\paddlex\utils\deps.py", line 195, in _wrapper return old_init_func(self, *args, **kwargs) File "D:\Anaconda\anaconda3\envs\paddleocr3.0.0\lib\site-packages\paddlex\inference\pipelines_parallel.py", line 103, in init self._pipeline = self._create_internal_pipeline(config, self.device) File "D:\Anaconda\anaconda3\envs\paddleocr3.0.0\lib\site-packages\paddlex\inference\pipelines_parallel.py", line 158, in _create_internal_pipeline return self.pipeline_cls( File "D:\Anaconda\anaconda3\envs\paddleocr3.0.0\lib\site-packages\paddlex\inference\pipelines\ocr\pipeline.py", line 114, in init self.text_det_model = self.create_model( File "D:\Anaconda\anaconda3\envs\paddleocr3.0.0\lib\site-packages\paddlex\inference\pipelines\base.py", line 107, in create_model model = create_predictor( File "D:\Anaconda\anaconda3\envs\paddleocr3.0.0\lib\site-packages\paddlex\inference\models_init.py", line 75, in create_predictor model_name == config["Global"]["model_name"] AssertionError: Model name mismatch,please input the correct model dir.

🏃‍♂️ Environment (运行环境)

paddleocr3.0.0

🌰 Minimal Reproducible Example (最小可复现问题的Demo)

text_detection_model_dir ="models/v5/PP-OCRv5_mobile_det_infer" text_recognition_model_dir = "models/v5/PP-OCRv5_mobile_rec_infer"

ocr = PaddleOCR( use_doc_orientation_classify=False, # 文档方向分类模型 默认true 检测整个文档图像的方向并纠正(即0度,90度,180度,270度)。 use_doc_unwarping=False, # 文本图像矫正模型 默认true 纠正图像中的透视变形或弯曲,使文档看起来像是正面拍摄的平面图像。 use_textline_orientation=False, # 文本行方向分类模型 默认true 识别文本行是水平排列还是垂直排列。 text_detection_model_dir=text_detection_model_dir, text_recognition_model_dir=text_recognition_model_dir, device="gpu" #device="gpu:3" 指定第三块gpu运行 )

运行时打印Creating model: ('PP-OCRv5_server_det', 'models/v5/PP-OCRv5_mobile_det_infer') 为什么不加载自己本地的模型

wqw0806 avatar Jun 05 '25 07:06 wqw0806

本地模型中的inference.yml方便提供下吗?

cuicheng01 avatar Jun 05 '25 07:06 cuicheng01

本地模型中的方便提供下吗?inference.yml

Global:
  model_name: PP-OCRv5_mobile_det
Hpi:
  backend_configs:
    paddle_infer:
      trt_dynamic_shapes: &id001
        x:
        - - 1
          - 3
          - 32
          - 32
        - - 1
          - 3
          - 736
          - 736
        - - 1
          - 3
          - 4000
          - 4000
    tensorrt:
      dynamic_shapes: *id001
PreProcess:
  transform_ops:
  - DecodeImage:
      channel_first: false
      img_mode: BGR
  - DetLabelEncode: null
  - DetResizeForTest:
      resize_long: 960
  - NormalizeImage:
      mean:
      - 0.485
      - 0.456
      - 0.406
      order: hwc
      scale: 1./255.
      std:
      - 0.229
      - 0.224
      - 0.225
  - ToCHWImage: null
  - KeepKeys:
      keep_keys:
      - image
      - shape
      - polys
      - ignore_tags
PostProcess:
  name: DBPostProcess
  thresh: 0.3
  box_thresh: 0.6
  max_candidates: 1000
  unclip_ratio: 1.5

模型就是在https://paddlepaddle.github.io/PaddleOCR/latest/version3.x/pipeline_usage/OCR.html#1-ocr这里下载的

Image下载了det和rec模型

wqw0806 avatar Jun 05 '25 07:06 wqw0806

请问解决了吗?

yvway avatar Jun 06 '25 03:06 yvway

把模型名中的“_infer”删去试试

yvway avatar Jun 06 '25 04:06 yvway

模型名称里是server版本,路径里是mobile版本,估计是这个原因

GreatV avatar Jun 06 '25 04:06 GreatV

在PaddleOCR()内部有两个参数用来指定模型名称,你需要将这两个参数设置为你自己本地的模型模型名称,比如你本地是移动端模型就在.yml文件中找到这个模型的名称然后设置

o0ii0o avatar Jun 12 '25 13:06 o0ii0o

Image 指定模型路径这个参数根本不生效 vim ./pyenv/lib/python3.10/site-packages/paddlex/inference/utils/official_models.py 我改了它那个源码下载的位置也识别不到我手动下载的模型 还是走的网络请求

Image

zhangsan-feng avatar Jun 20 '25 06:06 zhangsan-feng

请问解决了吗?

xiangmingzi1 avatar Jun 20 '25 11:06 xiangmingzi1

请问解决了吗?

没有 尝试了很多办法都不行 回退版本了 2.8 可以实现需求

zhangsan-feng avatar Jun 20 '25 12:06 zhangsan-feng

我也是用的mobile模型,添加了

text_detection_model_name="PP-OCRv5_mobile_det",
text_recognition_model_name="PP-OCRv5_mobile_rec",

就能正常使用。

完整的参数:

PaddleOCR(
          use_doc_orientation_classify=False,
          use_doc_unwarping=False,
          use_textline_orientation=False,
          device='gpu' if use_gpu else 'cpu', 
          text_detection_model_dir=det_model_path,
          text_recognition_model_dir=rec_model_path,
          text_detection_model_name="PP-OCRv5_mobile_det",
          text_recognition_model_name="PP-OCRv5_mobile_rec"
)

m4x1r avatar Jun 28 '25 06:06 m4x1r

把模型名中的“_infer”删去试试

我也遇到了这样的问题,删掉 model_name 结尾的 _infer 然后就可以正常运行了。


# 错误示范
det_model_name = "PP-OCRv5_server_det_infer"
rec_model_name = "PP-OCRv5_server_rec_infer"

# 正确示范
det_model_name = "PP-OCRv5_server_det"
rec_model_name = "PP-OCRv5_server_rec"

ocr = PaddleOCR( use_textline_orientation = True , lang = "ch" , device = device , text_det_box_thresh = 0.2 ,
                         text_detection_model_name = det_model_name , text_recognition_model_name = rec_model_name ,
                         text_detection_model_dir = det_model_dir , text_recognition_model_dir = rec_model_dir )

tinycen avatar Jul 19 '25 11:07 tinycen

把模型名中的“_infer”删去试试

我也遇到了这样的问题,删掉 model_name 结尾的 _infer 然后就可以正常运行了。

错误示范

det_model_name = "PP-OCRv5_server_det_infer" rec_model_name = "PP-OCRv5_server_rec_infer"

正确示范

det_model_name = "PP-OCRv5_server_det" rec_model_name = "PP-OCRv5_server_rec"

ocr = PaddleOCR( use_textline_orientation = True , lang = "ch" , device = device , text_det_box_thresh = 0.2 , text_detection_model_name = det_model_name , text_recognition_model_name = rec_model_name , text_detection_model_dir = det_model_dir , text_recognition_model_dir = rec_model_dir )

感谢指正

zhangsan-feng avatar Jul 20 '25 03:07 zhangsan-feng