报错:RuntimeError: Legacy autograd function with non-static forward method is deprecated

RuntimeError: Legacy autograd function with non-static forward method is deprecated

解决方法:
1、在出错的地方def forward()前面加上@staticmethod,即

def forward()

改为:

@staticmethod
def forward()

2、当forward变成静态方法后,调用时可使用.apply(),即:

net = Model() 
y = net(x)

改为:

net = Model() 
y = net.apply(x)

你可能感兴趣的:(深度学习,pytorch)