PaddleOCR
PaddleOCR copied to clipboard
Error in loading PDF file
请提供下述完整信息以便快速定位问题/Please provide the following information to quickly locate the problem
- 系统环境/System Environment:Ubuntu 18.04 LTS
- 版本号/Version:Paddle: 2.3.1.post116 PaddleOCR: 2.6.0.1 问题相关组件/Related components:
- 运行指令/Command Code:
import os
import cv2
from paddleocr import PPStructure,save_structure_res
from paddleocr.ppstructure.recovery.recovery_to_doc import sorted_layout_boxes, convert_info_docx
# English image
table_engine = PPStructure(recovery=True, lang='en')
save_folder = './output'
img_path = 'ppstructure/docs/table/Introduction.pdf'
result = table_engine(img_path)
save_structure_res(result, save_folder, os.path.basename(img_path).split('.')[0])
- 完整报错/Complete Error Message:
ppocr DEBUG: Namespace(alpha=1.0, benchmark=False, beta=1.0, cls_batch_num=6, cls_image_shape='3, 48, 192', cls_model_dir=None, 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='/home/matthieu/.paddleocr/whl/det/en/en_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='en', layout=True, layout_dict_path='/home/matthieu/anaconda3/envs/paddlepaddle-gpu-fresh/lib/python3.8/site-packages/paddleocr/ppocr/utils/dict/layout_dict/layout_publaynet_dict.txt', layout_model_dir='/home/matthieu/.paddleocr/whl/layout/picodet_lcnet_x1_0_fgd_layout_infer', 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='/home/matthieu/anaconda3/envs/paddlepaddle-gpu-fresh/lib/python3.8/site-packages/paddleocr/ppocr/utils/en_dict.txt', rec_image_shape='3, 48, 320', rec_model_dir='/home/matthieu/.paddleocr/whl/rec/en/en_PP-OCRv3_rec_infer', recovery=True, 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='/home/matthieu/anaconda3/envs/paddlepaddle-gpu-fresh/lib/python3.8/site-packages/paddleocr/ppocr/utils/dict/table_structure_dict.txt', table_max_len=488, table_model_dir='/home/matthieu/.paddleocr/whl/table/en_ppstructure_mobile_v2.0_SLANet_infer', total_process_num=1, type='ocr', use_angle_cls=False, use_dilation=False, use_gpu=True, 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)
[2022/09/16 16:40:16] ppocr ERROR: error in loading image:/home/matthieu/Code/Python/PP/ppstructure/docs/table/Introduction.pdf
AttributeError Traceback (most recent call last)
Cell In [2], line 13
11 save_folder = './output'
12 img_path = '/home/matthieu/Code/Python/PP/ppstructure/docs/table/Introduction.pdf'
---> 13 result = table_engine(img_path)
14 save_structure_res(result, save_folder, os.path.basename(img_path).split('.')[0])
File ~/anaconda3/envs/paddlepaddle-gpu-fresh/lib/python3.8/site-packages/paddleocr/paddleocr.py:602, in PPStructure.__call__(self, img, return_ocr_result_in_table, img_idx)
600 def __call__(self, img, return_ocr_result_in_table=False, img_idx=0):
601 img = check_img(img)
--> 602 res, _ = super().__call__(
603 img, return_ocr_result_in_table, img_idx=img_idx)
604 return res
File ~/anaconda3/envs/paddlepaddle-gpu-fresh/lib/python3.8/site-packages/paddleocr/ppstructure/predict_system.py:107, in StructureSystem.__call__(self, img, return_ocr_result_in_table, img_idx)
105 time_dict['image_orientation'] = toc - tic
106 if self.mode == 'structure':
--> 107 ori_im = img.copy()
108 if self.layout_predictor is not None:
109 layout_res, elapse = self.layout_predictor(img)
AttributeError: 'NoneType' object has no attribute 'copy'
make sure you use the right pdf file and set the valid pdf path
Hi @andyjpaddle I checked both of them.
then make sure you use the latest code, i try it and it works well. you can debug it
first you should convert pdf to img and then read it.
you can find the exmple code in here:
https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/paddleocr.py