Repository: PaddlePaddle/PaddleDetection

Issue:
[Export]最新版的Paddle无法导出模型
### 问题确认 Search before asking

- [X] 我已经查询[历史issue](https://github.com/PaddlePaddle/PaddleDetection/issues)，没有发现相似的bug。I have searched the [issues](https://github.com/PaddlePaddle/PaddleDetection/issues) and found no similar bug report.


### Bug组件 Bug Component

Export

### Bug描述 Describe the Bug

任意模型导出 遇到此错误。
```
python3 tools/export_model.py -c configs/mot/fairmot/fairmot_dla34_30e_576x320.yml -o weights=./models/fairmot_dla34_30e_576x320.pdparams
```
```
[11/01 13:47:50] ppdet.utils.checkpoint INFO: Finish loading model weights: ./models/fairmot_dla34_30e_576x320.pdparams
[11/01 13:47:50] ppdet.data.source.category WARNING: anno_file 'None' 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.
[11/01 13:47:50] ppdet.data.source.category WARNING: metric_type: MOT, load default categories of pedestrian MOT.
[11/01 13:47:50] ppdet.engine INFO: Export inference config file to output_inference/fairmot_dla34_30e_576x320/infer_cfg.yml
Traceback (most recent call last):
  File "tools/export_model.py", line 110, in <module>
    main()
  File "tools/export_model.py", line 106, in main
    run(FLAGS, cfg)
  File "tools/export_model.py", line 73, in run
    trainer.export(FLAGS.output_dir)
  File "/media/wjl/D2/github/fork/PaddleDetection/ppdet/engine/trainer.py", line 1170, in export
    static_model, pruned_input_spec = self._get_infer_cfg_and_input_spec(
  File "/media/wjl/D2/github/fork/PaddleDetection/ppdet/engine/trainer.py", line 1130, in _get_infer_cfg_and_input_spec
    input_spec, static_model.forward.main_program,
  File "/usr/local/lib/python3.8/dist-packages/paddle/jit/dy2static/program_translator.py", line 747, in main_program
    raise_error_template("main_program")()
  File "/usr/local/lib/python3.8/dist-packages/paddle/jit/dy2static/program_translator.py", line 684, 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.

```

原因 static_model.forward.main_program不可能使用？

### 复现环境 Environment

Paddle develop 1540e20051338597c3df4e001c4a1f896c25d74e
Ubuntu 20.04.5 

### Bug描述确认 Bug description confirmation

- [X] 我确认已经提供了Bug复现步骤、代码改动说明、以及环境信息，确认问题是可以复现的。I confirm that the bug replication steps, code change instructions, and environment information have been provided, and the problem can be reproduced.


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

- [X] 我愿意提交PR！I'd like to help by submitting a PR!


Discussion:
需要改写为
static_model = paddle.jit.to_static(
                self.model, input_spec=input_spec, full_graph=True)

Resolving patch:
diff --git a/ppdet/engine/trainer.py b/ppdet/engine/trainer.py
--- a/ppdet/engine/trainer.py
+++ b/ppdet/engine/trainer.py
@@ -1179,7 +1179,7 @@ def _get_infer_cfg_and_input_spec(self,
             })
         if prune_input:
             static_model = paddle.jit.to_static(
-                self.model, input_spec=input_spec)
+                self.model, input_spec=input_spec, full_graph=True)
             # NOTE: dy2st do not pruned program, but jit.save will prune program
             # input spec, prune input spec here and save with pruned input spec
             pruned_input_spec = _prune_input_spec(


Test patch: