Repository: PaddlePaddle/X2Paddle

Issue:
onnx模型转换到paddle时发生错误。
ONNX模型的来源：由pytorch转换而来，自己设计的算法模型（基于centernet），在pytorch中跑没有问题。
模型类型：目标检测  

具体问题：使用v0.8.9的x2paddle转换发生错误
转换命令：x2paddle --framework=onnx --model=circledet.onnx --save_dir=circledet_model
错误：
```
paddle.__version__ = 1.8.4
Now translating model from onnx to paddle.
model ir_version: 4, op version: 9
shape inferencing ...
[INFO] Complete symbolic shape inference.
shape inferenced.
Now, onnx2paddle support convert onnx model opset_verison [9],opset_verison of your onnx model is 9, automatically treated as op_set: 9.
Total nodes: 214
Nodes converting ...
Nodes converted.
Model optimizing ...
Model optimized.
Paddle model and code generating ...
Traceback (most recent call last):
  File "/opt/conda/lib/python3.6/site-packages/x2paddle/core/op_mapper.py", line 142, in save_inference_model
    inputs, outputs = model.x2paddle_net()
  File "circledet_model/model_with_code/model.py", line 104, in x2paddle_net
    x2paddle_529 = fluid.layers.conv2d(x2paddle_528, num_filters=32, filter_size=[3, 3], stride=[1, 1], padding=[1, 1], dilation=[1, 1], groups=1, param_attr='x2paddle_dla_up_ida_2_node_1_0_weight', name='x2paddle_529', bias_attr=False)
  File "/opt/conda/lib/python3.6/site-packages/paddle/fluid/layers/nn.py", line 2835, in conv2d
    "Received: %s." % (str(input.shape), str(num_channels)))
ValueError: The channel dimmention of the input((1, -1, 128, 128)) should be defined. Received: -1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/conda/bin/x2paddle", line 8, in <module>
    sys.exit(main())
  File "/opt/conda/lib/python3.6/site-packages/x2paddle/convert.py", line 285, in main
    onnx2paddle(args.model, args.save_dir, params_merge)
  File "/opt/conda/lib/python3.6/site-packages/x2paddle/convert.py", line 181, in onnx2paddle
    mapper.save_inference_model(save_dir, params_merge)
  File "/opt/conda/lib/python3.6/site-packages/x2paddle/core/op_mapper.py", line 197, in save_inference_model
    .format(py_code_dir))
Exception: Paddle code was saved in circledet_model/model_with_code/model.py, but seems there's wrong exist, please check model.py manually.
```




Discussion:
@daiyuanm 方便的话请把onnx的模型发到我的邮箱：chen_lingchi@163.com ，发送了之后请在issue里面留言一下。
> @daiyuanm 方便的话请把onnx的模型发到我的邮箱：[chen_lingchi@163.com](mailto:chen_lingchi@163.com) ，发送了之后请在issue里面留言一下。

你好，发给你了，发件人：ctdaiyuan@mail.scut.edu.cn
@daiyuanm 收到，有结论会尽快回复
> @daiyuanm 收到，有结论会尽快回复

好的，可以随时沟通
@daiyuanm 定位到原因是模型中过conv2d_transpose后，shape inference的时候出来channel变成-1了，导致后面conv做shape inference报错，PS: conv的输入channel必须是固定的。
解决办法还在寻找中.....
> @daiyuanm 定位到原因是模型中过conv2d_transpose后，shape inference的时候出来channel变成-1了，导致后面conv做shape inference报错，PS: conv的输入channel必须是固定的。
> 解决办法还在寻找中.....

多谢了，我们也不是cs专业的...希望能够尽快解决，麻烦了！

Resolving patch:
diff --git a/x2paddle/op_mapper/onnx2paddle/opset9/opset.py b/x2paddle/op_mapper/onnx2paddle/opset9/opset.py
--- a/x2paddle/op_mapper/onnx2paddle/opset9/opset.py
+++ b/x2paddle/op_mapper/onnx2paddle/opset9/opset.py
@@ -1564,7 +1564,7 @@ def ConvTranspose(self, node):
                           ) * strides[1] - 2 * paddings[1] + dilations[1] * (
                               kernel_shape[1] - 1) + 1 + out_padding[1]
         attr = {
-            'num_filters': num_out_channels,
+            'num_filters': num_out_channels * num_groups,
             'output_size': output_size or None,
             'filter_size': kernel_shape,
             'padding': paddings,


Test patch: