'pth to onnx model convertion

I am trying to convert the pth format to onnx, while converting, I face this issue,

RuntimeError: Exporting the operator _convolution_mode to ONNX opset version 13 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub.

pytorch version is 1.11.0+cpu

model -

    cnn = nn.Sequential()
    cnn.add_module('l1', nn.Conv2d(3, 32, 2, 1, "same"))
    cnn.add_module('l2', nn.ReLU())
    cnn.add_module('l3', nn.MaxPool2d(3, 3))

    ...

    cnn.add_module('fl', nn.LogSoftmax())

    torch.onnx.export(model, torch.zeros(16, 3, 224, 224).to(device), save_file, verbose=True, opset_version=13,
                export_params=True,
                training=torch.onnx.TrainingMode.EVAL,
                do_constant_folding=True,
                input_names = ['cnn.l1'], output_names=['cnn.fl'],
                          dynamic_axes={'cnn.l1': {0: 'batch'},
                                        'cnn.fl': {0: 'batch'}
                                        })

In this, I got two warnings,

UserWarning: Using padding='same' with even kernel lengths and odd dilation may require a zero-padded copy of the input be created (Triggered internally at ../aten/src/ATen/native/Convolution.cpp:744.)

Implicit dimension choice for log_softmax has been deprecated. Change the call to include dim=X as an argument.

How to successfully convert the pth file to onnx, thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source