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.38k stars 7.83k forks source link

TypeError: 'NoneType' object is not iterable #11203

Closed 925670849 closed 5 months ago

925670849 commented 1 year ago

请提供下述完整信息以便快速定位问题/Please provide the following information to quickly locate the problem

初始化OCR模型

ocr = PaddleOCR(use_angle_cls=True, lang="ch")

图像路径

img_path = 'D:/download/身高体重.png'

进行OCR识别

result = ocr.ocr(img_path, cls=True)

提取识别结果并保存成文本文件

output_file = 'D:/download/身高体重.txt' # 指定保存文本的文件名 with open(output_file, 'w', encoding='utf-8') as f: for res in result: for line in res: f.write(line[1][0] + '\n')

显示结果

from PIL import Image from paddleocr import draw_ocr

image = Image.open(img_path).convert('RGB') boxes = [line[0] for res in result for line in res] txts = [line[1][0] for res in result for line in res] scores = [line[1][1] for res in result for line in res] im_show = draw_ocr(image, boxes, txts, scores, font_path='./fonts/simfang.ttf') im_show = Image.fromarray(im_show) im_show.save('result2.jpg')

- 完整报错/Complete Error Message:
```bash
D:\ProgramData\miniconda\envs\paddleocr\python.exe D:\PycharmProjects\pythonProject\pictotxt.py 
[2023/11/06 12:08:51] ppocr DEBUG: Namespace(alpha=1.0, alphacolor=(255, 255, 255), benchmark=False, beta=1.0, binarize=False, cls_batch_num=6, cls_image_shape='3, 48, 192', cls_model_dir='C:\\Users\\liumin/.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_box_type='quad', 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_limit_side_len=960, det_limit_type='max', det_model_dir='C:\\Users\\liumin/.paddleocr/whl\\det\\ch\\ch_PP-OCRv4_det_infer', det_pse_box_thresh=0.85, det_pse_min_area=16, det_pse_scale=1, det_pse_thresh=0, det_sast_nms_thresh=0.2, 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_id=0, gpu_mem=500, help='==SUPPRESS==', image_dir=None, image_orientation=False, invert=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-OCRv4', output='./output', page_num=0, precision='fp32', process_id=0, re_model_dir=None, rec=True, rec_algorithm='SVTR_LCNet', rec_batch_num=6, rec_char_dict_path='D:\\ProgramData\\miniconda\\envs\\paddleocr\\lib\\site-packages\\paddleocr-2.7.0.1-py3.8.egg\\paddleocr\\ppocr\\utils\\ppocr_keys_v1.txt', rec_image_inverse=True, rec_image_shape='3, 48, 320', rec_model_dir='C:\\Users\\liumin/.paddleocr/whl\\rec\\ch\\ch_PP-OCRv4_rec_infer', recovery=False, save_crop_res=False, save_log_path='./log_output/', scales=[8, 16, 32], ser_dict_path='../train_data/XFUND/class_list_xfun.txt', ser_model_dir=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=True, use_mp=False, use_npu=False, use_onnx=False, use_pdf2docx_api=False, use_pdserving=False, use_space_char=True, use_tensorrt=False, use_visual_backbone=True, use_xpu=False, vis_font_path='./doc/fonts/simfang.ttf', warmup=False)
[2023/11/06 12:09:15] ppocr DEBUG: dt_boxes num : 0, elapsed : 4.999279260635376
[2023/11/06 12:09:16] ppocr DEBUG: cls num  : 0, elapsed : 0
[2023/11/06 12:09:16] ppocr DEBUG: rec_res num  : 0, elapsed : 0.0
Traceback (most recent call last):
  File "D:\PycharmProjects\pythonProject\pictotxt.py", line 18, in <module>
    for line in res:
TypeError: 'NoneType' object is not iterable

Process finished with exit code 1
likenamehaojie commented 1 year ago

我跟你的情况是一样的飞桨团队是不解决这个问题么?我的也是windows系统,不知道是不是版本不对

zhuimengren-a11u commented 12 months ago

你是什么版本的

Huirouuu commented 10 months ago

报错行应该是for res in result,原因是没有文字被检测出来所以result = None,而None是不可迭代的,建议加上if statement确保有results避免此问题。

garychan22 commented 8 months ago

看起来这个重要的bug并没有被修复

xxWeiDG commented 8 months ago

目前还是有这个问题,也没有修复

Lakindu1999 commented 7 months ago

Try to change use_gpu status to False.

ocr = PaddleOCR(use_angle_cls=True, use_gpu=False)

SWHL commented 5 months ago

在最新main分支中,已经修复了