[PaddlePaddle/PaddleOCR]PaddleOCR 自行修改了检测到的字

2024-05-14 111 views
6

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

  • 系统环境/System Environment:Windows10
  • 版本号/Version:Paddle: PaddleOCR: 问题相关组件/Related components:PaddleOCR
  • 运行指令/Command Code:
  • 完整报错/Complete Error Message:

遇到一些很奇葩的问题,模型本身所检测到的字和实体字有出入: 譬如: O/H 变成了 H/O; 一些字眼如6/9 变成了0/0;更奇葩的是可以2排字肉眼看是一样的(比如3/9);只有一排是对的,另外一排可能是(0/0).

这些都是发生在很清楚的图文里。请问OCR的本身是不是有Autocorrect还是自己预测接下来的字并自行篡改输出的??

回答

9

请问OCR的本身是不是有Autocorrect还是自己预测接下来的字并自行篡改输出的

没有,不会。

5

Code: PaddleOCR(use_gpu=False,lang='en',use_angle_cls=True, enable_mkldnn=True, drop_score = 0.3, use_space_char = True, enable_dilation = True, show_log = False)

就真的不懂是什么环节出错了>< 随机出错的概率不小。。。

6

enable_mkldnn=False 试试看

2

为什么呢? 可是没有enable_mkldnn 真的够慢 - 我是用着PaddleOCRv3 的 ><

5

有用吗,你的电脑是AMD还是Intel的

1

好的。。。我明早才测试; 电脑是Intel的 - 有什么区别?

我也观察到:局部图像OCR 和 一整张图像OCR - 同个位子,输出也可能不同 - 为啥这是?懵了><

9

我也观察到:局部图像OCR 和 一整张图像OCR - 同个位子,输出也可能不同 - 为啥这是?懵了><

这个是有可能的

0

一整张图像OCR 有时又比 局部图像OCR 准。。。。 除了关MKLDNN, 还有其他办法吗?

1

使用GPU

9

一整张图像OCR 有时又比 局部图像OCR 准。。。。

两阶段OCR的整个流程是先检测位置再识别字符。这个是有可能的。

1

好的。。。我明早才测试; 电脑是Intel的 - 有什么区别?

我也观察到:局部图像OCR 和 一整张图像OCR - 同个位子,输出也可能不同 - 为啥这是?懵了><

测了,并没有区别><

0

测了,并没有区别><

用的 paddle 版本是什么,使用的官方的推理代码吗

5

如果可以麻烦提供一下测试用的图

1

Paddle 版本:

image

PaddleOCR(use_gpu=False,lang='en',use_angle_cls=True, enable_mkldnn=True, drop_score = 0.3, use_space_char = True, enable_dilation = True, show_log = False)

Paddle 模型所用参数(看看我是放少了什么,还是没用到最新的模型版本): [2023/07/13 11:04:58] 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\\E/.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\\E/.paddleocr/whl\\det\\en\\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.3, 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_dilation=True, enable_mkldnn=True, 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=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='c:\\Users\\E\\anaconda3\\envs\\pyocr\\lib\\site-packages\\paddleocr\\ppocr\\utils\\en_dict.txt', rec_image_inverse=True, rec_image_shape='3, 48, 320', rec_model_dir='C:\\Users\\E/.paddleocr/whl\\rec\\en\\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=False, 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)

以下是我的图像(.pkl file - 我zip了) - 为了更好测(我搞了一些image preprocessing, 为啥么这么做,paddleocr认空格不够理想,想拿table first column 有时又会与其他的column字连一起) sub_img.zip Unzip 后:

image

这会是cv 的 np.array。。。谢啦

我的输出, 用着以上的参数:

image

4

这里是我用官方代码跑出的结果

  • ch
[2023/07/13 13:00:30] ppocr DEBUG: dt_boxes num : 12, elapse : 0.05553102493286133
[2023/07/13 13:00:31] ppocr DEBUG: rec_res num  : 12, elapse : 0.5531811714172363
[2023/07/13 13:00:31] ppocr INFO: [[[17.0, 3.0], [96.0, 3.0], [96.0, 20.0], [17.0, 20.0]], ('TARIKHMASUK', 0.862173855304718)]
[2023/07/13 13:00:31] ppocr INFO: [[[24.0, 23.0], [87.0, 23.0], [87.0, 41.0], [24.0, 41.0]], ('进支日期', 0.771024763584137)]
[2023/07/13 13:00:31] ppocr INFO: [[[19.0, 44.0], [89.0, 44.0], [89.0, 61.0], [19.0, 61.0]], ('ENTRYDATE', 0.9352404475212097)]
[2023/07/13 13:00:31] ppocr INFO: [[[46.0, 87.0], [92.0, 87.0], [92.0, 110.0], [46.0, 110.0]], ('09/03', 0.9296207427978516)]
[2023/07/13 13:00:31] ppocr INFO: [[[46.0, 184.0], [91.0, 184.0], [91.0, 207.0], [46.0, 207.0]], ('09/03', 0.9292374849319458)]
[2023/07/13 13:00:31] ppocr INFO: [[[46.0, 279.0], [91.0, 279.0], [91.0, 302.0], [46.0, 302.0]], ('09/03', 0.9264490008354187)]
[2023/07/13 13:00:31] ppocr INFO: [[[46.0, 375.0], [91.0, 375.0], [91.0, 398.0], [46.0, 398.0]], ('09/03', 0.9305203557014465)]
[2023/07/13 13:00:31] ppocr INFO: [[[46.0, 448.0], [92.0, 448.0], [92.0, 471.0], [46.0, 471.0]], ('09/03', 0.948712170124054)]
[2023/07/13 13:00:31] ppocr INFO: [[[45.0, 542.0], [94.0, 542.0], [94.0, 568.0], [45.0, 568.0]], ('09/03', 0.9283186793327332)]
[2023/07/13 13:00:31] ppocr INFO: [[[46.0, 640.0], [92.0, 640.0], [92.0, 663.0], [46.0, 663.0]], ('10/03', 0.9872738718986511)]
[2023/07/13 13:00:31] ppocr INFO: [[[47.0, 736.0], [92.0, 736.0], [92.0, 759.0], [47.0, 759.0]], ('10/03', 0.9269412755966187)]
[2023/07/13 13:00:31] ppocr INFO: [[[46.0, 832.0], [92.0, 832.0], [92.0, 855.0], [46.0, 855.0]], ('10/03', 0.9840824007987976)]
  • en
[2023/07/13 13:01:33] ppocr DEBUG: dt_boxes num : 12, elapse : 0.044239044189453125
[2023/07/13 13:01:33] ppocr DEBUG: rec_res num  : 12, elapse : 0.537524938583374
[2023/07/13 13:01:33] ppocr INFO: [[[16.0, 3.0], [96.0, 3.0], [96.0, 20.0], [16.0, 20.0]], ('TARIKH MASUK', 0.9665706753730774)]
[2023/07/13 13:01:33] ppocr INFO: [[[20.0, 43.0], [91.0, 43.0], [91.0, 60.0], [20.0, 60.0]], ('ENTRYDATE', 0.9926372170448303)]
[2023/07/13 13:01:33] ppocr INFO: [[[46.0, 87.0], [92.0, 87.0], [92.0, 110.0], [46.0, 110.0]], ('09/03', 0.9989567995071411)]
[2023/07/13 13:01:33] ppocr INFO: [[[46.0, 184.0], [92.0, 184.0], [92.0, 207.0], [46.0, 207.0]], ('09/03', 0.9989815950393677)]
[2023/07/13 13:01:33] ppocr INFO: [[[46.0, 279.0], [92.0, 279.0], [92.0, 302.0], [46.0, 302.0]], ('09/03', 0.9989106059074402)]
[2023/07/13 13:01:33] ppocr INFO: [[[45.0, 375.0], [92.0, 375.0], [92.0, 398.0], [45.0, 398.0]], ('09/03', 0.9972482919692993)]
[2023/07/13 13:01:33] ppocr INFO: [[[45.0, 448.0], [92.0, 448.0], [92.0, 471.0], [45.0, 471.0]], ('09/03', 0.9969029426574707)]
[2023/07/13 13:01:33] ppocr INFO: [[[45.0, 544.0], [92.0, 544.0], [92.0, 567.0], [45.0, 567.0]], ('09/03', 0.9973653554916382)]
[2023/07/13 13:01:33] ppocr INFO: [[[46.0, 640.0], [92.0, 640.0], [92.0, 663.0], [46.0, 663.0]], ('10/03', 0.9994903802871704)]
[2023/07/13 13:01:33] ppocr INFO: [[[46.0, 736.0], [92.0, 736.0], [92.0, 759.0], [46.0, 759.0]], ('10/03', 0.9993782043457031)]
[2023/07/13 13:01:33] ppocr INFO: [[[45.0, 832.0], [92.0, 832.0], [92.0, 855.0], [45.0, 855.0]], ('10/03', 0.9990254640579224)]
9

请问您有full code吗? 我看看。

2

你的问题可以复现

import joblib
from paddleocr import PaddleOCR

img = joblib.load('sub_img.pkl')

ocr = PaddleOCR(lang='en')
# 这里使用文本方向分类器会导致识别效果下降
# ocr = PaddleOCR(use_angle_cls=True, lang="en")
result = ocr.ocr(img)
print(result)

use_angle_cls=False 可能对你的问题有缓解

8

这是为啥。。。。>< 郁闷

7

无论如何-感谢您的启示!

9

@similang 因为错误的分类结果会使得文本方向变化,不是正向的文本方向会使得文本检测识别效果明显变差。

4

所以终结是-默认的参数是最好的? 可以问问- 有时还有一些标点符号被略过,有办法修正这吗?

4

针对自己的场景fine-tune一下。

6

针对自己的场景fine-tune一下。

这是指re-training吗? 还是参数的改变?

2

重新加入错分的数据,进行微调训练。

3

以上回答已经充分解答了问题,如果有新的问题欢迎随时提交issue,或者在此条issue下继续回复~ 我们开启了飞桨套件的ISSUE攻关活动,欢迎感兴趣的开发者参加:https://github.com/PaddlePaddle/PaddleOCR/issues/10223