open-mmlab / mmaction2

OpenMMLab's Next Generation Video Understanding Toolbox and Benchmark
https://mmaction2.readthedocs.io
Apache License 2.0
4.31k stars 1.25k forks source link

[Bug] AttributeError: 'ConfigDict' object has no attribute 'test_pipeline' when run video Inference demo code from mmaction2 official site #2866

Closed slent310 closed 3 months ago

slent310 commented 3 months ago

Branch

main branch (1.x version, such as v1.0.0, or dev-1.x branch)

Prerequisite

Environment

sys.platform: win32 Python: 3.8.19 | packaged by conda-forge | (default, Mar 20 2024, 12:38:07) [MSC v.1929 64 bit (AMD64)] CUDA available: True MUSA available: False numpy_random_seed: 2147483648 GPU 0: NVIDIA GeForce RTX 3060 CUDA_HOME: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3 NVCC: Cuda compilation tools, release 11.3, V11.3.58 MSVC: Microsoft (R) C/C++ 최적화 컴파일러 버전 19.29.30151(x64) GCC: n/a PyTorch: 1.9.1+cu111 PyTorch compiling details: PyTorch built with:

TorchVision: 0.10.1+cu111 OpenCV: 4.10.0 MMEngine: 0.10.4 MMAction2: 1.2.0+4d6c934 MMCV: 2.1.0 MMDetection: 3.3.0

Describe the bug

Hi ~ I make my costomed ava dataset and trianed it with the config file in detection/slowfast/slowfast_kinetics400-pretrained-r50_8xb6-8x8x1-cosine-10e_ava22-rgb.py by following mmaction2 training instruction and get my pth files successfully. and now I want to do some video inference with the my model file to test. but when I use Inference demo code from mmaction2 official site It comes that error , I try to find some way to get this done and tried to replace test_pipeline to val_pipeline or replace cfg.test_pipeline to cfg.pipeline (cus I find a similar issue was work out with it) but it's still not work. greatfully waitting for a advice or any solution about it. plz ㅠㅠ

Reproduces the problem - code sample

inference_video.py

import os from mmaction.apis import inference_recognizer, init_recognizer

config_path = 'configs/detection/slowfast/my_slowfast_kinetics400-pretrained-r50_8xb6-8x8x1-cosine-10e_ava22-rgb.py' checkpoint_path = 'work_dirs/my_slowfast_kinetics400-pretrained-r50_8xb6-8x8x1-cosine-10e_ava22-rgb_2/epoch_100.pth' img_path = 'demo/Arrangement_0021_01.avi' model = init_recognizer(config_path, checkpoint_path, device="cpu")
result = inference_recognizer(model, img_path)

print(result)

Reproduces the problem - command or script

python inference_video.py

Reproduces the problem - error message

Loads checkpoint by local backend from path: work_dirs/my_slowfast_kinetics400-pretrained-r50_8xb6-8x8x1-cosine-10e_ava22-rgb_2/epoch_100.pth Traceback (most recent call last): File "C:\ProgramData\Anaconda3\envs\mmaction\lib\site-packages\mmengine\config\config.py", line 109, in getattr value = super().getattr(name) File "C:\Users\xxx\AppData\Roaming\Python\Python38\site-packages\addict\addict.py", line 67, in getattr return self.getitem(item) File "C:\ProgramData\Anaconda3\envs\mmaction\lib\site-packages\mmengine\config\config.py", line 138, in getitem return self.build_lazy(super().getitem(key)) File "C:\ProgramData\Anaconda3\envs\mmaction\lib\site-packages\mmengine\config\config.py", line 105, in missing raise KeyError(name) KeyError: 'test_pipeline'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "inference_video.py", line 9, in result = inference_recognizer(model, img_path) File "D:\working_space_xxx\mmaction2\mmaction\apis\inference.py", line 79, in inference_recognizer test_pipeline_cfg = cfg.test_pipeline #test_pipeline_cfg = cfg.test_pipeline File "C:\ProgramData\Anaconda3\envs\mmaction\lib\site-packages\mmengine\config\config.py", line 1499, in getattr return getattr(self._cfg_dict, name) File "C:\ProgramData\Anaconda3\envs\mmaction\lib\site-packages\mmengine\config\config.py", line 113, in getattr raise AttributeError(f"'{self.class.name}' object has no " AttributeError: 'ConfigDict' object has no attribute 'test_pipeline'

Additional information

No response

slent310 commented 3 months ago

Hi, I would like to ask if the inference code in demo is only applicable to pre-trained model files, if I want to inference from my own dataset trained model files which parts need to be modified? I just replaced test_pipeline with val_pipeline then the video part comes to another error which might have some problem to process the input video, becauce I try the same video with slowfast pre-trained model and it's run without any problem. so I guess it might be something wrong with the pth file. I'm still try to figure it out... hope to get some advice. thanks a lot ! the error message is down bellow : File "d:\working_space_xxx\mmaction2\mmaction\datasets\transforms\loading.py", line 753, in transform fps = results['fps'] KeyError: 'fps'

slent310 commented 3 months ago

Hi! turns out that I use the wrong weights and it should be tested on demo_spatiotemporal_det.py or webcam_demo_spatiotemporal_det.py (If someone like me train ava dataset using slowfast or videomae to detect some action task). so anyway problem solved and thank you all ^ ^