python中如何导入torch_如何将Pytorch模型导入MATLAB

我已经在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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值