Skip to content

在PyTorch 1.7下,运行test_video.py报错:RuntimeError: Legacy autograd function with non-static forward method is deprecated. #28

Description

@HYJJJJJJJJ

运行环境:

  • CPU: Intel i7-10700K
  • GPU: RTX3090
  • RAM: 64GB
  • 操作系统:Ubuntu 20.04.1 LTS
  • Python 3.6
  • Pytorch 1.7.0 with CUDA 11.0

背景&现象:

由于Pytorch 1.3以下版本,不支持CUDA11,无法兼容30系GPU,所以使用了Pytorch1.7,运行demo时,输出如下错误:

/home/lmz/anaconda3/envs/py36/bin/python /home/lmz/TPN/test_video.py config_files/sthv2/tsm_tpn.py ckpt/sthv2_tpn.pth
Extracting frames using ffmpeg...
The model and loaded state dict do not match exactly

missing keys in source state_dict: necks.aux_head.convs.conv.weight, necks.aux_head.convs.bn.weight, necks.aux_head.convs.bn.bias, necks.aux_head.convs.bn.running_mean, necks.aux_head.convs.bn.running_var, necks.aux_head.fc.weight, necks.aux_head.fc.bias

Traceback (most recent call last):
File "/home/lmz/TPN/test_video.py", line 148, in
results = inference_recognizer(model, seg_frames)
File "/home/lmz/TPN/test_video.py", line 75, in inference_recognizer
result = model(return_loss=False, rescale=True, **data)
File "/home/lmz/anaconda3/envs/py36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/lmz/TPN/mmaction/models/recognizers/base.py", line 41, in forward
return self.forward_test(num_modalities, img_meta, **kwargs)
File "/home/lmz/TPN/mmaction/models/recognizers/TSN2D.py", line 154, in forward_test
x = self.segmental_consensus(x)
File "/home/lmz/anaconda3/envs/py36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/lmz/TPN/mmaction/models/tenons/segmental_consensuses/simple_consensus.py", line 50, in forward
return _SimpleConsensus(self.consensus_type, self.dim)(input)
File "/home/lmz/anaconda3/envs/py36/lib/python3.6/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)

Process finished with exit code 1

了解到在pytorch1.3及以后的版本需要规定forward方法为静态方法,给TPN/mmaction/models/tenons/segmental_consensuses/simple_consensus.py 中的forward方法加上静态修饰,报错:

/home/lmz/anaconda3/envs/py36/bin/python /home/lmz/TPN/test_video.py config_files/sthv2/tsm_tpn.py ckpt/sthv2_tpn.pth
Extracting frames using ffmpeg...
The model and loaded state dict do not match exactly

missing keys in source state_dict: necks.aux_head.convs.conv.weight, necks.aux_head.convs.bn.weight, necks.aux_head.convs.bn.bias, necks.aux_head.convs.bn.running_mean, necks.aux_head.convs.bn.running_var, necks.aux_head.fc.weight, necks.aux_head.fc.bias

Traceback (most recent call last):
File "/home/lmz/TPN/test_video.py", line 148, in
results = inference_recognizer(model, seg_frames)
File "/home/lmz/TPN/test_video.py", line 75, in inference_recognizer
result = model(return_loss=False, rescale=True, **data)
File "/home/lmz/anaconda3/envs/py36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/lmz/TPN/mmaction/models/recognizers/base.py", line 41, in forward
return self.forward_test(num_modalities, img_meta, **kwargs)
File "/home/lmz/TPN/mmaction/models/recognizers/TSN2D.py", line 154, in forward_test
x = self.segmental_consensus(x)
File "/home/lmz/anaconda3/envs/py36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
TypeError: forward() missing 1 required positional argument: 'input'

Process finished with exit code 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions