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

发布时间:2024-08-17 14:01

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [128, 3, 4, 4]] is at version 2; 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).

在做stackGAN时候的问题,需要把前一个网络的G的输出作为下一层的输入,一开始的时候把两个网络合在一起写的,
iuputs-》G1-》output1,训练G1,output1->G2,训练G2
这时候是不能运行的,
报错:
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [128, 3, 4, 4]] is at version 2; 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).
但是后面改成了
inuts->G1->output1 ,训练G1,inuts->G1(训练后的)->output1->G2,训练G2
感觉应该是变量是否存在梯度的问题,可能第一层的一开始的输出不能被梯度吧,需要再看看这些个变量的问题。

自用,不保证对错。

ItVuer - 免责声明 - 关于我们 - 联系我们

本网站信息来源于互联网,如有侵权请联系:561261067@qq.com

桂ICP备16001015号