已启用use_angle_cls的PaddleOCR无法识别旋转文本问题咨询
问题描述
在Sagemaker中部署预训练PaddleOCR模型(检测+识别+方向分类),正常图像可成功识别文本并返回置信度与边界框,但传入旋转90度的同一张图像时推理结果为空,推测方向分类(CLS)功能未生效。已显式设置use_angle_cls=True,但问题依旧,询问是否需要额外配置参数。
模型初始化代码
ocr = PaddleOCR(det_model_dir='/opt/program/inference/en_PP-OCRv3_det_infer', rec_model_dir='/opt/program/inference/en_PP-OCRv3_rec_infer', cls_model_dir='/opt/program/inference/ch_ppocr_mobile_v2.0_cls_infer', lang='en', use_angle_cls=True, label_list=['0', '90', '180'], use_pdserving=False)
推理代码
result = ocr.ocr(imgpath)
正常图像推理结果
[ [ [ [ [137.0, 463.0], [252.0, 463.0], [252.0, 495.0], [137.0, 495.0] ], ('Hello', 0.9691440463066101) ], [ [ [162.0, 524.0], [234.0, 524.0], [234.0, 534.0], [162.0, 534.0] ], ('Text', 0.9424589276313782) ], [ [ [185.0, 537.0], [204.0, 537.0], [204.0, 545.0], [185.0, 545.0] ], ('World', 0.994895339012146) ] ] ]
模型初始化调试输出
Namespace(alpha=1.0, benchmark=False, beta=1.0, cls_batch_num=6, cls_image_shape='3, 48, 192', cls_model_dir='/opt/program/inference/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='/opt/program/inference/en_PP-OCRv3_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_mem=500, help='==SUPPRESS==', image_dir=None, image_orientation=False, ir_optim=True, kie_algorithm='LayoutXLM', label_list=['0', '90'], lang='en', 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', 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='/opt/program/ppocr/utils/en_dict.txt', rec_image_inverse=True, rec_image_shape='3, 48, 320', rec_model_dir='/opt/program/inference/en_PP-OCRv3_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)
解决方案
从调试输出可定位几个关键问题,调整以下参数即可解决:
修正
label_list参数
调试输出显示label_list=['0', '90'],与初始化时设置的['0', '90', '180']不符,说明参数未生效。ch_ppocr_mobile_v2.0_cls_infer模型仅支持0/90度方向分类,无需添加180,将初始化代码中的label_list改为['0', '90']。启用全局方向检测
当前image_orientation=False,该参数控制是否对整张图像做方向矫正。旋转90度的图像需先全局矫正,才能让检测模型识别文本区域,因此添加image_orientation=True到初始化参数。降低方向分类阈值
当前cls_thresh=0.9,若模型对旋转图像的方向预测置信度低于该值会跳过矫正。可将阈值调低至0.5,确保低置信度的预测也能生效,添加cls_thresh=0.5到初始化参数。
调整后的初始化代码:
ocr = PaddleOCR(det_model_dir='/opt/program/inference/en_PP-OCRv3_det_infer', rec_model_dir='/opt/program/inference/en_PP-OCRv3_rec_infer', cls_model_dir='/opt/program/inference/ch_ppocr_mobile_v2.0_cls_infer', lang='en', use_angle_cls=True, label_list=['0', '90'], image_orientation=True, cls_thresh=0.5, use_pdserving=False)
- 可选:提升检测敏感度
若上述调整后仍无结果,可临时降低det_db_thresh到0.2、det_db_box_thresh到0.4,提升检测模型对旋转文本的识别能力,测试后再调回合适值。
内容的提问来源于stack exchange,提问作者219CID
相关产品推荐
相关产品推荐

