Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
HYJJJJJJJJ opened this issue Dec 2, 2020 · 4 comments

Comments

@HYJJJJJJJJ
Copy link

运行环境:

  • 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

@LiuWenJia-ops
Copy link

可以试试x = self.segmental_consensus.forward(x), 或者是具体调用segmental_consensus里的某个子模型, 我遇到相似的问题是这么解决的

@Note-Liu
Copy link

Note-Liu commented Jul 4, 2021

I have the same issue,how did you solve it?

@784682065
Copy link

I have the same issue,how did you solve it?

I solved this problem whit this link
b02523d

@ZienZhang6
Copy link

@784682065 这个回答暂时解决了我的问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants