Convert DeepFillv2 to Onnx

Hello! I’m trying to convert DeepFillv2 model to Onnx, but I have this error: Unsupported: ONNX export of convolution for kernel of unknown shape.

Do you have any ideas why am a getting this error?

Code for converting: `from mmcv.onnx import register_extra_symbolics

def pytorch2onnx(model,
opset_version=11,
show=False,
output_file=‘tmp.onnx’,
verify=False,
dynamic_export=True):
“”“Export Pytorch model to ONNX model and verify the outputs are same
between Pytorch and ONNX.
Args:
model (nn.Module): Pytorch model we want to export.
input (dict): We need to use this input to execute the model.
opset_version (int): The onnx op version. Default: 11.
show (bool): Whether print the computation graph. Default: False.
output_file (string): The path to where we store the output ONNX model.
Default: tmp.onnx.
verify (bool): Whether compare the outputs between Pytorch and ONNX.
Default: False.
“””
model.cpu().eval()

img = torch.rand([3, 256, 256]).unsqueeze(0).cpu()
mask = torch.empty(img.shape[0], 1, img.shape[2], img.shape[3]).cpu()
data = (img, mask)

register_extra_symbolics(opset_version)
dynamic_axes = None
if dynamic_export:
    dynamic_axes = {
        'input': {
            0: 'batch',
            2: 'height',
            3: 'width'
        },
        'output': {
            0: 'batch',
            2: 'height',
            3: 'width'
        }
    }
with torch.no_grad():
    torch.onnx.export(
        model,
        data,
        output_file,
        input_names=['input'],
        output_names=['output'],
        export_params=True,
        keep_initializers_as_inputs=False,
        verbose=show,
        opset_version=opset_version,
        dynamic_axes=dynamic_axes)
print(f'Successfully exported ONNX model: {output_file}')

Traceback:
~/anaconda3/lib/python3.9/site-packages/torch/onnx/symbolic_opset9.py in _convolution(g, input, weight, bias, stride, padding, dilation, transposed, output_padding, groups, benchmark, deterministic, cudnn_enabled, allow_tf32)
1298
1299 if kernel_shape is None or any([i is None for i in kernel_shape]):
→ 1300 raise RuntimeError("Unsupported: ONNX export of convolution for kernel "
1301 “of unknown shape.”)
1302

RuntimeError: Unsupported: ONNX export of convolution for kernel of unknown shape.

I met same issue but i fixed by not using reshape(-1, a, b, c) ‘-1’ not supported by onnx in contextual_attention.py , it must be calculated by yourself.

1 Like