【发布时间】:2021-10-04 11:24:18
【问题描述】:
我一直在使用多个卷积层(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的其他方法吗?
【问题讨论】:
标签: python-3.x matlab pytorch conv-neural-network onnx