RuntimeError:one of the variables needed for gradient computation has been modified by an inplace...

调试过程出现如下错误:

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [4, 3, 513, 513]], which is output 0 of ReluBackward1, is at version 3; expected version 1 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).

参考博客

由于新版本的pytorch把Varible和Tensor融合为一个Tensor,inplace操作,之前对Varible能用,但现在对Tensor,就会出错了。

res += x # 报错
res = x + res # right
发布了106 篇原创文章 · 获赞 158 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/qq_41997920/article/details/100095961