在写深度学习的时候,运行代码发现如下error:
one of the variables needed for gradient computation has been modified by an inplace operation:torch.DoubleTensor [64, 80, 5]], which is output 0 of ReluBackward0, is at version 1; expected version 0 instead.
Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).
大意就是说在计算梯度的时候检查出某个Variable有被一个 inplace operation
修改。
网上说的什么改loss.backward()、改+=什么尝试了一遍,都没有用
后来根据配置要求看了一下,发现是torch版本的问题,把torch版本降级到需要版本就好了
使用pycharm写的,在settings-》project-》python interpreter找到torch,双击找到specify version,改到需要的版本
顺便改完torch版本后记得把torchvision的版本也改了,按照网上给出的对应版本