我一直在使用多个卷积层(3x3,步长 1,填充相同)在 Pytorch 框架中训练模型。该模型表现良好,我想在 Matlab 中使用它进行推理。为此,框架之间的 NN 交换的 ONNX 格式似乎是(唯一的?)解决方案。可以使用以下命令导出模型:
torch.onnx.export(net.to('cpu'), test_input,'onnxfile.onnx')
这是我的 CNN 架构定义:
class Encoder_decoder(nn.Module):
def __init__(self):
super().__init__()
self.model = nn.Sequential(
nn.Conv2d(2,8, (3, 3),stride = 1, padding='same'),
nn.ReLU(),
nn.Conv2d(8,8, (3, 3),stride = 1, padding='same'),
nn.ReLU(),
nn.Conv2d(8,16, (3, 3),stride = 1, padding='same'),
nn.ReLU(),
nn.Conv2d(16,16, (3, 3),stride = 1, padding='same'),
nn.ReLU(),
nn.Conv2d(16,32, (3, 3),stride = 1, padding='same'),
nn.ReLU(),
nn.Conv2d(32,32, (3, 3),stride = 1, padding='same'),
nn.ReLU(),
nn.Conv2d(32,64, (3, 3),stride = 1, padding='same'),
nn.ReLU(),
nn.Conv2d(64,64, (3, 3),stride = 1, padding='same'),
nn.ReLU(),
nn.Conv2d(64,128, (3, 3),stride = 1, padding='same'),
nn.ReLU(),
nn.Conv2d(128,128, (3, 3),stride = 1, padding='same'),
nn.ReLU(),
nn.Conv2d(128,1, (1, 1))
)
def forward(self, x):
x = self.model(x)
return x
但是,当我运行torch.onnx.export
命令我收到以下错误:
RuntimeError: Exporting the operator _convolution_mode to ONNX opset version 9 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub.
我尝试过更改 opset,但这并不能解决问题。 ONNX 完全支持卷积神经网络。另外,我正在 google colab 中训练网络。
您知道将模型转移到 matlab 的其他方法吗?