[PaddlePaddle/PaddleOCR]PPstructure 表格识别错误

2024-05-13 689 views
6

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

系统环境/System Environment:

Windows 10 家庭中文版 22H2: 1060MaxQ + CUDA 11.6

版本号/Version: Python:3.9, anaconda Paddle:paddlepaddle-gpu==2.5.1.post116 PaddleOCR: 2.7 问题相关组件/Related components:PPStructure 版面回复

运行指令/Command Code: python predict_system.py --image_dir=3.pdf --det_model_dir=inference/ch_PP-OCRv4_det_infer --rec_model_dir=inference/ch_PP-OCRv4_rec_infer --rec_char_dict_path=../ppocr/utils/ppocr_keys_v1.txt --table_model_dir=inference/ch_ppstructure_mobile_v2.0_SLANet_infer --table_char_dict_path=../ppocr/utils/dict/table_structure_dict_ch.txt --layout_model_dir=inference/picodet_lcnet_x1_0_fgd_layout_cdla_infer --layout_dict_path=../ppocr/utils/dict/layout_dict/layout_cdla_dict.txt --vis_font_path=../doc/fonts/simfang.ttf --recovery=True --output=./output/ --use_gpu=False

完整报错/Complete Error Message: PDF文档中的表格如下: image

使用版面恢复,运行到最后出现 ppocr ERROR: error in layout recovery image:1.pdf, err msg: list index out of range image

能输出文件 image 但是在 predict_system.py 292 行,调用 convert_info_docx(img, all_res, save_folder, img_name) 时出现问题

问题定位: 原因在于,识别的表格行列数出现了格式错误 从 predict_system.py 调用 convert_info_docx 跳转到 recovery_to_doc.py 63行 parser.handle_table(region['res']['html'], doc) 调用 recovery/table_process.py 第238行 def handle_table(self, html, doc) 识别到表格的 res: image 产生的 html 如下: image

其中 handle_table 函数中,提取的 cols_len = 4 但是在表格的 html 中错误地出现了 colspan = 5 导致在函数中,出现了 list index out of range 的情况 image

这个 colspan=5 是在表格分析的过程中产生的,我无法解决,需要求助

回答

8

同样的问题,请问解决了吗?

4

上面链接失效了,还有其他方法解决colspan, rowspan文章或办法吗?

0

@nissansz 这个是链接格式没写好,把逗号后面的去掉就行了。或者直接搜 python对图片中的表格拆分

2

这个文章看过。有的时候表格线有断开,各种变形会导致投影法失效,有办法修补表格线吗? 另外,我用paddle训练表格识别模型,测试时,有的图片,colspan, rowspan会漏掉,这种是什么问题?怎么解决?

image

4

@nissansz 如果是扫描文档,表格断开的话可以考虑用 opencv 做图像增强,做一些图形学的膨胀之类的加粗表格线。然后如果是拍照的图片变形了可能就要考虑手动用PS之类的修补了。 然后 colspan rowspan 这个可能是面对复杂表格,模型不够准确的问题,如果要解决的话可能只能微调模型了,加自己的数据来训练,我也还没有找到很好的方法

9

膨胀之类的加粗表格线,怎麽判断已经找到全部表格线?

5

这个应该没有什么好办法了,要靠opencv+调参,不同文档可能还不一样。比如用霍夫变换什么的识别表格线,里面挺多参数要手动试的

3

应该是最后一行合并的时候报错了,在269行添加一个判断就好了 while docx_cell.text != '': # Skip the merged cell cell_col += 1 docx_cell = table.cell(cell_row, cell_col)

if cell_row + rowspan - 1 == len(rows): rowspan -= 1

cell_to_merge = table.cell(cell_row + rowspan - 1, cell_col + colspan - 1)

8

应该是最后一行合并的时候报错了,在269行添加一个判断就好了 while docx_cell.text != '': # Skip the merged cell cell_col += 1 docx_cell = table.cell(cell_row, cell_col)

if cell_row + rowspan - 1 == len(rows): rowspan -= 1

cell_to_merge = table.cell(cell_row + rowspan - 1, cell_col + colspan - 1)

这是哪个py文件?

2

应该是最后一行合并的时候报错了,在269行添加一个判断就好了 while docx_cell.text != '': # Skip the merged cell cell_col += 1 docx_cell = table.cell(cell_row, cell_col) if cell_row + rowspan - 1 == len(rows): rowspan -= 1 cell_to_merge = table.cell(cell_row + rowspan - 1, cell_col + colspan - 1)

这是哪个py文件?

微信截图_20231109193911 table_process.py 这不是表格没识别出来,应该是在做还原到word文档的时候报错了,网上有其他的还原方法,可以去找下

0

我找到报错的问题是在表格提取成html时
colspan = int(col.attrs.get('colspan', 1)) rowspan = int(col.attrs.get('rowspan', 1)) 这两个数值跟正确的表格是不相符的,导致list out, 现在的解决办法是报错的时候rowspan = int(col.attrs.get('rowspan', 1)) - 1 或colspan = int(col.attrs.get('colspan', 1)) - 1,目前只遇到跨度多了1的情况

7

我训练表格模型,有时正常span,有时消失。而且效果总没有官方好。 更奇怪的是,最简单的表格,也很难准确

1

我训练表格模型,有时正常span,有时消失。而且效果总没有官方好。 更奇怪的是,最简单的表格,也很难准确

正常的表格识别没什么问题,有个问题是pdf转图片的时候 mat = fitz.Matrix(2, 2)用的是2,会导致图片模糊,你可以把图片打印出来看下,如果很模糊要改变缩放系数, if pm.width > 2000 or pm.height > 2000:也不能做这个缩小

8

有训练好的模型分享吗?

0

有训练好的模型分享吗?

没有,我也没训练过

0

crnn训练,英文识别率差,且英文单词间的空格缺失,这个有办法吗?

8

有没有好的参数设置呢?