pytorch:网络定义参数的时候后面不能加".cuda()"

2022-10-20 11:07:22

pytorch定义网络__init__()的时候,参数不能加“cuda()", 不然参数不包含在state_dict()中,比如下面这种写法是错误的

self.W1= nn.Parameter(torch.FloatTensor(3,3), requires_grad=True).cuda()

应该去掉".cuda()"

self.W1= nn.Parameter(torch.FloatTensor(3,3), requires_grad=True)
  • 作者:whyume
  • 原文链接:https://blog.csdn.net/whyume/article/details/81544180
    更新时间:2022-10-20 11:07:22