解决方案:volatile was removed and now has no effect. Use with torch.no_grad():
instead.
源代码
self.priors = Variable(self.priorbox.forward(), volatile=True)
原因
- 在torch版本中
volatile
已经被移除。
在pytorch 0.4.0之前 input= Variable(input, volatile=True) 设置volatile为True ,只要是一个输入为volatile,则输出也是volatile的,它能够保证不存在中间状态;但是在pytorch 0.4.0之后取消了volatile的机制 被替换成torch.no_grad(), torch.set_grad_enable(grad_mode)等函数 - torch.no_grad() 是一个上下文管理器
在使用pytorch时,并不是所有的操作都需要进行计算图的生成(计算过程的构建,以便梯度反向传播等操作)。而对于tensor的计算操作,默认是要进行计算图的构建的,在这种情况下,可以使用 with torch.no_grad():,强制之后的内容不进行计算图构建。
在torch.no_grad() 会影响pytorch的反向传播机制,在测试时因为确定不会使用到反向传播因此 这种模式可以帮助节省内存空间。同理对于 torch.set_grad_enable(grad_mode)也是这样
修改为
with torch.no_grad():
self.priors = Variable(self.priorbox.forward())
或者
self.priors = Variable(self.priorbox.forward())