我已经在Pythorch中创建了一个模型,我希望将其转换到MATLAB中,下面给出了一个最小的示例import torch.nn as nn
import torch
class cnn(nn.Module):
def __init__(self):
super(cnn, self).__init__()
self.fc1 = nn.Sequential(
nn.Linear(10, 1),
nn.ReLU(True)
)
def forward(self, x):
out = self.fc1(x)
return out
the_net = cnn()
torch.save(the_net,'desperation.h5')
在MATLAB中我调用
^{pr2}$
这将给出错误消息Error using importKerasLayers (line 104)
Unable to read HDF5 file 'desperation.h5'. The error message was: 'The filename specified was either
not found on the MATLAB path or it contains unsupported characters.''
文件在路径上,我可以将模型加载回Python。我真正想要的是任何一种解决方案,它允许我将模型从Pytorch转移到MATLAB中,而不需要手动复制所有权重。在
我运行的是Matlab2018b、Python3.6和Pythorc0.4.0