PaddlePaddle / PaddleOCR

Awesome multilingual OCR toolkits based on PaddlePaddle (practical ultra lightweight OCR system, support 80+ languages recognition, provide data annotation and synthesis tools, support training and deployment among server, mobile, embedded and IoT devices)
https://paddlepaddle.github.io/PaddleOCR/
Apache License 2.0
44.29k stars 7.83k forks source link

更换中文繁体识别模型后报错IndexError: list index out of range #13590

Closed bbg221 closed 3 months ago

bbg221 commented 3 months ago

Search before asking

Bug

from paddleocr import PaddleOCR, draw_ocr

ocr = PaddleOCR(use_angle_cls=True, lang="ch", use_gpu=False, det_model_dir=r'D:\myown\baidupaddle\modela', rec_model_dir=r'D:\myown\baidupaddle\modelb', cls_model_dir=r'D:\myown\baidupaddle\modelc' ) impath = './b.jpg' r = ocr.ocr(impath, cls=True) print (r)

我从https://github.com/PaddlePaddle/PaddleOCR/blob/main/doc/doc_ch/models_list.md下载了中文繁体识别模型,然后解压后替换到了rec_model_dir里边,重新运行就报错: (paddleocr_py39) PS D:\myown\baidupaddle> python .\paddleocr_test.py [2024/08/05 08:38:52] ppocr DEBUG: Namespace(help='==SUPPRESS==', use_gpu=False, 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:\myown\baidupaddle\modela', 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:\myown\baidupaddle\modelb', rec_image_inverse=True, rec_image_shape='3, 48, 320', rec_batch_num=6, max_text_length=25, rec_char_dict_path='D:\myown\baidupaddle\paddleocr_py39\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:\myown\baidupaddle\modelc', 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, 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, ocr=True, recovery=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') [2024/08/05 08:38:53] ppocr DEBUG: dt_boxes num : 12, elapsed : 0.19106101989746094 [2024/08/05 08:38:53] ppocr DEBUG: cls num : 12, elapsed : 0.061598777770996094 Traceback (most recent call last): File "D:\myown\baidupaddle\paddleocr_test.py", line 29, in r = ocr.ocr(impath, cls=True) File "D:\myown\baidupaddle\paddleocr_py39\lib\site-packages\paddleocr\paddleocr.py", line 729, in ocr dt_boxes, recres, = self.call(img, cls, slice) File "D:\myown\baidupaddle\paddleocr_py39\lib\site-packages\paddleocr\tools\infer\predict_system.py", line 144, in call rec_res, elapse = self.text_recognizer(img_crop_list) File "D:\myown\baidupaddle\paddleocr_py39\lib\site-packages\paddleocr\tools\infer\predict_rec.py", line 689, in call rec_result = self.postprocess_op( File "D:\myown\baidupaddle\paddleocr_py39\lib\site-packages\paddleocr\ppocr\postprocess\rec_postprocess.py", line 206, in call text = self.decode( File "D:\myown\baidupaddle\paddleocr_py39\lib\site-packages\paddleocr\ppocr\postprocess\rec_postprocess.py", line 154, in decode char_list = [ File "D:\myown\baidupaddle\paddleocr_py39\lib\site-packages\paddleocr\ppocr\postprocess\rec_postprocess.py", line 155, in self.character[text_id] for text_id in text_index[batch_idx][selection] IndexError: list index out of range (paddleocr_py39) PS D:\myown\baidupaddle> b

Environment

windows11 python39 AMD64

(paddleocr_py39) PS D:\myown\baidupaddle> pip list Package Version


anyio 4.4.0 astor 0.8.1 beautifulsoup4 4.12.3 certifi 2024.7.4 charset-normalizer 3.3.2 colorama 0.4.6 contourpy 1.2.1 cycler 0.12.1 Cython 3.0.10 decorator 5.1.1 exceptiongroup 1.2.2 fire 0.6.0 fonttools 4.53.1 h11 0.14.0 httpcore 1.0.5 httpx 0.27.0 idna 3.7 imageio 2.34.2 imgaug 0.4.0 importlib_resources 6.4.0 kiwisolver 1.4.5 lazy_loader 0.4 lmdb 1.5.1 lxml 5.2.2 matplotlib 3.9.1 networkx 3.2.1 numpy 1.26.4 opencv-contrib-python 4.10.0.84 opencv-python 4.10.0.84 opt-einsum 3.3.0 packaging 24.1 paddleocr 2.8.1 paddlepaddle 2.6.1 pillow 10.4.0 pip 22.0.4 protobuf 3.20.2 pyclipper 1.3.0.post5 pyparsing 3.1.2 python-dateutil 2.9.0.post0 python-docx 1.1.2 PyYAML 6.0.1 rapidfuzz 3.9.5 requests 2.32.3 scikit-image 0.24.0 scipy 1.13.1 setuptools 58.1.0 shapely 2.0.5 six 1.16.0 sniffio 1.3.1 soupsieve 2.5 termcolor 2.4.0 tifffile 2024.7.24 tqdm 4.66.4 typing_extensions 4.12.2 urllib3 2.2.2 zipp 3.19.2

Minimal Reproducible Example

from paddleocr import PaddleOCR, draw_ocr

ocr = PaddleOCR(use_angle_cls=True, lang="ch", use_gpu=False, det_model_dir=r'D:\myown\baidupaddle\modela', rec_model_dir=r'D:\myown\baidupaddle\modelb', cls_model_dir=r'D:\myown\baidupaddle\modelc' ) impath = './b.jpg' r = ocr.ocr(impath, cls=True) print (r)

Additional

No response

Are you willing to submit a PR?

SWHL commented 3 months ago

image

看你勾选了愿意提交PR来修复这个问题,期待你的PR哈

Gmgge commented 3 months ago

我看到你的日志中rec_char_dict_path='D:\myown\baidupaddle\paddleocr_py39\lib\site-packages\paddleocr\ppocr\utils\ppocr_keys_v1.txt',请确认是否切换繁体识别的字典?

根据官方文档描述,更换繁体识别模型对应字典为:ppocr/utils/dict/chinese_cht_dict.txt | 中文繁体识别

bbg221 commented 3 months ago

我看到你的日志中rec_char_dict_path='D:\myown\baidupaddle\paddleocr_py39\lib\site-packages\paddleocr\ppocr\utils\ppocr_keys_v1.txt',请确认是否切换繁体识别的字典?

根据官方文档描述,更换繁体识别模型对应字典为:ppocr/utils/dict/chinese_cht_dict.txt | 中文繁体识别 非常感谢,切换字典后正常了。

from paddleocr import PaddleOCR, draw_ocr

ocr = PaddleOCR(use_angle_cls=True, lang="ch", use_gpu=False, det_model_dir=r'D:\myown\baidupaddle\modela', rec_model_dir=r'D:\myown\baidupaddle\modelb', cls_model_dir=r'D:\myown\baidupaddle\modelc', rec_char_dict_path=r'D:\myown\baidupaddle\paddleocr_py39\Lib\site-packages\paddleocr\ppocr\utils\dict\chinese_cht_dict.txt' ) impath = './b.jpg' r = ocr.ocr(impath, cls=True) print (r)

bbg221 commented 3 months ago

[[[[[45.0, 13.0], [78.0, 13.0], [77.0, 566.0], [44.0, 566.0]], ('東風起日落汀洲一望時愁情不斷如春水人日', 0.9933711886405945)], [[[90.0, 14.0], [120.0, 14.0], [121.0, 566.0], [91.0, 566.0]], ('汀洲人未歸其二一日杏省煙波隔千黑白蘋香散', 0.8930906057357788)], [[[138.0, 12.0], [168.0, 12.0], [166.0, 566.0], [136.0, 566.0]], ('孤村芳草遠斜日杏花飛江南春畫離陽斷 頻濤', 0.9436619281768799)], [[[176.0, 10.0], [213.0, 10.0], [215.0, 568.0], [178.0, 568.0]], ('傷為主當為江南表二施其一日波泓泓郴欣依', 0.8255800604820251)], [[[266.0, 10.0], [302.0, 10.0], [306.0, 541.0], [270.0, 542.0]], ('無人渡孤舟畫日橫到海尺十黑過山應萬重', 0.9826182126998901)], [[[317.0, 13.0], [346.0, 13.0], [346.0, 542.0], [317.0, 542.0]], ('方前代羅江東趙渭南也錄公警策之篇岩遠', 0.9869053959846497)], [[[362.0, 14.0], [391.0, 14.0], [391.0, 568.0], [362.0, 568.0]], ('公之墓序初知巴東日詩家者流目海冠巴東以', 0.9445298910140991)], [[[406.0, 12.0], [436.0, 12.0], [437.0, 570.0], [407.0, 570.0]], ('不欽噗故樞相文康即公之婿實有道之士焉志', 0.9343686103820801)], [[[264.0, 541.0], [307.0, 541.0], [307.0, 563.0], [264.0, 563.0]], ('詩此', 0.9987170696258545)], [[[322.0, 538.0], [344.0, 545.0], [339.0, 564.0], [316.0, 557.0]], ('K', 0.5856369733810425)]]]