PaddlePaddle / PaddleDetection

Object Detection toolkit based on PaddlePaddle. It supports object detection, instance segmentation, multiple object tracking and real-time multi-person keypoint detection.
Apache License 2.0
12.79k stars 2.89k forks source link

对faster rcnn 进行export_model报错 #9075

Open Ochre-amber opened 3 months ago

Ochre-amber commented 3 months ago

问题确认 Search before asking

请提出你的问题 Please ask your question

为了将faster rcnn转为onnx模型,考虑先使用export_model.py导出,运行命令: python tools/export_model.py -c configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.yml -o weights=output/frcnn/model_final.pdparams export_onnx=True --output_dir=output_inference/frcnn/但出现报错

[07/28 01:10:02] ppdet.utils.checkpoint INFO: Finish loading model weights: frcnn/model_final.pdparams
[07/28 01:10:02] ppdet.engine WARNING: Exporting RCNN model to ONNX only support batch_size = 1
[07/28 01:10:02] ppdet.data.source.category WARNING: anno_file '/aidata/CYHan/project_benke/mmdetection-main/data/coco/annotations/instances_val2017.json' is None or not set or not exist, please recheck TrainDataset/EvalDataset/TestDataset.anno_path, otherwise the default categories will be used by metric_type.
[07/28 01:10:02] ppdet.data.source.category WARNING: metric_type: COCO, load default categories of COCO.
[07/28 01:10:02] ppdet.engine INFO: Export inference config file to output_inference/frcnn/faster_rcnn_r50_fpn_1x_coco/infer_cfg.yml
Traceback (most recent call last):
  File "tools/export_model.py", line 118, in <module>
    main()
  File "tools/export_model.py", line 114, in main
    run(FLAGS, cfg)
  File "tools/export_model.py", line 80, in run
    trainer.export(FLAGS.output_dir, for_fd=FLAGS.for_fd)
  File "/project/PaddleDetection-develop/ppdet/engine/trainer.py", line 1257, in export
    static_model, pruned_input_spec = self._get_infer_cfg_and_input_spec(
  File "/project/PaddleDetection-develop/ppdet/engine/trainer.py", line 1209, in _get_infer_cfg_and_input_spec
    input_spec, static_model.forward.main_program,
  File "/home/nvidia/plugs/yes/envs/paddle/lib/python3.8/site-packages/paddle/jit/dy2static/program_translator.py", line 1062, in main_program
    concrete_program = self.concrete_program
  File "/home/nvidia/plugs/yes/envs/paddle/lib/python3.8/site-packages/paddle/jit/dy2static/program_translator.py", line 941, in concrete_program
    return self.concrete_program_specify_input_spec(input_spec=None)
  File "/home/nvidia/plugs/yes/envs/paddle/lib/python3.8/site-packages/paddle/jit/dy2static/program_translator.py", line 986, in concrete_program_specify_input_spec
    concrete_program, _ = self.get_concrete_program(
  File "/home/nvidia/plugs/yes/envs/paddle/lib/python3.8/site-packages/paddle/jit/dy2static/program_translator.py", line 875, in get_concrete_program
    concrete_program, partial_program_layer = self._program_cache[
  File "/home/nvidia/plugs/yes/envs/paddle/lib/python3.8/site-packages/paddle/jit/dy2static/program_translator.py", line 1648, in __getitem__
    self._caches[item_id] = self._build_once(item)
  File "/home/nvidia/plugs/yes/envs/paddle/lib/python3.8/site-packages/paddle/jit/dy2static/program_translator.py", line 1575, in _build_once
    concrete_program = ConcreteProgram.from_func_spec(
  File "/home/nvidia/plugs/yes/envs/paddle/lib/python3.8/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "/home/nvidia/plugs/yes/envs/paddle/lib/python3.8/site-packages/paddle/base/wrapped_decorator.py", line 26, in __impl__
    return wrapped_func(*args, **kwargs)
  File "/home/nvidia/plugs/yes/envs/paddle/lib/python3.8/site-packages/paddle/base/dygraph/base.py", line 68, in __impl__
    return func(*args, **kwargs)
  File "/home/nvidia/plugs/yes/envs/paddle/lib/python3.8/site-packages/paddle/jit/dy2static/program_translator.py", line 1346, in from_func_spec
    error_data.raise_new_exception()
  File "/home/nvidia/plugs/yes/envs/paddle/lib/python3.8/site-packages/paddle/jit/dy2static/error.py", line 452, in raise_new_exception
    raise new_exception from None
IndexError: In transformed code:

    File "/project/PaddleDetection-develop/ppdet/modeling/architectures/meta_arch.py", line 59, in forward
        if self.training:
    File "/project/PaddleDetection-develop/ppdet/modeling/architectures/meta_arch.py", line 69, in forward
        for inp in inputs_list:
    File "/project/PaddleDetection-develop/ppdet/modeling/architectures/meta_arch.py", line 76, in forward
        outs.append(self.get_pred())
    File "/project/PaddleDetection-develop/ppdet/modeling/architectures/faster_rcnn.py", line 122, in get_pred
        if self.use_extra_data:
    File "/project/PaddleDetection-develop/ppdet/modeling/architectures/faster_rcnn.py", line 130, in get_pred
        bbox_pred, bbox_num = self._forward()
    File "/project/PaddleDetection-develop/ppdet/modeling/architectures/faster_rcnn.py", line 79, in _forward
        if self.training:
    File "/project/PaddleDetection-develop/ppdet/modeling/architectures/faster_rcnn.py", line 89, in _forward
        bbox, bbox_num, nms_keep_idx = self.bbox_post_process(
    File "/project/PaddleDetection-develop/ppdet/modeling/post_process.py", line 69, in __call__
        if self.nms is not None:
    File "/project/PaddleDetection-develop/ppdet/modeling/post_process.py", line 70, in __call__
        bboxes, score = self.decode(head_out, rois, im_shape, scale_factor)
    File "/project/PaddleDetection-develop/ppdet/modeling/layers.py", line 464, in __call__
        if self.export_onnx:
    File "/project/PaddleDetection-develop/ppdet/modeling/layers.py", line 465, in __call__
        if self.export_onnx:
            onnx_rois_num_per_im = rois_num[0]
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
            origin_shape = paddle.expand(im_shape[0, :],
                                         [onnx_rois_num_per_im, 2])

    File "/home/nvidia/plugs/yes/envs/paddle/lib/python3.8/site-packages/paddle/base/framework.py", line 2500, in __getitem__
        return _getitem_static(self, item)
    File "/home/nvidia/plugs/yes/envs/paddle/lib/python3.8/site-packages/paddle/base/variable_index.py", line 800, in _getitem_static
        ) = parse_index(x, indices)
    File "/home/nvidia/plugs/yes/envs/paddle/lib/python3.8/site-packages/paddle/base/variable_index.py", line 300, in parse_index
        and x.shape[dim] is not None

    IndexError: tuple index out of range

请问如何正确导出faster rcnn?

Ochre-amber commented 3 months ago

根本问题就是控制流怎么去掉的问题

hzylalala commented 2 months ago

您好,请问您解决这个问题了吗,我也遇到了同样的问题

Ochre-amber commented 2 months ago

您好,请问您解决这个问题了吗,我也遇到了同样的问题

还没有,或许可以尝试一下https://github.com/PaddlePaddle/Paddle2ONNX/issues/699 的解决方法,用老版本的paddle尝试一下。

Ochre-amber commented 2 months ago

@hzylalala 用paddlepaddle2.4 paddledet2.4 似乎可以

您好,请问您解决这个问题了吗,我也遇到了同样的问题