decisionforce / TPN

[CVPR 2020] Temporal Pyramid Network for Action Recognition
https://decisionforce.github.io/TPN/
Apache License 2.0
394 stars 55 forks source link

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

Open HYJJJJJJJJ opened 3 years ago

HYJJJJJJJJ commented 3 years ago

运行环境:

背景&现象:

由于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 commented 3 years ago

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

Note-Liu commented 3 years ago

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

784682065 commented 3 years ago

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

I solved this problem whit this link https://github.com/decisionforce/TPN/pull/30/commits/b02523d94d39f4439bc081d8097c054ca010d6ce

ZienZhang6 commented 1 year ago

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