[PaddlePaddle/PaddleOCR]请问怎么修改默认9.7M大小的版本面分析模型为221.0M大小的版本面分析模型?

2024-05-14 619 views
8

直接修改模型和字典会报错,是不是哪里还要设置?例如我想用官方模型库里的ppyolov2_r50vd_dcn_365e_publaynet该怎么办?没看到文档里有说明 https://github.com/PaddlePaddle/PaddleOCR/blob/ release/2.6/ppstruct/docs/models_list.md 报错:layout_res, elapse = self.layout_predictor(img) self.predictor.run() ValueError: In user code:

File "tools/export_model.py", line 107, in <module>
  main()
File "tools/export_model.py", line 103, in main
  run(FLAGS, cfg)
File "tools/export_model.py", line 69, in run
  trainer.export(FLAGS.output_dir)
File "/Users/anmengtao/Desktop/model_ED/PaddleDetection-release-2.0/ppdet/engine/trainer.py", line 460, in export
  input_spec, static_model.forward.main_program,
File "/Users/anmengtao/opt/anaconda3/lib/python3.8/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 534, in main_program
  concrete_program = self.concrete_program
File "/Users/anmengtao/opt/anaconda3/lib/python3.8/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 454, in concrete_program
  return self.concrete_program_specify_input_spec(input_spec=None)
File "/Users/anmengtao/opt/anaconda3/lib/python3.8/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 487, in concrete_program_specify_input_spec
  concrete_program, _ = self.get_concrete_program(
File "/Users/anmengtao/opt/anaconda3/lib/python3.8/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 402, in get_concrete_program
  concrete_program, partial_program_layer = self._program_cache[cache_key]
File "/Users/anmengtao/opt/anaconda3/lib/python3.8/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 711, in __getitem__
  self._caches[item] = self._build_once(item)
File "/Users/anmengtao/opt/anaconda3/lib/python3.8/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 698, in _build_once
  concrete_program = ConcreteProgram.from_func_spec(
File "<decorator-gen-58>", line 2, in from_func_spec

File "/Users/anmengtao/opt/anaconda3/lib/python3.8/site-packages/paddle/fluid/wrapped_decorator.py", line 25, in __impl__
  return wrapped_func(*args, **kwargs)
File "/Users/anmengtao/opt/anaconda3/lib/python3.8/site-packages/paddle/fluid/dygraph/base.py", line 39, in __impl__
  return func(*args, **kwargs)
File "/Users/anmengtao/opt/anaconda3/lib/python3.8/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 652, in from_func_spec
  outputs = static_func(*inputs)
File "/var/folders/0t/0lmgjgfj7012tggtgbwtqby80000l2/T/tmpk8piw4sd.py", line 26, in forward
  out = paddle.jit.dy2static.convert_ifelse(self.training, true_fn_1,
File "/Users/anmengtao/opt/anaconda3/lib/python3.8/site-packages/paddle/fluid/dygraph/dygraph_to_static/convert_operators.py", line 210, in convert_ifelse
  return _run_py_ifelse(pred, true_fn, false_fn, true_args, false_args)
File "/Users/anmengtao/opt/anaconda3/lib/python3.8/site-packages/paddle/fluid/dygraph/dygraph_to_static/convert_operators.py", line 235, in _run_py_ifelse
  return true_fn(*true_args) if pred else false_fn(*false_args)
File "/Users/anmengtao/Desktop/model_ED/PaddleDetection-release-2.0/ppdet/modeling/architectures/meta_arch.py", line 29, in forward
  out = self.get_pred()
File "/Users/anmengtao/Desktop/model_ED/PaddleDetection-release-2.0/ppdet/modeling/architectures/yolo.py", line 75, in get_pred
  bbox_pred, bbox_num = self._forward()
File "/Users/anmengtao/Desktop/model_ED/PaddleDetection-release-2.0/ppdet/modeling/architectures/yolo.py", line 59, in _forward
  body_feats = self.backbone(self.inputs)
File "/Users/anmengtao/opt/anaconda3/lib/python3.8/site-packages/paddle/fluid/dygraph/layers.py", line 891, in __call__
  outputs = self.forward(*inputs, **kwargs)
File "/Users/anmengtao/Desktop/model_ED/PaddleDetection-release-2.0/ppdet/modeling/backbones/resnet.py", line 573, in forward
  conv1 = self.conv1(x)
File "/Users/anmengtao/opt/anaconda3/lib/python3.8/site-packages/paddle/fluid/dygraph/layers.py", line 891, in __call__
  outputs = self.forward(*inputs, **kwargs)
File "/Users/anmengtao/opt/anaconda3/lib/python3.8/site-packages/paddle/fluid/dygraph/container.py", line 86, in forward
  input = layer(input)
File "/Users/anmengtao/opt/anaconda3/lib/python3.8/site-packages/paddle/fluid/dygraph/layers.py", line 891, in __call__
  outputs = self.forward(*inputs, **kwargs)
File "/Users/anmengtao/Desktop/model_ED/PaddleDetection-release-2.0/ppdet/modeling/backbones/resnet.py", line 122, in forward
  out = self.conv(inputs)
File "/Users/anmengtao/opt/anaconda3/lib/python3.8/site-packages/paddle/fluid/dygraph/layers.py", line 891, in __call__
  outputs = self.forward(*inputs, **kwargs)
File "/Users/anmengtao/opt/anaconda3/lib/python3.8/site-packages/paddle/nn/layer/conv.py", line 631, in forward
  out = F.conv._conv_nd(
File "/Users/anmengtao/opt/anaconda3/lib/python3.8/site-packages/paddle/nn/functional/conv.py", line 143, in _conv_nd
  helper.append_op(
File "/Users/anmengtao/opt/anaconda3/lib/python3.8/site-packages/paddle/fluid/layer_helper.py", line 43, in append_op
  return self.main_program.current_block().append_op(*args, **kwargs)
File "/Users/anmengtao/opt/anaconda3/lib/python3.8/site-packages/paddle/fluid/framework.py", line 3012, in append_op
  op = Operator(
File "/Users/anmengtao/opt/anaconda3/lib/python3.8/site-packages/paddle/fluid/framework.py", line 2102, in __init__
  for frame in traceback.extract_stack():

InvalidArgumentError: The size of Op(Conv) inputs should not be 0.
  [Hint: Expected in_dims[i] != 0, but received in_dims[i]:0 == 0:0.] (at ..\paddle\phi\infermeta\binary.cc:465)
  [operator < conv2d > error]

回答

7

我也遇到了

5

@andyjpaddle,有什么帮助吗? @kokia2018,有更新吗?

7

table_engine = PPStructure(表 = False,ocr = False,layout_model_dir =“路径/到/...”)

8

@gl94,你能给出完整的代码来加载模型并在sample.jpg/png上进行输出以获取布局bbox吗?我尝试从代码存储库修改 infer.py 文件,但它不起作用。

6

@gl94,你能给出完整的代码来加载模型并在sample.jpg/png上进行输出以获取布局bbox吗?我尝试从代码存储库修改 infer.py 文件,但它不起作用。

下面是我的代码,我建议你在 jupyter 中测试它。

导入操作系统导入cv2从paddleocr导入PPStructure,save_struct_res

table_engine = PPStructure(table=False, ocr=False, show_log=True,layout_model_dir="your_path/picodet_lcnet_x1_0_fgd_layout_table_infer") #将其更改为你的推断模型路径 table_engine_2 = PPStructure(table=False, ocr=False, show_log=True)

img_path = 'your_path/600030_2019_z_5.jpg' img = cv2.imread(img_path) 结果 = table_engine(img) result_2 = table_engine_2(img)

对于结果中的行:

line.pop('img')
 print(line)
9

@gl94,你能给出完整的代码来加载模型并在sample.jpg/png上进行输出以获取布局bbox吗?我尝试从代码存储库修改 infer.py 文件,但它不起作用。

你可以在jupyter中测试我的代码,你会发现结果是一个json类型列表。打印(结果[0].keys())

3

@gl94为什么你必须创建 table_engine 和 table_engine_2 ?

两者似乎不一样,哪个是哪个?

8

@gl94,关于如何从模型的各个输出上获取结果分数有什么想法吗?

结果 = table_engine(图像)

打印(类型(结果))数据=结果打印(len(数据))打印(数据[0].keys())

<class 'list'> 12 dict_keys(['type', 'bbox', 'img', 'res', 'img_idx'])

我得到了预测的“类型”,预测的“bbox”,但没有分数,没有分数我无法计算 mAP 并将其与其他模型进行比较;我错过了什么吗?

0

@gl94,你能给出完整的代码来加载模型并在sample.jpg/png上进行输出以获取布局bbox吗?我尝试从代码存储库修改 infer.py 文件,但它不起作用。

下面是我的代码,我建议你在 jupyter 中测试它。

导入操作系统导入cv2从paddleocr导入PPStructure,save_struct_res

table_engine = PPStructure(table=False, ocr=False, show_log=True,layout_model_dir="your_path/picodet_lcnet_x1_0_fgd_layout_table_infer") #将其更改为你的推断模型路径 table_engine_2 = PPStructure(table=False, ocr=False, show_log=True)

img_path = 'your_path/600030_2019_z_5.jpg' img = cv2.imread(img_path) 结果 = table_engine(img) result_2 = table_engine_2(img)

对于结果中的行:

line.pop('img')
 print(line)

如果我们在初始化 PPStructure lang='en' 时添加https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.7/ppocr/utils/dict/layout_dict/layout_publaynet_dict.txt这些参数,那么这段代码会更好,layout_model_dir =“./exported_models/inference_model/picodet_lcnet_x1_0_fgd_layout_infer”,layout_dict_path =“./exported_models/layout_publaynet_dict.txt”,structural_version =“PP-StructureV2”,

9

该线程最初是为了使用 221mb 模型而开始的,该模型基于 yolo,但只是旁注,如果人们阅读论文 pp-struct v2 https://arxiv.org/abs/2210.05391,他们会发现 9.7mb 模型 picodet 击败yolo 在 PubLayNet 和 CDLA 数据集中的 mAP 得分(表 1 和表 2 供参考)中都有一个,即大小在这里并不重要

8

PPStructure 预训练模型结构和 PaddleDetection 提供的配置文件模型结构不一样,需要使用deploy/python/infer.py进行推理,目前似乎没有提供代码方便地调用推理。