@[TOC](UserWarning: volatile was removed and now has no effect. Use with torch.no_grad():
instead.
input_var = torch.autograd.Variable(input, volatile=True)
UserWarning: volatile was removed and now has no effect. Use with torch.no_grad():
instead.
pytorch进行自动梯度下降时出现错误
input_var = torch.autograd.Variable(input, volatile=True)
target_var = torch.autograd.Variable(target, volatile=True)
当执行上面的代码时出现如下错误:
E:/hscnn_main.py:165: UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
input_var = torch.autograd.Variable(input, volatile=True)
E:/hscnn_main.py:166: UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
target_var = torch.autograd.Variable(target, volatile=True)
由于版本迭代,我们只需要按照提示步骤将其改为如下表示方式即可:
with torch.no_grad():
input_var = torch.autograd.Variable(input)
with torch.no_grad():
target_var = torch.autograd.Variable(target)
成功解除报错!
"with torch.no_grad():"表示后面的执行代码得到的结果不会参与反向传播,因此我们只需要知道forword的结果就可以了,不需要记录网络参数。在交叉检验或者测试过程中我们只需要网络输出的结果,不需要记录传播过程的参数,因此会节约内存。