PaddleOCR
PaddleOCR copied to clipboard
在做版面恢复的时候,如果使用clda的版面分析推理 模型报错ppocr ERROR: error in layout recovery image:, err msg: list indices must be integers or slices, not str
请提供下述完整信息以便快速定位问题/Please provide the following information to quickly locate the problem
- 系统环境/System Environment:
- 版本号/Version:Paddle: PaddleOCR: 问题相关组件/Related components:
- 运行指令/Command Code:python3 ppstructure/predict_system.py --image_dir=CDLA_DATASET/train/train_0100.jpg --det_model_dir=./infer/ch_PP-OCRv3_det_slim_infer --rec_model_dir=./infer/ch_PP-OCRv3_rec_slim_infer --rec_char_dict_path=./ppocr/utils/ppocr_keys_v1.txt --table_model_dir=./infer/SLANet_ch --table_char_dict_path=ppocr/utils/dict/table_structure_dict_ch.txt --layout_model_dir=/./infer/picodet_lcnet_x1_0_fgd_layout_cdla_infer --layout_dict_path=./ppocr/utils/dict/layout_dict/cdla_dict.txt --vis_font_path=./doc/fonts/simfang.ttf --recovery=True --output=./output_img/
- 完整报错/Complete Error Message: [2024/04/17 12:47:55] ppocr ERROR: error in layout recovery image:/data/CDLA_DATASET/train/train_0100.jpg, err msg: list indices must be integers or slices, not str
在做版面恢复的时候,如果用到了https://paddleocr.bj.bcebos.com/ppstructure/models/layout/picodet_lcnet_x1_0_fgd_layout_cdla_infer.tar 这个推理模型,或者是与训练模型转出来的推理模型,就会遇到这个问题,报错是从recovery_to_doc.py 的72行
parser.handle_table(region['res']['html'], doc)
然后我看了下res的值,如果是table的话,出来的值是个list,并不是dict。如果用https://paddleocr.bj.bcebos.com/ppstructure/models/layout/picodet_lcnet_x1_0_fgd_layout_infer.tar 这个模型则不会出现问题。不知道是我那里操作的有问题
问题好像是在predict_system.py中 StructureSystem 的__call__中if region['label'] == 'table' ,因为不同的版面分析lable不一样,需要改成region['label'] == 'table' or region['label'].lower() == 'table'才能正确的走到表格模型输出带html的res。不知道这个是不是需要提pr. @Sunting78
@Double97828 欢迎提个pr修复这个问题。
问题好像是在predict_system.py中 StructureSystem 的__call__中if region['label'] == 'table' ,因为不同的版面分析lable不一样,需要改成region['label'] == 'table' or region['label'].lower() == 'table'才能正确的走到表格模型输出带html的res。不知道这个是不是需要提pr. @Sunting78
not working ...
looks the bugging is coming from handel_table(self, html, doc)
tmp fix by:
while docx_cell.text != "": # Skip the merged cell
cell_col += 1
if cell_col + colspan -1 < cols_len:
docx_cell = table.cell(cell_row, cell_col)
else:
print(f"[WARNING]: cell_col out of index")
break
print(f"[DEBUG]: --element [{cell_row+rowspan-1}, {cell_col + colspan-1}], cols_len {cols_len}")
if cell_col+colspan-1 < cols_len:
cell_to_merge = table.cell(
cell_row + rowspan - 1, cell_col + colspan - 1
)
if docx_cell != cell_to_merge:
docx_cell.merge(cell_to_merge)