之前好几年的编程,遇到各种奇怪的报错,有的解决了有的没有,现在都忘了,我非常痛心。所以从现在(2023.05.10)开始对以后遇到的报错进行记录。
- 1.RuntimeError: Trying to backward through the graph a second time (or directly access saved variables after they have already been freed). Saved intermediate values of the graph are freed when you call .backward() or autograd.grad(). Specify retain_graph=True if you need to backward through the graph a second time or if you need to access saved variables after calling backward.
1.RuntimeError: Trying to backward through the graph a second time (or directly access saved variables after they have already been freed). Saved intermediate values of the graph are freed when you call .backward() or autograd.grad(). Specify retain_graph=True if you need to backward through the graph a second time or if you need to access saved variables after calling backward.
解决方法:网上较多的是针对一个网络有多个输出分别进行梯度下降的情况,我遇到的则是Softmax和Parameter同时在一条语句中使用时报错,解决方法是去掉Softmax