3. PaddleOCR - 샘플코드 실행

2022. 6. 13. 13:40OCR/PaddleOCR

반응형

아래 코드를 실행

from paddleocr import PaddleOCR,draw_ocr
# Paddleocr supports Chinese, English, French, German, Korean and Japanese.
# You can set the parameter `lang` as `ch`, `en`, `french`, `german`, `korean`, `japan`
# to switch the language model in order.
ocr = PaddleOCR(use_angle_cls=True, lang='korean') # need to run only once to download and load model into memory
img_path = 'example/0.jpg'
result = ocr.ocr(img_path, cls=True)
for line in result:
    print(line)

오류 발생

Traceback (most recent call last):
  File "d:/dev/workspace_py/paddleocr/test1.py", line 1, in <module>
    from paddleocr import PaddleOCR,draw_ocr
  File "C:\Users\SolutionDev\anaconda3\envs\paddle_env\lib\site-packages\paddleocr\__init__.py", line 14, in <module>   
    from .paddleocr import *
  File "C:\Users\SolutionDev\anaconda3\envs\paddle_env\lib\site-packages\paddleocr\paddleocr.py", line 21, in <module>  
    import paddle
    from .fluid import monkey_patch_variable
  File "C:\Users\SolutionDev\anaconda3\envs\paddle_env\lib\site-packages\paddle\fluid\__init__.py", line 36, in <module>
    from . import framework
  File "C:\Users\SolutionDev\anaconda3\envs\paddle_env\lib\site-packages\paddle\fluid\framework.py", line 35, in <module>
    from .proto import framework_pb2
  File "C:\Users\SolutionDev\anaconda3\envs\paddle_env\lib\site-packages\paddle\fluid\proto\framework_pb2.py", line 33, in <module>
    _descriptor.EnumValueDescriptor(
  File "C:\Users\SolutionDev\anaconda3\envs\paddle_env\lib\site-packages\google\protobuf\descriptor.py", line 755, in __new__
    _message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.
 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

해결 방법 1: protobuf 다운그레이드

pip install --upgrade "protobuf<=3.20.1"

위 오류는 해결

 

Traceback (most recent call last):
  File "d:\dev\workspace_py\paddleocr\test1.py", line 7, in <module>
    result = ocr.ocr(img_path, cls=True)
  File "C:\Users\SolutionDev\anaconda3\envs\paddle_env\lib\site-packages\paddleocr\paddleocr.py", line 474, in ocr
    dt_boxes, rec_res = self.__call__(img, cls)
  File "C:\Users\SolutionDev\anaconda3\envs\paddle_env\lib\site-packages\paddleocr\tools\infer\predict_system.py", line 69, in __call__
    dt_boxes, elapse = self.text_detector(img)
  File "C:\Users\SolutionDev\anaconda3\envs\paddle_env\lib\site-packages\paddleocr\tools\infer\predict_det.py", line 215, in __call__
    self.input_tensor.copy_from_cpu(img)
  File "C:\Users\SolutionDev\anaconda3\envs\paddle_env\lib\site-packages\paddle\fluid\inference\wrapper.py", line 35, in tensor_copy_from_cpu
    self.copy_from_cpu_bind(data)
RuntimeError: (PreconditionNotMet) The third-party dynamic library (cudnn64_8.dll) that Paddle depends on is not configured correctly. (error code is 126)
  Suggestions:
  1. Check if the third-party dynamic library (e.g. CUDA, CUDNN) is installed correctly and its version is matched with paddlepaddle you installed.       
  2. Configure third-party dynamic library environment variables as follows:
  - Linux: set LD_LIBRARY_PATH by `export LD_LIBRARY_PATH=...`
  - Windows: set PATH by `set PATH=XXX; (at ..\paddle\fluid\platform\dynload\dynamic_loader.cc:285)

새로운 오류 발생 GPU CUDA 관련 오류인데 
CUDA 10.1 v7이 설치되어 있어서 

아래 사이트에서 CUDA 10.2 v8.4.0 다운받아 설치

developer.nvidia.com/rdp/cudnn-archive

Traceback (most recent call last):
  File "d:\dev\workspace_py\paddleocr\test1.py", line 7, in <module>
    result = ocr.ocr(img_path, cls=True)
  File "C:\Users\SolutionDev\anaconda3\envs\paddle_env\lib\site-packages\paddleocr\paddleocr.py", line 474, in ocr
    dt_boxes, rec_res = self.__call__(img, cls)
  File "C:\Users\SolutionDev\anaconda3\envs\paddle_env\lib\site-packages\paddleocr\tools\infer\predict_system.py", line 69, in __call__
    dt_boxes, elapse = self.text_detector(img)
  File "C:\Users\SolutionDev\anaconda3\envs\paddle_env\lib\site-packages\paddleocr\tools\infer\predict_det.py", line 215, in __call__
    self.input_tensor.copy_from_cpu(img)
  File "C:\Users\SolutionDev\anaconda3\envs\paddle_env\lib\site-packages\paddle\fluid\inference\wrapper.py", line 35, in tensor_copy_from_cpu
    self.copy_from_cpu_bind(data)
RuntimeError: (PreconditionNotMet) The third-party dynamic library (cublas64_112.dll;cublas64_11.dll) that Paddle depends on is not configured correctly. (error code is 126)
  Suggestions:
  1. Check if the third-party dynamic library (e.g. CUDA, CUDNN) is installed correctly and its version is matched with paddlepaddle you installed.
  2. Configure third-party dynamic library environment variables as follows:
  - Linux: set LD_LIBRARY_PATH by `export LD_LIBRARY_PATH=...`
  - Windows: set PATH by `set PATH=XXX; (at ..\paddle\fluid\platform\dynload\dynamic_loader.cc:285)

오류 내용을 보니 CUDA 11을 설치 필요.  CUDA 10  지원한다고 되어 있는데 참 난감함.

[2022/06/13 14:31:39] 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\\SolutionDev/.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\\SolutionDev/.paddleocr/whl\\det\\ml\\Multilingual_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, ir_optim=True, label_list=['0', '180'], lang='korean', layout=True, layout_label_map=None, layout_path_model='lp://PubLayNet/ppyolov2_r50vd_dcn_365e_publaynet/config', max_batch_size=10, max_text_length=25, min_subgraph_size=15, mode='structure', ocr=True, 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='C:\\Users\\SolutionDev\\anaconda3\\envs\\paddle_env\\lib\\site-packages\\paddleocr\\ppocr\\utils\\dict\\korean_dict.txt', rec_image_shape='3, 48, 320', rec_model_dir='C:\\Users\\SolutionDev/.paddleocr/whl\\rec\\korean\\korean_PP-OCRv3_rec_infer', save_crop_res=False, save_log_path='./log_output/', scales=[8, 16, 
32], show_log=True, structure_version='PP-STRUCTURE', table=True, 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=True, use_mp=False, use_onnx=False, use_pdserving=False, use_space_char=True, use_tensorrt=False, vis_font_path='./doc/fonts/simfang.ttf', warmup=False)
Could not locate cublasLt64_10.dll. Please make sure it is in your library path!

CUDA 11설치 후 10버전 파일을 찾아서 10에 있는 파일 복사 해서 넣음

[2022/06/13 14:33:39] 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\\SolutionDev/.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\\SolutionDev/.paddleocr/whl\\det\\ml\\Multilingual_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, ir_optim=True, label_list=['0', '180'], lang='korean', layout=True, layout_label_map=None, layout_path_model='lp://PubLayNet/ppyolov2_r50vd_dcn_365e_publaynet/config', max_batch_size=10, max_text_length=25, min_subgraph_size=15, mode='structure', ocr=True, 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='C:\\Users\\SolutionDev\\anaconda3\\envs\\paddle_env\\lib\\site-packages\\paddleocr\\ppocr\\utils\\dict\\korean_dict.txt', rec_image_shape='3, 48, 320', rec_model_dir='C:\\Users\\SolutionDev/.paddleocr/whl\\rec\\korean\\korean_PP-OCRv3_rec_infer', save_crop_res=False, save_log_path='./log_output/', scales=[8, 16, 
32], show_log=True, structure_version='PP-STRUCTURE', table=True, 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=True, use_mp=False, use_onnx=False, use_pdserving=False, use_space_char=True, use_tensorrt=False, vis_font_path='./doc/fonts/simfang.ttf', warmup=False)
Could not locate zlibwapi.dll. Please make sure it is in your library path!

zlib 없다고 나와서 다운로드 받아서 넣어줌
https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html#install-zlib-windows

 

Installation Guide :: NVIDIA Deep Learning cuDNN Documentation

About this task export QNX_HOST={flash_dir}/toolchains/qnx_toolchain/host/linux/x86_64 export QNX_TARGET={flash_dir}/toolchains/qnx_toolchain/target/qnx7 export HOST_COMPILER=$QNX_HOST/usr/bin/aarch64-unknown-nto-qnx7.1.0-g++ export CUDNN_LIB_PATH=/usr/lib

docs.nvidia.com

 

PS D:\dev\workspace_py\paddleocr>  d:; cd 'd:\dev\workspace_py\paddleocr'; & 'C:\Users\SolutionDev\anaconda3\envs\paddle_env\python.exe' 'c:\Users\SolutionDev\.vscode\extensions\ms-python.python-2022.8.0\pythonFiles\lib\python\debugpy\launcher' '54871' '--' 'd:\dev\workspace_py\paddleocr\test1.py' 
C:\Users\SolutionDev\anaconda3\envs\paddle_env\lib\site-packages\paddle\vision\transforms\functional_pil.py:36: DeprecationWarning: NEAREST is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.NEAREST or Dither.NONE instead.
  'nearest': Image.NEAREST,
C:\Users\SolutionDev\anaconda3\envs\paddle_env\lib\site-packages\paddle\vision\transforms\functional_pil.py:37: DeprecationWarning: BILINEAR is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BILINEAR instead.
  'bilinear': Image.BILINEAR,
C:\Users\SolutionDev\anaconda3\envs\paddle_env\lib\site-packages\paddle\vision\transforms\functional_pil.py:38: DeprecationWarning: BICUBIC is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BICUBIC instead.
  'bicubic': Image.BICUBIC,
C:\Users\SolutionDev\anaconda3\envs\paddle_env\lib\site-packages\paddle\vision\transforms\functional_pil.py:39: DeprecationWarning: BOX is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BOX instead.
  'box': Image.BOX,
C:\Users\SolutionDev\anaconda3\envs\paddle_env\lib\site-packages\paddle\vision\transforms\functional_pil.py:40: DeprecationWarning: LANCZOS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead.
  'lanczos': Image.LANCZOS,
C:\Users\SolutionDev\anaconda3\envs\paddle_env\lib\site-packages\paddle\vision\transforms\functional_pil.py:41: DeprecationWarning: HAMMING is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.HAMMING instead.
  'hamming': Image.HAMMING
[2022/06/13 14:36:56] 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\\SolutionDev/.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\\SolutionDev/.paddleocr/whl\\det\\ml\\Multilingual_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, ir_optim=True, label_list=['0', '180'], lang='korean', layout=True, layout_label_map=None, layout_path_model='lp://PubLayNet/ppyolov2_r50vd_dcn_365e_publaynet/config', max_batch_size=10, max_text_length=25, min_subgraph_size=15, mode='structure', ocr=True, 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='C:\\Users\\SolutionDev\\anaconda3\\envs\\paddle_env\\lib\\site-packages\\paddleocr\\ppocr\\utils\\dict\\korean_dict.txt', rec_image_shape='3, 48, 320', rec_model_dir='C:\\Users\\SolutionDev/.paddleocr/whl\\rec\\korean\\korean_PP-OCRv3_rec_infer', save_crop_res=False, save_log_path='./log_output/', scales=[8, 16, 
32], show_log=True, structure_version='PP-STRUCTURE', table=True, 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=True, use_mp=False, use_onnx=False, use_pdserving=False, use_space_char=True, use_tensorrt=False, vis_font_path='./doc/fonts/simfang.ttf', warmup=False)
[2022/06/13 14:36:59] ppocr DEBUG: dt_boxes num : 6, elapse : 1.5444152355194092
[2022/06/13 14:36:59] ppocr DEBUG: cls num  : 6, elapse : 0.019956588745117188
[2022/06/13 14:36:59] ppocr DEBUG: rec_res num  : 6, elapse : 0.02193593978881836
[[[145.0, 84.0], [283.0, 99.0], [275.0, 177.0], [136.0, 161.0]], ('서울', 0.999789834022522)]
[[[378.0, 103.0], [523.0, 115.0], [517.0, 196.0], [372.0, 185.0]], ('%윤', 0.5694964528083801)]
[[[168.0, 182.0], [251.0, 189.0], [248.0, 227.0], [165.0, 220.0]], ('Seou', 0.9961248636245728)]
[[[357.0, 197.0], [528.0, 216.0], [523.0, 259.0], [353.0, 239.0]], ('Pyeongyang', 0.9998717308044434)]
[[[196.0, 281.0], [284.0, 287.0], [281.0, 329.0], [193.0, 322.0]], ('56Km', 0.8872096538543701)]
[[[353.0, 292.0], [455.0, 301.0], [452.0, 340.0], [350.0, 331.0]], ('205Km', 0.9700227975845337)]
PS D:\dev\workspace_py\paddleocr>

샘플코드 실행 성공
GPU사용하는 것 설정하는 부분에서 시간 많이 걸림

 

 

 

vscode와 anaconda 연동

vscode를 켠 후 Ctrl + Shift + P 를 누르고 python interpreter라고 검색하면 다음과 같이 나온다.

 

 

select interpreter를 누르고 아까 생성한 main을 선택해 준다.

 

 

반응형

'OCR > PaddleOCR' 카테고리의 다른 글

4. PaddleOCR - 테스트 1  (0) 2022.06.13
2. PaddleOCR - 패키지설치  (0) 2022.06.13
1. PaddleOCR - 개발환경 구성  (0) 2022.06.13