[PaddlePaddle/PaddleOCR]CDLA自训练模型PPStructure报错

2024-05-14 634 views
6

1.paddleocr版本2.6.0 paddleDetection版本2.5.0(mac 和 centos 7 上均复现) 2.下载CDLA中文数据集在ai studio中利用:ppyolov2_r50vd_dcn_365e_coco.yml 训练。 3.训练生成best_model.pdparams 利用脚本: python tools/export_model.py -c configs/ppyolo/ppyolov2_r50vd_dcn_365e_coco.yml --output_dir=./inference_model 导出成model.pdiparams 和 model.pdmodel 静态文件。 4.利用layoutparser(https://paddleocr.bj.bcebos.com/whl/layoutparser-0.0.0-py3-none-any.whl) 能正常输出结构信息。 代码片段,参考: https://aistudio.baidu.com/aistudio/projectdetail/2274897 model = lp.PaddleDetectionLayoutModel(model_path="./checkpoint", threshold=0.5, label_map={1: "Text", 2: "Title", 3: "Figure", 4: "Figure caption", 5: "Table", 6: "Table caption", 7: "Header", 8: "Footer", 9: "Reference", 10: "Equation"}, enforce_cpu=True, enable_mkldnn=False) layout = model.detect(image) show_img = lp.draw_box(image, layout, box_width=5, show_element_type=True)

5.利用PPStructure运行报错误: 代码片段,参考: https://aistudio.baidu.com/aistudio/projectdetail/2274897 table_engine = PPStructure(show_log=True, lang='ch', table=False, layout_model_dir="./checkpoint") files = os.listdir(img_dir) for fi in files: fi_d = os.path.join(img_dir, fi) for img in os.listdir(fi_d): img_path = os.path.join(fi_d, img) img = cv2.imread(img_path) logger.info("table_engine calling .....") result = table_engine(img) save_structure_res(result, os.path.join(save_folder, fi), os.path.basename(img_path).split('.')[0])

异常信息: File "/Users/zengtao/projects/asdc/ocr-helper/venv/lib/python3.9/site-packages/paddleocr/paddleocr.py", line 605, in call res, _ = super().call( File "/Users/zengtao/projects/asdc/ocr-helper/venv/lib/python3.9/site-packages/paddleocr/ppstructure/predict_system.py", line 109, in call layout_res, elapse = self.layout_predictor(img) File "/Users/zengtao/projects/asdc/ocr-helper/venv/lib/python3.9/site-packages/paddleocr/ppstructure/layout/predict_layout.py", line 86, in call self.predictor.run() ValueError: (InvalidArgument) The conv2d Op's Input Variable Input contains uninitialized Tensor. [Hint: Expected t->IsInitialized() == true, but received t->IsInitialized():0 != true:1.] (at /home/Paddle/paddle/fluid/framework/operator.cc:2411) [operator < conv2d > error]

帮忙分析一下原因,谢谢。:)

备注: 动态模型在ai studio 上,利用: python tools/infer.py -c configs/ppyolo/ppyolov2_r50vd_dcn_365e_coco.yml --infer_img=./output/images_00001.png --output_dir=infer_output/ -o weights=./output/ppyolov2_r50vd_dcn_365e_coco/best_model 是能够输出正常结果的。

回答

2

之前有帖子说:追加参数 (如无需导出NMS,请指定:-o export.nms=False)解决。 但实验后,还是同样错误。

5

ppyolov2是第一版本使用的模型,集成在layoutparser里,第二版版面分析用的picodet模型,2个后处理不同,所以使用ppyolov2训练的模型,在ppocr中使用会报错,如果想使用ppyolov2导出后的模型,可以参考PaddleDetection套件中的预测命令

0

例子是利用英文图像数据集:PubLayNet 如果我是使用中文CLDA数据集的话,配置上需要做什么变动么?

7

ppyolov2是第一版本使用的模型,集成在layoutparser里,第二版版面分析用的picodet模型,2个后处理不同,所以使用ppyolov2训练的模型,在ppocr中使用会报错,如果想使用ppyolov2导出后的模型,可以参考PaddleDetection套件中的预测命令

为什么这种预测脚本可以支持?是做了兼容么?

2

@zengtao1978 Dear friend in config/runtime.yml file set:

post_process: False

8

post_process

thank you for your suggestion

3

已经利用picodet_lcnet_x1_0_layout.yml 训练生成新模型。 导出方式: python tools/export_model.py -c configs/picodet/legacy_model/application/layout_analysis/picodet_lcnet_x1_0_layout.yml --output_dir=./inference_model -o weights=./checkpoint/model_final export.benchmark=True

9

已经利用picodet_lcnet_x1_0_layout.yml 训练生成新模型。 导出方式: python tools/export_model.py -c configs/picodet/legacy_model/application/layout_analysis/picodet_lcnet_x1_0_layout.yml --output_dir=./inference_model -o weights=./checkpoint/model_final export.benchmark=True

请问你导出后的模型可以用吗,会出现ValueError: (InvalidArgument) The conv2d_fusion Op's Input Variable Input contains uninitialized Tensor. [Hint: Expected t->IsInitialized() == true, but received t->IsInitialized():0 != true:1.] (at /paddle/paddle/fluid/framework/operator.cc:2411) [operator < conv2d_fusion > error]这个错吗?

8

我这边没问题,是不是版本的问题呢?

3

我这边没问题,是不是版本的问题呢?

方便告知一下您用的paddleOCR版本和PaddleDetection版本吗,还有paddlepaddle的版本,谢谢了。

2

export.benchmark=True

我加了这个参数后 export.benchmark=True,可以用了,但是效果很差很差10%都不到,您遇到过吗?去掉这个参数后导出的模型使用python3 deploy/python/infer.py \ --model_dir=picodet_lcnet_x1_0_fgd_layout_cdla_infer/ \ --image_file=docs/images/layout.jpg \ --device=GPU 可以得出结果,效果没有损失,集成到paddleocr里面后就出现这个错误了。

1

paddleDetection 2.5.0 下训练的模型

程序中利用 PPStructure 运行: paddlepaddle==2.4.2 paddleocr==2.6.1.3

9

paddleDetection 2.5.0 下训练的模型

程序中利用 PPStructure 运行: paddlepaddle==2.4.2 paddleocr==2.6.1.3

好的,感谢