Mah*_*any 5 matlab python-3.x conv-neural-network pytorch onnx
我一直在使用多个卷积层(3x3,步长 1,填充相同)在 Pytorch 框架中训练模型。该模型表现良好,我想在 Matlab 中使用它进行推理。为此,框架之间的 NN 交换的 ONNX 格式似乎是(唯一的?)解决方案。可以使用以下命令导出模型:
torch.onnx.export(net.to('cpu'), test_input,'onnxfile.onnx')
Run Code Online (Sandbox Code Playgroud)
这是我的 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
Run Code Online (Sandbox Code Playgroud)
但是,当我运行该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.
Run Code Online (Sandbox Code Playgroud)
我尝试过更改 opset,但这并不能解决问题。ONNX 完全支持卷积神经网络。另外,我正在 google colab 中训练网络。
您知道将模型传输到 matlab 的其他方法吗?
目前,pytorch不支持_convolution_mode
运算符。这是由于使用了.padding='same'
您需要将填充更改为整数值或将其更改为其等效值。请参阅Pytorch 中的相同填充等效项。
归档时间: |
|
查看次数: |
5521 次 |
最近记录: |