Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The model conversion from ONNX to X2paddle failed on a VGG model (trained on MNIST) #992

Open
shiningrain opened this issue Sep 1, 2023 · 0 comments

Comments

@shiningrain
Copy link

shiningrain commented Sep 1, 2023

Description

When I'm trying to convert an onnx model (which is constructed by myself, trained on MNIST dataset and using VGG architecture), the conversion of X2paddle throws a value as follows:

In transformed code:

    File "./result_m_v-7/paddle_model/x2paddle_code.py", line 60, in forward
        x2paddle_functional_1_concatenate_concat_0 = paddle.concat(x=[x2paddle_functional_1_resizing_resize_ResizeBilinear_0, x2paddle_functional_1_resizing_resize_ResizeBilinear_0, x2paddle_functional_1_resizing_resize_ResizeBilinear_0], axis=3)
        x2paddle_adjusted_input12 = paddle.transpose(x=x2paddle_functional_1_concatenate_concat_0, perm=[0, 3, 1, 2])
        x2paddle_convolution_output12 = self.conv0(x2paddle_adjusted_input12)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
        x2paddle_functional_1_vgg16_block1_conv1_Relu_0 = self.relu0(x2paddle_convolution_output12)
        x2paddle_convolution_output11 = self.conv1(x2paddle_functional_1_vgg16_block1_conv1_Relu_0)

    File "./python3.6/site-packages/paddle/fluid/dygraph/layers.py", line 917, in __call__
	return self._dygraph_call_func(*inputs, **kwargs)
    File ".python3.6/site-packages/paddle/fluid/dygraph/layers.py", line 907, in _dygraph_call_func
	outputs = self.forward(*inputs, **kwargs)
    File "./python3.6/site-packages/paddle/nn/layer/conv.py", line 677, in forward
	use_cudnn=self._use_cudnn)
    File "./python3.6/site-packages/paddle/nn/functional/conv.py", line 148, in _conv_nd
	type=op_type, inputs=inputs, outputs=outputs, attrs=attrs)
    File "./python3.6/site-packages/paddle/fluid/layer_helper.py", line 43, in append_op
	return self.main_program.current_block().append_op(*args, **kwargs)
    File "./python3.6/site-packages/paddle/fluid/framework.py", line 3184, in append_op
	attrs=kwargs.get("attrs", None))
    File "./python3.6/site-packages/paddle/fluid/framework.py", line 2344, in __init__
	self.desc.infer_shape(self.block.desc)

    ValueError: (InvalidArgument) The number of input's channels should be equal to filter's channels * groups for Op(Conv). But received: the input's channels is -1, the input's shape is [-1, -1, -1, -1]; the filter's channels is 3, the filter's shape is [64, 3, 3, 3]; the groups is 1, the data_format is NCHW. The error may come from wrong data_format setting.
  [Hint: Expected input_channels == filter_dims[1] * groups, but received input_channels:-1 != filter_dims[1] * groups:3.] (at /paddle/paddle/fluid/operators/conv_op.cc:119)
  [operator < conv2d > error]

This onnx model can be converted to pytorch with onnx2torch but failed when converting to paddle with X2paddle. Could anyone kindly tell me the reason?

Versions

onnx 1.11.0
paddlepaddle 2.2.2
x2paddle 1.4.0

Reproduce

Model

I have put the model (which is about 50 MB) in this repo and you could download it and unzip this file mnist+vgg.zip to get the whole model.

I also uploaded the .zip file of the conversion result in this repo. The paddle_model dir is generated by X2paddle and this ValueError caused the paddle_model/inference_model directory to be empty.

Command

I try to covert this onnx model with the following command and then face the above ValueError.

x2paddle --framework=onnx --model=./.onnx --save_dir=./tmp_pb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant