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.65k stars 2.87k forks source link

Can't call main_program when full_graph=False. Use paddle.jit.to_static(full_graph=True) instead. #8941

Open zhenzi0322 opened 5 months ago

zhenzi0322 commented 5 months ago

问题确认 Search before asking

Bug组件 Bug Component

No response

Bug描述 Describe the Bug

使用导出模型发生异常:

python tools/export_model.py -c configs/yolov3/yolov3_mobilenet_v1_roadsign.yml --output_dir=inference_model -o weights=https://paddledet.bj.bcebos.com/models/yolov3_mobilenet_v1_270e_coco.pdparams

异常如下:

Traceback (most recent call last):
  File "E:\python\test\PaddleDetection\tools\export_model.py", line 118, in <module>
    main()
  File "E:\python\test\PaddleDetection\tools\export_model.py", line 114, in main
    run(FLAGS, cfg)
  File "E:\python\test\PaddleDetection\tools\export_model.py", line 80, in run
    trainer.export(FLAGS.output_dir, for_fd=FLAGS.for_fd)
  File "E:\python\test\PaddleDetection\ppdet\engine\trainer.py", line 1229, in export
    static_model, pruned_input_spec = self._get_infer_cfg_and_input_spec(
  File "E:\python\test\PaddleDetection\ppdet\engine\trainer.py", line 1181, in _get_infer_cfg_and_input_spec
    input_spec, static_model.forward.main_program,
  File "D:\python\Envs\test-2Ti2Q\lib\site-packages\paddle\jit\dy2static\program_translator.py", line 768, in main_program
    raise_error_template("main_program")()
  File "D:\python\Envs\test-2Ti2Q\lib\site-packages\paddle\jit\dy2static\program_translator.py", line 704, in _raise_error
    raise RuntimeError(error_template.format(func=func_str))
RuntimeError: Can't call main_program when full_graph=False. Use paddle.jit.to_static(full_graph=True) instead.

复现环境 Environment

拉取分支release/2.7代码。然后按下面的步骤进行即可复现异常。

python tools/train.py -c configs/yolov3/yolov3_mobilenet_v1_roadsign.yml --eval -o use_gpu=true

python tools/export_model.py -c configs/yolov3/yolov3_mobilenet_v1_roadsign.yml --output_dir=inference_model -o weights=https://paddledet.bj.bcebos.com/models/yolov3_mobilenet_v1_270e_coco.pdparams

Bug描述确认 Bug description confirmation

是否愿意提交PR? Are you willing to submit a PR?

zhiboniu commented 5 months ago

可能版本有更新,加上full_graph=True这个参数试一下呢

Dat0901 commented 5 months ago

In ppdet/engine/trainer.py find if prune_input: static_model = paddle.jit.to_static( self.model, input_spec=input_spec) change to if prune_input: static_model = paddle.jit.to_static( self.model, input_spec=input_spec, full_graph=True)