解决SSD报错:Legacy autograd function with non-static forward method is deprecated.

报错记录:

Traceback (most recent call last):
  File "eval.py", line 438, in
    thresh=args.confidence_threshold)
  File "eval.py", line 385, in test_net
    detections = net(x).data
  File "D:\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "D:\0_me_python\ssd.pytorch-master\ssd.pytorch-master\ssd.py", line 103, in forward
    self.priors.type(type(x.data))                  # default boxes
  File "D:\Anaconda3\lib\site-packages\torch\autograd\function.py", line 160, in __call__
    "Legacy autograd function with non-static forward method is deprecated. "
RuntimeError: Legacy autograd function with non-static forward method is deprecated. Please use new-style autograd function with static forward method. (Example: https://pytorch.org/docs/stable/autograd.html#torch.autograd.Function)

        原因:是Torch版本太高,在pytorch1.3及以后的版本需要规定forward方法为静态方法,所以在pytorch1.3以上的版本执行出错。 

解决方案是将ssd.py中的以下代码进行修改:

解决SSD报错:Legacy autograd function with non-static forward method is deprecated._第1张图片

修改为 :

解决SSD报错:Legacy autograd function with non-static forward method is deprecated._第2张图片

你可能感兴趣的:(异常报错,机器学习,python,线性代数)