调试使用ppocrv4的onnx模型后本地的paddle版本模型无法使用 #14330
-
🔎 Search before asking
🐛 Bug (问题描述)1.调试onnx前本地路径模型正常使用开源项目改:2.onnx本地模型调试好后,ppocr模型无法使用PS C:\Users\wmh21> & C:/Users/wmh21/.conda/envs/paddleocr_env/python.exe d:/Thesis/1.项目代码/OCR/test_ocr_draw.py
信息: 用提供的模式无法找到文件。
C:\Users\wmh21\.conda\envs\paddleocr_env\Lib\site-packages\paddle\utils\cpp_extension\extension_utils.py:686: 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
Traceback (most recent call last):
File "d:\1.项目代码\OCR\test_ocr_draw.py", line 5, in <module>
ocr = PaddleOCR(det_model_dir='D:\\1.项目代码\\OCR\\model\\paddle\\PP-OCRv4\\ch_PP-OCRv4_det_infer',
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\wmh21\.conda\envs\paddleocr_env\Lib\site-packages\paddleocr\paddleocr.py", line 687, in __init__
super().__init__(params)
File "C:\Users\wmh21\.conda\envs\paddleocr_env\Lib\site-packages\paddleocr\tools\infer\predict_system.py", line 53, in __init__
self.text_detector = predict_det.TextDetector(args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\wmh21\.conda\envs\paddleocr_env\Lib\site-packages\paddleocr\tools\infer\predict_det.py", line 139, in __init__
) = utility.create_predictor(args, "det", logger)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\wmh21\.conda\envs\paddleocr_env\Lib\site-packages\paddleocr\tools\infer\utility.py", line 230, in create_predictor
config = inference.Config(model_file_path, params_file_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: (NotFound) Cannot open file D:\1.项目代码\OCR\model\paddle\PP-OCRv4\ch_PP-OCRv4_det_infer/inference.pdmodel, please confirm whether the file is normal.
[Hint: Expected paddle::inference::IsFileExists(prog_file_) == true, but received paddle::inference::IsFileExists(prog_file_):0 != true:1.] (at C:\home\workspace\Paddle\paddle\fluid\inference\api\analysis_config.cc:111) 使用官方的模型同样报此错误 3.重启电脑后:官方的模型正常使用,但是本地模型无法使用,更换文件夹、官方模型复制为本地模型更换和验证MD5也不行PS C:\Users\wmh21> & C:/Users/wmh21/.conda/envs/paddleocr_env/python.exe d:/Thesis/1.项目代码/OCR1/test_ocr_例子.py
download https://paddleocr.bj.bcebos.com/PP-OCRv4/chinese/ch_PP-OCRv4_det_infer.tar to D:\1.项目代码\OCR\model\ch_PP-OCRv4_det_infer.tar
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 4780/4780 [00:06<00:00, 710.17it/s]
[2024/12/02 09:31:25] ppocr DEBUG: Namespace(help='==SUPPRESS==', use_gpu=True, use_xpu=False, use_npu=False, use_mlu=False, ir_optim=True, use_tensorrt=False, min_subgraph_size=15, precision='fp32', gpu_mem=500, gpu_id=0, image_dir=None, page_num=0, det_algorithm='DB', det_model_dir='D:\\1.项目代码\\OCR\\model', det_limit_side_len=960, det_limit_type='max', det_box_type='quad', det_db_thresh=0.3, det_db_box_thresh=0.6, det_db_unclip_ratio=1.5, max_batch_size=10, use_dilation=False, det_db_score_mode='fast', det_east_score_thresh=0.8, det_east_cover_thresh=0.1, det_east_nms_thresh=0.2, det_sast_score_thresh=0.5, det_sast_nms_thresh=0.2, det_pse_thresh=0, det_pse_box_thresh=0.85, det_pse_min_area=16, det_pse_scale=1, scales=[8, 16, 32], alpha=1.0, beta=1.0, fourier_degree=5, rec_algorithm='SVTR_LCNet', rec_model_dir='D:\\1.项目代码\\OCR\\model', rec_image_inverse=True, rec_image_shape='3, 48, 320', rec_batch_num=6, max_text_length=25, rec_char_dict_path='C:\\Users\\wmh21\\.conda\\envs\\paddleocr_env\\Lib\\site-packages\\paddleocr\\ppocr\\utils\\ppocr_keys_v1.txt', use_space_char=True, vis_font_path='./doc/fonts/simfang.ttf', drop_score=0.5, e2e_algorithm='PGNet', e2e_model_dir=None, e2e_limit_side_len=768, e2e_limit_type='max', e2e_pgnet_score_thresh=0.5, e2e_char_dict_path='./ppocr/utils/ic15_dict.txt', e2e_pgnet_valid_set='totaltext', e2e_pgnet_mode='fast', use_angle_cls=True, cls_model_dir='D:\\1.项目代码\\OCR\\model', cls_image_shape='3, 48, 192', label_list=['0', '180'], cls_batch_num=6, cls_thresh=0.9, enable_mkldnn=False, cpu_threads=10, use_pdserving=False, warmup=False, sr_model_dir=None, sr_image_shape='3, 32, 128', sr_batch_num=1, draw_img_save_dir='./inference_results', save_crop_res=False, crop_res_save_dir='./output', use_mp=False, total_process_num=1, process_id=0, benchmark=False, save_log_path='./log_output/', show_log=True, use_onnx=False, return_word_box=False, output='./output', table_max_len=488, table_algorithm='TableAttn', table_model_dir=None, merge_no_span_structure=True, table_char_dict_path=None, formula_algorithm='LaTeXOCR', formula_model_dir=None, formula_char_dict_path=None, formula_batch_num=1, layout_model_dir=None, layout_dict_path=None, layout_score_threshold=0.5, layout_nms_threshold=0.5, kie_algorithm='LayoutXLM', ser_model_dir=None, re_model_dir=None, use_visual_backbone=True, ser_dict_path='../train_data/XFUND/class_list_xfun.txt', ocr_order_method=None, mode='structure', image_orientation=False, layout=True, table=True, formula=False, ocr=True, recovery=False, recovery_to_markdown=False, use_pdf2docx_api=False, invert=False, binarize=False, alphacolor=(255, 255, 255), lang='ch', det=True, rec=True, type='ocr', savefile=False, ocr_version='PP-OCRv4', structure_version='PP-StructureV2')
Traceback (most recent call last):
File "d:\1.项目代码\OCR1\test_ocr_例子.py", line 8, in <module>
# 初始化 PaddleOCR
^^^^^^^^^^^^
File "C:\Users\wmh21\.conda\envs\paddleocr_env\Lib\site-packages\paddleocr\paddleocr.py", line 687, in __init__
super().__init__(params)
File "C:\Users\wmh21\.conda\envs\paddleocr_env\Lib\site-packages\paddleocr\tools\infer\predict_system.py", line 53, in __init__
self.text_detector = predict_det.TextDetector(args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\wmh21\.conda\envs\paddleocr_env\Lib\site-packages\paddleocr\tools\infer\predict_det.py", line 139, in __init__
) = utility.create_predictor(args, "det", logger)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\wmh21\.conda\envs\paddleocr_env\Lib\site-packages\paddleocr\tools\infer\utility.py", line 230, in create_predictor
config = inference.Config(model_file_path, params_file_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: (NotFound) Cannot open file D:\1.项目代码\OCR\model/inference.pdmodel, please confirm whether the file is normal.
[Hint: Expected paddle::inference::IsFileExists(prog_file_) == true, but received paddle::inference::IsFileExists(prog_file_):0 != true:1.] (at C:\home\workspace\Paddle\paddle\fluid\inference\api\analysis_config.cc:111) 请问如何解决 🏃♂️ Environment (运行环境)1.conda的python环境(paddleocr_env) PS C:\Users\wmh21> pip list
Package Version
------------------------ -----------------
albucore 0.0.13
albumentations 1.4.10
annotated-types 0.7.0
anyio 4.6.2.post1
astor 0.8.1
asttokens 2.4.1
beautifulsoup4 4.12.3
blinker 1.9.0
certifi 2024.8.30
charset-normalizer 3.4.0
click 8.1.7
colorama 0.4.6
coloredlogs 15.0.1
comm 0.2.2
contourpy 1.3.1
cycler 0.12.1
Cython 3.0.11
debugpy 1.8.5
decorator 5.1.1
executing 2.0.1
fire 0.7.0
Flask 3.1.0
Flask-Cors 5.0.0
flatbuffers 24.3.25
fonttools 4.54.1
gunicorn 23.0.0
h11 0.14.0
httpcore 1.0.6
httpx 0.27.2
humanfriendly 10.0
idna 3.10
imageio 2.36.0
imgaug 0.4.0
ipykernel 6.29.5
ipython 8.26.0
itsdangerous 2.2.0
jedi 0.19.1
Jinja2 3.1.4
joblib 1.4.2
jupyter_client 8.6.2
jupyter_core 5.7.2
kiwisolver 1.4.7
lazy_loader 0.4
lmdb 1.5.1
lxml 5.3.0
MarkupSafe 3.0.2
matplotlib 3.9.2
matplotlib-inline 0.1.7
mpmath 1.3.0
nest-asyncio 1.6.0
networkx 3.4.2
numpy 1.26.4
nvidia-cublas-cu12 12.3.4.1
nvidia-cuda-nvrtc-cu12 12.6.77
nvidia-cuda-runtime-cu12 12.3.101
nvidia-cudnn-cu12 9.0.0.312
nvidia-cufft-cu12 11.2.1.3
nvidia-curand-cu12 10.3.5.147
nvidia-cusolver-cu12 11.6.1.9
nvidia-cusparse-cu12 12.3.1.170
nvidia-nvjitlink-cu12 12.6.77
onnx 1.16.2
onnxruntime-gpu 1.20.0
opencv-contrib-python 4.10.0.84
opencv-python 4.10.0.84
opencv-python-headless 4.10.0.84
opt-einsum 3.3.0
packaging 24.2
paddle2onnx 0.8.1
paddleocr 2.9.1
paddlepaddle-gpu 3.0.0.dev20241112
parso 0.8.4
pillow 11.0.0
pip 24.2
platformdirs 4.2.2
prompt_toolkit 3.0.47
protobuf 3.20.2
psutil 6.1.0
pure_eval 0.2.3
pyclipper 1.3.0.post6
pydantic 2.9.2
pydantic_core 2.23.4
Pygments 2.18.0
pyparsing 3.2.0
pyreadline3 3.5.4
python-dateutil 2.9.0.post0
python-docx 1.1.2
pywin32 306
PyYAML 6.0.2
pyzmq 26.1.0
RapidFuzz 3.10.1
requests 2.32.3
scikit-image 0.24.0
scikit-learn 1.5.2
scipy 1.14.1
setuptools 75.1.0
shapely 2.0.6
six 1.16.0
sniffio 1.3.1
soupsieve 2.6
stack-data 0.6.3
sympy 1.13.3
termcolor 2.5.0
threadpoolctl 3.5.0
tifffile 2024.9.20
tomli 2.1.0
tornado 6.4.1
tqdm 4.67.0
traitlets 5.14.3
typing_extensions 4.12.2
urllib3 2.2.3
wcwidth 0.2.13
Werkzeug 3.1.3
wheel 0.44.0 2.操作系统windows11 23h2
PS C:\Users\wmh21> nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Fri_Jun_14_16:44:19_Pacific_Daylight_Time_2024
Cuda compilation tools, release 12.6, V12.6.20
Build cuda_12.6.r12.6/compiler.34431801_0
PS C:\Users\wmh21> nvidia-smi
Mon Dec 2 09:46:20 2024
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 566.14 Driver Version: 566.14 CUDA Version: 12.7 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Driver-Model | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 NVIDIA GeForce RTX 4060 ... WDDM | 00000000:01:00.0 On | N/A |
| N/A 52C P8 5W / 81W | 1298MiB / 8188MiB | 0% Default |
| | | N/A |
🌰 Minimal Reproducible Example (最小可复现问题的Demo)from paddleocr import PaddleOCR
# 指定本地模型路径
det_model_dir = r"D:\1.项目代码\OCR\model\paddle\PP-OCRv4\ch_PP-OCRv4_det_infer" # 检测模型路径
rec_model_dir = r"D:\1.项目代码\OCR\model\paddle\PP-OCRv4\ch_PP-OCRv4_rec_infer" # 识别模型路径
cls_model_dir = r"D:\1.项目代码\OCR\model\paddle\PP-OCRv4\ch_ppocr_mobile_v2.0_cls_infer" # 分类模型路径(可选)
# 初始化 PaddleOCR
ocr = PaddleOCR(
det_model_dir=det_model_dir,
rec_model_dir=rec_model_dir,
cls_model_dir=cls_model_dir, # 如果不需要角度分类,可以省略此行
use_angle_cls=True, # 启用角度分类
lang='ch' # 设置识别语言为中文,也可以设置为 'en' 英文等其他语言
)
# 指定图片路径
img_path = r"C:\Users\wmh21\Desktop\1.jpg"
# 进行 OCR 识别
result = ocr.ocr(img_path, cls=True)
# 打印结果,仅输出文字
for line in result:
print(line) # 仅输出文字部分 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
根据您提供的问题描述和错误信息,问题主要集中在以下几点:
以下是详细的排查和解决步骤: 1. 检查模型文件的完整性
2. 检查路径配置是否正确
3. 确保ONNX调试环境未影响PaddleOCR
4. 使用官方模型测试
5. 调试代码
6. 重新导出本地模型
7. 参考相关问题
总结通过上述操作,您应能定位并解决问题。如果问题仍然存在,可以尝试以下操作:
希望以上内容能帮助您解决问题! Response generated by 🤖 feifei-bot | chatgpt-4o-latest |
Beta Was this translation helpful? Give feedback.
-
@GreatV 重建python环境并将路径更改为英文路径后模型成功加载,但是想问一下之前同样的代码为什么中文路径可以加载 |
Beta Was this translation helpful? Give feedback.
-
根据您的问题描述和相关错误信息,我建议您按照以下步骤解决问题:
# 首先使用paddle2onnx将paddle模型转换为onnx格式
paddle2onnx --model_dir ./paddle/PP-OCRv4/ch_PP-OCRv4_det_infer \
--model_filename inference.pdmodel \
--params_filename inference.pdiparams \
--save_file ./onnx/det_model.onnx \
--opset_version 11 \
--enable_onnx_checker True
# 其他模型类似转换...
# 使用onnx模型
ocr = PaddleOCR(
use_onnx=True,
det_model_dir='path/to/det_model.onnx',
rec_model_dir='path/to/rec_model.onnx'
)
# 重启环境后再使用paddle模型
ocr = PaddleOCR(
det_model_dir='path/to/det_paddle_model',
rec_model_dir='path/to/rec_paddle_model'
)
这样应该可以解决您遇到的问题。如果还有问题,欢迎继续反馈。 Response generated by 🤖 feifei-bot | claude-3-5-sonnet-latest |
Beta Was this translation helpful? Give feedback.
猜测可能是中文名路径解析问题导致的。
D:\1.项目代码
这里有一个点。当然这个需要你那里实验一下,去掉点后,中文路径是否可以加载。