Legacy autograd function with non-static forward method is deprecated. Please use new-style autograd function with static forward method jacke121
报错代码:
self.priors_pal2.type(type(x.data)).to(self.device)
我的解决方法:
我的这个类只有forward函数,么有backward,我就把继承Function去掉了。
改成普通的类调用,就可以了。
网上的有反向传播的解决方法:
加 staticmethod注释
class GradReverse(Function):
# 重写父类方法的时候,最好添加默认参数,不然会有warning(为了好看。。)
@ staticmethod
def forward(ctx, x, lambd, **kwargs: None):
# 其实就是传入dict{'lambd' = lambd}
ctx.lambd = lambd
return x.view_as(x)
@staticmethod