Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python rest_api/application.py 8891运行失败 #3242

Closed
Ywandung-Lyou opened this issue Sep 11, 2022 · 14 comments
Closed

python rest_api/application.py 8891运行失败 #3242

Ywandung-Lyou opened this issue Sep 11, 2022 · 14 comments
Assignees

Comments

@Ywandung-Lyou
Copy link

Ywandung-Lyou commented Sep 11, 2022

在Win11安装PaddlePaddle 2.3.2。在运行WINDOWS环境下搭建端到端语义检索系统的过程中,python rest_api/application.py 8891运行失败了,报错如下:

09/11/2022 10:02:37 AM YAML version (1.1.0) does not match with pipelines version (0.1.0). Issues may occur during loading. To fix this warning, save again this pipeline with the current pipelines version using Pipeline.save_to_yaml(), or downgrade to pipelines version 0.1.0.
[2022/09/11 10:02:37] ppocr DEBUG: Namespace(alpha=1.0, benchmark=False, beta=1.0, cls_batch_num=6, cls_image_shape='3, 48, 192', cls_model_dir='C:\\Users\\my_name/.paddleocr/whl\\cls\\ch_ppocr_mobile_v2.0_cls_infer', cls_thresh=0.9, cpu_threads=10, crop_res_save_dir='./output', det=True, det_algorithm='DB', det_db_box_thresh=0.6, det_db_score_mode='fast', det_db_thresh=0.3, det_db_unclip_ratio=1.5, det_east_cover_thresh=0.1, det_east_nms_thresh=0.2, det_east_score_thresh=0.8, det_fce_box_type='poly', det_limit_side_len=960, det_limit_type='max', det_model_dir='C:\\Users\\my_name/.paddleocr/whl\\det\\ch\\ch_PP-OCRv3_det_infer', det_pse_box_thresh=0.85, det_pse_box_type='quad', det_pse_min_area=16, det_pse_scale=1, det_pse_thresh=0, det_sast_nms_thresh=0.2, det_sast_polygon=False, det_sast_score_thresh=0.5, draw_img_save_dir='./inference_results', drop_score=0.5, e2e_algorithm='PGNet', e2e_char_dict_path='./ppocr/utils/ic15_dict.txt', e2e_limit_side_len=768, e2e_limit_type='max', e2e_model_dir=None, e2e_pgnet_mode='fast', e2e_pgnet_score_thresh=0.5, e2e_pgnet_valid_set='totaltext', enable_mkldnn=False, fourier_degree=5, gpu_mem=500, help='==SUPPRESS==', image_dir=None, image_orientation=False, ir_optim=True, kie_algorithm='LayoutXLM', label_list=['0', '180'], lang='ch', layout=True, layout_dict_path=None, layout_model_dir=None, layout_nms_threshold=0.5, layout_score_threshold=0.5, max_batch_size=10, max_text_length=25, merge_no_span_structure=True, min_subgraph_size=15, mode='structure', ocr=True, ocr_order_method=None, ocr_version='PP-OCRv3', output='./output', precision='fp32', process_id=0, rec=True, rec_algorithm='SVTR_LCNet', rec_batch_num=6, rec_char_dict_path='D:\\Programs\\miniconda3\\envs\\ml\\lib\\site-packages\\paddleocr\\ppocr\\utils\\ppocr_keys_v1.txt', rec_image_shape='3, 48, 320', rec_model_dir='C:\\Users\\my_name/.paddleocr/whl\\rec\\ch\\ch_PP-OCRv3_rec_infer', recovery=False, save_crop_res=False, save_log_path='./log_output/', save_pdf=False, scales=[8, 16, 32], ser_dict_path='../train_data/XFUND/class_list_xfun.txt', ser_model_dir=None, shape_info_filename=None, show_log=True, sr_batch_num=1, sr_image_shape='3, 32, 128', sr_model_dir=None, structure_version='PP-Structurev2', table=True, table_algorithm='TableAttn', table_char_dict_path=None, table_max_len=488, table_model_dir=None, total_process_num=1, type='ocr', use_angle_cls=True, use_dilation=False, use_gpu=False, use_mp=False, use_onnx=False, use_pdserving=False, use_space_char=True, use_tensorrt=False, use_xpu=False, vis_font_path='./doc/fonts/simfang.ttf', warmup=False)
Traceback (most recent call last):
  File "D:\Programs\miniconda3\envs\ml\lib\site-packages\pipelines\pipelines\base.py", line 832, in _load_or_get_component
    component_type=component_type, **component_params)
  File "D:\Programs\miniconda3\envs\ml\lib\site-packages\pipelines\nodes\base.py", line 67, in load_from_args
    instance = subclass(**kwargs)
  File "D:\Programs\miniconda3\envs\ml\lib\site-packages\pipelines\nodes\file_converter\image.py", line 64, in __init__
    use_gpu=use_gpu)
  File "D:\Programs\miniconda3\envs\ml\lib\site-packages\paddleocr\paddleocr.py", line 474, in __init__
    super().__init__(params)
  File "D:\Programs\miniconda3\envs\ml\lib\site-packages\paddleocr\tools\infer\predict_system.py", line 46, in __init__
    self.text_detector = predict_det.TextDetector(args)
  File "D:\Programs\miniconda3\envs\ml\lib\site-packages\paddleocr\tools\infer\predict_det.py", line 137, in __init__
    args, 'det', logger)
  File "D:\Programs\miniconda3\envs\ml\lib\site-packages\paddleocr\tools\infer\utility.py", line 273, in create_predictor
    predictor = inference.create_predictor(config)
RuntimeError: (NotFound) Cannot open file C:\Users\my_name/.paddleocr/whl\det\ch\ch_PP-OCRv3_det_infer/inference.pdmodel, please confirm whether the file is normal.
  [Hint: Expected static_cast<bool>(fin.is_open()) == true, but received static_cast<bool>(fin.is_open()):0 != true:1.] (at C:\home\workspace\Paddle_release\paddle\fluid\inference\api\analysis_predictor.cc:1500)


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "rest_api/application.py", line 35, in <module>
    from rest_api.controller.router import router as api_router
  File ".\rest_api\controller\router.py", line 17, in <module>
    from rest_api.controller import file_upload, search, feedback, document
  File ".\rest_api\controller\file_upload.py", line 60, in <module>
    Path(PIPELINE_YAML_PATH), pipeline_name=INDEXING_PIPELINE_NAME)
  File "D:\Programs\miniconda3\envs\ml\lib\site-packages\pipelines\pipelines\base.py", line 278, in load_from_yaml
    overwrite_with_env_variables=overwrite_with_env_variables,
  File "D:\Programs\miniconda3\envs\ml\lib\site-packages\pipelines\pipelines\base.py", line 789, in load_from_config
    components=components)
  File "D:\Programs\miniconda3\envs\ml\lib\site-packages\pipelines\pipelines\base.py", line 835, in _load_or_get_component
    raise Exception(f"Failed loading pipeline component '{name}': {e}")
Exception: Failed loading pipeline component 'ImageFileConverter': (NotFound) Cannot open file C:\Users\my_name/.paddleocr/whl\det\ch\ch_PP-OCRv3_det_infer/inference.pdmodel, please confirm whether the file is normal.
  [Hint: Expected static_cast<bool>(fin.is_open()) == true, but received static_cast<bool>(fin.is_open()):0 != true:1.] (at C:\home\workspace\Paddle_release\paddle\fluid\inference\api\analysis_predictor.cc:1500)
@w5688414
Copy link
Contributor

C:\Users\my_name/.paddleocr/whl\det\ch\ch_PP-OCRv3_det_infer/inference.pdmodel, please confirm whether the file is normal.

看上去是paddleocr的问题,请确保paddleocr是最新版,并且运行paddleocr的代码没问题

@w5688414 w5688414 self-assigned this Sep 11, 2022
@Ywandung-Lyou
Copy link
Author

请问应该怎么检查paddleocr的代码有没有问题?我安装的paddleocr版本是2.6,应该是最新的。

@w5688414
Copy link
Contributor

w5688414 commented Sep 11, 2022

请问应该怎么检查paddleocr的代码有没有问题?我安装的paddleocr版本是2.6,应该是最新的。

解决方法请参考paddleocr的issue: PaddlePaddle/PaddleOCR#1964

use_gpu=False
from paddleocr import PaddleOCR
recognize = PaddleOCR(use_angle_cls=True,
                                   lang='ch',
                                   use_gpu=use_gpu)
img_path = 'your_img_path'
result =recognize.ocr(img_path, cls=True)

@Ywandung-Lyou
Copy link
Author

看起来真有问题。

Python 3.7.13 (default, Mar 28 2022, 08:03:21) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> use_gpu=False
>>> from paddleocr import PaddleOCR
>>> recognize = PaddleOCR(use_angle_cls=True, lang='ch', use_gpu=use_gpu)
[2022/09/11 16:24:54] ppocr DEBUG: Namespace(alpha=1.0, benchmark=False, beta=1.0, cls_batch_num=6, cls_image_shape='3, 48, 192', cls_model_dir='C:\\Users\\刘源东/.paddleocr/whl\\cls\\ch_ppocr_mobile_v2.0_cls_infer', cls_thresh=0.9, cpu_threads=10, crop_res_save_dir='./output', det=True, det_algorithm='DB', det_db_box_thresh=0.6, det_db_score_mode='fast', det_db_thresh=0.3, det_db_unclip_ratio=1.5, det_east_cover_thresh=0.1, det_east_nms_thresh=0.2, det_east_score_thresh=0.8, det_fce_box_type='poly', det_limit_side_len=960, det_limit_type='max', det_model_dir='C:\\Users\\刘源东/.paddleocr/whl\\det\\ch\\ch_PP-OCRv3_det_infer', det_pse_box_thresh=0.85, det_pse_box_type='quad', det_pse_min_area=16, det_pse_scale=1, det_pse_thresh=0, det_sast_nms_thresh=0.2, det_sast_polygon=False, det_sast_score_thresh=0.5, draw_img_save_dir='./inference_results', drop_score=0.5, e2e_algorithm='PGNet', e2e_char_dict_path='./ppocr/utils/ic15_dict.txt', e2e_limit_side_len=768, e2e_limit_type='max', e2e_model_dir=None, e2e_pgnet_mode='fast', e2e_pgnet_score_thresh=0.5, e2e_pgnet_valid_set='totaltext', enable_mkldnn=False, fourier_degree=5, gpu_mem=500, help='==SUPPRESS==', image_dir=None, image_orientation=False, ir_optim=True, kie_algorithm='LayoutXLM', label_list=['0', '180'], lang='ch', layout=True, layout_dict_path=None, layout_model_dir=None, layout_nms_threshold=0.5, layout_score_threshold=0.5, max_batch_size=10, max_text_length=25, merge_no_span_structure=True, min_subgraph_size=15, mode='structure', ocr=True, ocr_order_method=None, ocr_version='PP-OCRv3', output='./output', precision='fp32', process_id=0, rec=True, rec_algorithm='SVTR_LCNet', rec_batch_num=6, rec_char_dict_path='D:\\Programs\\miniconda3\\envs\\ml\\lib\\site-packages\\paddleocr\\ppocr\\utils\\ppocr_keys_v1.txt', rec_image_shape='3, 48, 320', rec_model_dir='C:\\Users\\刘源东/.paddleocr/whl\\rec\\ch\\ch_PP-OCRv3_rec_infer', recovery=False, save_crop_res=False, save_log_path='./log_output/', save_pdf=False, scales=[8, 16, 32], ser_dict_path='../train_data/XFUND/class_list_xfun.txt', ser_model_dir=None, shape_info_filename=None, show_log=True, sr_batch_num=1, sr_image_shape='3, 32, 128', sr_model_dir=None, structure_version='PP-Structurev2', table=True, table_algorithm='TableAttn', table_char_dict_path=None, table_max_len=488, table_model_dir=None, total_process_num=1, type='ocr', use_angle_cls=True, use_dilation=False, use_gpu=False, use_mp=False, use_onnx=False, use_pdserving=False, use_space_char=True, use_tensorrt=False, use_xpu=False, vis_font_path='./doc/fonts/simfang.ttf', warmup=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Programs\miniconda3\envs\ml\lib\site-packages\paddleocr\paddleocr.py", line 501, in __init__
    super().__init__(params)
  File "D:\Programs\miniconda3\envs\ml\lib\site-packages\paddleocr\tools\infer\predict_system.py", line 46, in __init__
    self.text_detector = predict_det.TextDetector(args)
  File "D:\Programs\miniconda3\envs\ml\lib\site-packages\paddleocr\tools\infer\predict_det.py", line 137, in __init__
    args, 'det', logger)
  File "D:\Programs\miniconda3\envs\ml\lib\site-packages\paddleocr\tools\infer\utility.py", line 274, in create_predictor
    predictor = inference.create_predictor(config)
RuntimeError: (NotFound) Cannot open file C:\Users\刘源东/.paddleocr/whl\det\ch\ch_PP-OCRv3_det_infer/inference.pdmodel, please confirm whether the file is normal.
  [Hint: Expected static_cast<bool>(fin.is_open()) == true, but received static_cast<bool>(fin.is_open()):0 != true:1.] (at C:\home\workspace\Paddle_release\paddle\fluid\inference\api\analysis_predictor.cc:1500)

>>> img_path = 'your_img_path'
>>> result =recognize.ocr(img_path, cls=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'recognize' is not defined

@w5688414
Copy link
Contributor

看起来真有问题。

Python 3.7.13 (default, Mar 28 2022, 08:03:21) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> use_gpu=False
>>> from paddleocr import PaddleOCR
>>> recognize = PaddleOCR(use_angle_cls=True, lang='ch', use_gpu=use_gpu)
[2022/09/11 16:24:54] ppocr DEBUG: Namespace(alpha=1.0, benchmark=False, beta=1.0, cls_batch_num=6, cls_image_shape='3, 48, 192', cls_model_dir='C:\\Users\\刘源东/.paddleocr/whl\\cls\\ch_ppocr_mobile_v2.0_cls_infer', cls_thresh=0.9, cpu_threads=10, crop_res_save_dir='./output', det=True, det_algorithm='DB', det_db_box_thresh=0.6, det_db_score_mode='fast', det_db_thresh=0.3, det_db_unclip_ratio=1.5, det_east_cover_thresh=0.1, det_east_nms_thresh=0.2, det_east_score_thresh=0.8, det_fce_box_type='poly', det_limit_side_len=960, det_limit_type='max', det_model_dir='C:\\Users\\刘源东/.paddleocr/whl\\det\\ch\\ch_PP-OCRv3_det_infer', det_pse_box_thresh=0.85, det_pse_box_type='quad', det_pse_min_area=16, det_pse_scale=1, det_pse_thresh=0, det_sast_nms_thresh=0.2, det_sast_polygon=False, det_sast_score_thresh=0.5, draw_img_save_dir='./inference_results', drop_score=0.5, e2e_algorithm='PGNet', e2e_char_dict_path='./ppocr/utils/ic15_dict.txt', e2e_limit_side_len=768, e2e_limit_type='max', e2e_model_dir=None, e2e_pgnet_mode='fast', e2e_pgnet_score_thresh=0.5, e2e_pgnet_valid_set='totaltext', enable_mkldnn=False, fourier_degree=5, gpu_mem=500, help='==SUPPRESS==', image_dir=None, image_orientation=False, ir_optim=True, kie_algorithm='LayoutXLM', label_list=['0', '180'], lang='ch', layout=True, layout_dict_path=None, layout_model_dir=None, layout_nms_threshold=0.5, layout_score_threshold=0.5, max_batch_size=10, max_text_length=25, merge_no_span_structure=True, min_subgraph_size=15, mode='structure', ocr=True, ocr_order_method=None, ocr_version='PP-OCRv3', output='./output', precision='fp32', process_id=0, rec=True, rec_algorithm='SVTR_LCNet', rec_batch_num=6, rec_char_dict_path='D:\\Programs\\miniconda3\\envs\\ml\\lib\\site-packages\\paddleocr\\ppocr\\utils\\ppocr_keys_v1.txt', rec_image_shape='3, 48, 320', rec_model_dir='C:\\Users\\刘源东/.paddleocr/whl\\rec\\ch\\ch_PP-OCRv3_rec_infer', recovery=False, save_crop_res=False, save_log_path='./log_output/', save_pdf=False, scales=[8, 16, 32], ser_dict_path='../train_data/XFUND/class_list_xfun.txt', ser_model_dir=None, shape_info_filename=None, show_log=True, sr_batch_num=1, sr_image_shape='3, 32, 128', sr_model_dir=None, structure_version='PP-Structurev2', table=True, table_algorithm='TableAttn', table_char_dict_path=None, table_max_len=488, table_model_dir=None, total_process_num=1, type='ocr', use_angle_cls=True, use_dilation=False, use_gpu=False, use_mp=False, use_onnx=False, use_pdserving=False, use_space_char=True, use_tensorrt=False, use_xpu=False, vis_font_path='./doc/fonts/simfang.ttf', warmup=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Programs\miniconda3\envs\ml\lib\site-packages\paddleocr\paddleocr.py", line 501, in __init__
    super().__init__(params)
  File "D:\Programs\miniconda3\envs\ml\lib\site-packages\paddleocr\tools\infer\predict_system.py", line 46, in __init__
    self.text_detector = predict_det.TextDetector(args)
  File "D:\Programs\miniconda3\envs\ml\lib\site-packages\paddleocr\tools\infer\predict_det.py", line 137, in __init__
    args, 'det', logger)
  File "D:\Programs\miniconda3\envs\ml\lib\site-packages\paddleocr\tools\infer\utility.py", line 274, in create_predictor
    predictor = inference.create_predictor(config)
RuntimeError: (NotFound) Cannot open file C:\Users\刘源东/.paddleocr/whl\det\ch\ch_PP-OCRv3_det_infer/inference.pdmodel, please confirm whether the file is normal.
  [Hint: Expected static_cast<bool>(fin.is_open()) == true, but received static_cast<bool>(fin.is_open()):0 != true:1.] (at C:\home\workspace\Paddle_release\paddle\fluid\inference\api\analysis_predictor.cc:1500)

>>> img_path = 'your_img_path'
>>> result =recognize.ocr(img_path, cls=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'recognize' is not defined

请确保安装路径不要有中文哈,建议安装在D盘或者E盘,并且路径不要有中文

@Ywandung-Lyou
Copy link
Author

Ywandung-Lyou commented Sep 11, 2022

我其实用miniconda安装的python,还放在D盘(没有中文名)。不知道为什么会去C盘找inference.pdmodel。
有没有什么办法让paddlepaddle支持中文路径?

@w5688414
Copy link
Contributor

w5688414 commented Sep 11, 2022

 C:\Users\刘源东/.paddleocr/whl\det\ch\ch_PP-OCRv3_det_infer/inference.pdmodel

https://gitee.com/paddlepaddle/PaddleOCR/issues/I4N5S8

试试,或者把您的中文人名换成英文

@Ywandung-Lyou
Copy link
Author

这中文路径没法改吧?已经装了这么多程序,如果改了怕出乱子。
您分享的这段代码怎么用没看懂。这应该是个python脚本吧,是要我运行一遍吗?

SUPPORT_DET_MODEL = ['DB']
VERSION = '2.6.0.1'
SUPPORT_REC_MODEL = ['CRNN', 'SVTR_LCNet']

# 修改开始
HUB_HOME = os.environ.get('HUB_HOME')
BASE_DIR = ""
if 'HUB_HOME' in os.environ:
    BASE_DIR = os.getenv('HUB_HOME') + '/.paddleocr/'
else:
    BASE_DIR = os.path.expanduser("~/.paddleocr/")
# 修改结束

DEFAULT_OCR_MODEL_VERSION = 'PP-OCRv3'
SUPPORT_OCR_MODEL_VERSION = ['PP-OCR', 'PP-OCRv2', 'PP-OCRv3']
DEFAULT_STRUCTURE_MODEL_VERSION = 'PP-Structurev2'
SUPPORT_STRUCTURE_MODEL_VERSION = ['PP-Structure', 'PP-Structurev2']

@w5688414
Copy link
Contributor

w5688414 commented Sep 11, 2022

@Ywandung-Lyou
Copy link
Author

Ywandung-Lyou commented Sep 11, 2022

您好!
依照教程,重新安装了改过源码的paddleocr.py,但是依旧出现上述报错。
image

@w5688414
Copy link
Contributor

把hub_home换成其他路径,写成D盘或者E盘的某个路径即可。您这样修改hub_home是环境变量,需要您自己指定hub_home。

@Ywandung-Lyou
Copy link
Author

Ywandung-Lyou commented Sep 11, 2022

做了如下修改后重新安装,还是有一样的报错。
image

@w5688414
Copy link
Contributor

我尝试写了一下,您看看:

SUPPORT_DET_MODEL = ['DB']
VERSION = '2.6.0.1'
SUPPORT_REC_MODEL = ['CRNN', 'SVTR_LCNet']
HUB_HOME = "D:/ProgramData/Model_hub"
# 修改开始
BASE_DIR = ""
if os.path.exists(HUB_HOME):
    BASE_DIR = HUB_HOME + '/.paddleocr/'
else:
    BASE_DIR = os.path.expanduser("~/.paddleocr/")
# 修改结束

DEFAULT_OCR_MODEL_VERSION = 'PP-OCRv3'
SUPPORT_OCR_MODEL_VERSION = ['PP-OCR', 'PP-OCRv2', 'PP-OCRv3']
DEFAULT_STRUCTURE_MODEL_VERSION = 'PP-Structurev2'
SUPPORT_STRUCTURE_MODEL_VERSION = ['PP-Structure', 'PP-Structurev2']

请确保D:/ProgramData/Model_hub存在

@Ywandung-Lyou
Copy link
Author

解决,谢谢。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants