mmaction2
mmaction2 copied to clipboard
how can I inference on single video for BMN for action localization
I m using this code of building the model and testing a given video.
"import torch
from mmaction.apis import init_recognizer, inference_recognizer
config_file = 'configs/recognition/tsn/tsn_r50_video_inference_1x1x3_100e_kinetics400_rgb.py' checkpoint_file = 'checkpoints/tsn_r50_1x1x3_100e_kinetics400_rgb_20200614-e508be42.pth'
device = 'cuda:0' # or 'cpu' device = torch.device(device)
model = init_recognizer(config_file, checkpoint_file, device=device video = 'demo/demo.mp4'
labels = 'tools/data/kinetics/label_map_k400.txt' results = inference_recognizer(model, video)
labels = open('tools/data/kinetics/label_map_k400.txt').readlines() labels = [x.strip() for x in labels] results = [(labels[k[0]], k[1]) for k in results]
print(f'The top-5 labels with corresponding scores are:') for result in results: print(f'{result[0]}: ', result[1])"
can we do inferences on single video for action localization using BMN. If yes its is it work with this code?
You can refer to https://github.com/open-mmlab/mmaction2/blob/master/configs/localization/bmn/README.md. The init_recognizer
and inference_recognizer
functions are used for classification tasks.
I have tried it but having issues. This is my Inference_video.py
import torch
from mmaction.apis import init_recognizer, inference_recognizer
config_file = r'configs\localization\bmn\bmn_400x100_2x8_9e_activitynet_feature.py'
# download the checkpoint from model zoo and put it in `checkpoints/`
checkpoint_file = r'configs\localization\bmn\bmn_400x100_9e_activitynet_feature_20200619-42a3b111.pth'
# assign the desired device.
device = 'cuda:0' # or 'cpu'
device = torch.device(device)
# build the model from a config file and a checkpoint file
model = init_recognizer(config_file, checkpoint_file, device=device)
# test a single video and show the result:
video = r'C:\Users\ASDF\Downloads\test.mp4'
labels = r'C:\Users\ASDF\Desktop\mmaction2\tools\data\activitynet\label_map.txt'
results = inference_recognizer(model, video)
# show the results
labels = open(r'C:\Users\ASDF\Desktop\mmaction2\tools\data\activitynet\label_map.txt').readlines()
labels = [x.strip() for x in labels]
results = [(labels[k[0]], k[1]) for k in results]
print(f'The top-5 labels with corresponding scores are:')
for result in results:
print(f'{result[0]}: ', result[1])
Error
Traceback (most recent call last):
File "inference_video.py", line 14, in
I also followed this (https://github.com/open-mmlab/mmaction2/blob/master/configs/localization/bmn/README.md.) readme.
I m running the test.py file with given parameters
python test.py configs/localization/bmn/bmn_400x100_2x8_9e_activitynet_feature.py C:\Users\ASDF\Desktop\mmaction2\tools\configs\localization\bmn\bmn_400x100_9e_activitynet_feature_20200619-42a3b111.pth --eval AR@AN --out results.json
But its also giving error
Traceback (most recent call last):
File "test.py", line 372, in
I also followed this (https://github.com/open-mmlab/mmaction2/blob/master/configs/localization/bmn/README.md.) readme.
I m running the test.py file with given parameters
python test.py configs/localization/bmn/bmn_400x100_2x8_9e_activitynet_feature.py C:\Users\ASDF\Desktop\mmaction2\tools\configs\localization\bmn\bmn_400x100_9e_activitynet_feature_20200619-42a3b111.pth --eval AR@AN --out results.json
But its also giving error
Traceback (most recent call last): File "test.py", line 372, in main() File "test.py", line 357, in main outputs = inference_pytorch(args, cfg, distributed, data_loader) File "test.py", line 162, in inference_pytorch model, default_device, default_args=dict(device_ids=cfg.gpu_ids)) File "C:\Users\ASDF\anaconda3\envs\open-mmlab\lib\site-packages\mmcv\utils\config.py", line 519, in getattr return getattr(self._cfg_dict, name) File "C:\Users\ASDF\anaconda3\envs\open-mmlab\lib\site-packages\mmcv\utils\config.py", line 50, in getattr raise ex AttributeError: 'ConfigDict' object has no attribute 'gpu_ids'
To solve this replace the cfg.gpu_ids with [0]. I thinks its the issue of pytorch which is not getting gpu id
Adding --cfg-option gpu_ids=[0]
to the commands would work without modifying the config files.
I encountered a similar issue where I am unable to deploy BMN on a single video. Have you found a solution for this?