本文共 7111 字,大约阅读时间需要 23 分钟。
以下链接是个人关于mmaction2(SlowFast-动作识别) 所有见解,如有错误欢迎大家指出,我会第一时间纠正。有兴趣的朋友可以加微信:a944284742相互讨论技术。若是帮助到了你什么,一定要记得点赞!因为这是对我最大的鼓励。 文 末 附 带 \color{blue}{文末附带} 文末附带 公 众 号 − \color{blue}{公众号 -} 公众号− 海 量 资 源 。 \color{blue}{ 海量资源}。 海量资源。
极 度 推 荐 的 商 业 级 项 目 : \color{red}{极度推荐的商业级项目:} 极度推荐的商业级项目:这是本人落地的行为分析项目,主要包含(1.行人检测,2.行人追踪,3.行为识别三大模块):
注 意 , 本 人 编 写 该 博 客 的 时 间 为 2020 / 07 / 28 , 也 就 是 说 , 你 现 在 下 载 的 作 者 代 码 或 许 和 \color{red}{注意,本人编写该博客的时间为2020/07/28,也就是说,你现在下载的作者代码或许和} 注意,本人编写该博客的时间为2020/07/28,也就是说,你现在下载的作者代码或许和
本 人 的 代 码 不 一 样 ( 如 果 作 者 有 更 新 过 ) 还 有 就 是 , 本 人 调 试 该 代 码 为 u b u n t u 18.04 系 统 \color{red}{本人的代码不一样(如果作者有更新过)还有就是,本人调试该代码为ubuntu18.04系统} 本人的代码不一样(如果作者有更新过)还有就是,本人调试该代码为ubuntu18.04系统 即 下 面 的 报 错 使 用 u b u n t u 18.04 报 错 的 过 程 , 以 及 解 决 办 法 \color{red}{即下面的报错使用ubuntu18.04报错的过程,以及解决办法} 即下面的报错使用ubuntu18.04报错的过程,以及解决办法# $MMACTION2表示项目(从githubu下载)的根目录cd $MMACTION2conda create -n mmaction2-pytorch1.5-py3.6 -y python=3.6conda activate mmaction2-pytorch1.5-py3.6pip install torch==1.5.0+cu101 torchvision==0.6.0+cu101 -f https://download.pytorch.org/whl/torch_stable.htmlpip install -r requirements/build.txtpython setup.py developpip install decord -i https://pypi.douban.com/simple
上一篇博客已经给出数据的下载链接,并且告示了需要的内容,下载下来之后本人摆放如下(没有的目录请自行创建):
本人的数据制作流程主要参考如下链接(有兴趣的朋友可以自行探索):
执行如下指令# $MMACTION2表示项目的根目录cd $MMACTION2# 创建软连接。注意/work/2.ChiPeak/5.OpenMMLab/1.mmaction2/Dataset需要替换成你本人Dataset路径ln -s /work/2.ChiPeak/5.OpenMMLab/1.mmaction2/Dataset datacd tools/data/python build_rawframes.py ../../data/ucf101/videos/ ../../data/ucf101/rawframes/ --task rgb --level 2 --ext avi --use-opencv --new-short 0 --new-width 320 --new-height 240cd ucf101bash generate_rawframes_filelist.shbash generate_videos_filelist.sh
执行完成之后,本人的目录分布如下:
首先执行如下指令,在项目的根目录$MMACTION2:
cp configs/recognition/slowfast/slowfast_r50_4x16x1_256e_kinetics400_rgb.py configs/recognition/slowfast/my_slowfast_r50_4x16x1_256e_ucf101_rgb.py
然后修改configs/recognition/slowfast/my_slowfast_r50_4x16x1_256e_ucf101_rgb.py文件如下(灰色字体表示本人注释的源码):
test_cfg = dict(average_clips=None)#dataset_type = 'RawframeDataset'#data_root = 'data/kinetics400/rawframes_train'#data_root_val = 'data/kinetics400/rawframes_val'#ann_file_train = 'data/kinetics400/kinetics400_train_list_rawframes.txt'#ann_file_val = 'data/kinetics400/kinetics400_val_list_rawframes.txt'#ann_file_test = 'data/kinetics400/kinetics400_val_list_rawframes.txt'dataset_type = 'RawframeDataset'data_root = 'data/ucf101/rawframes'data_root_val = 'data/ucf101/rawframes'ann_file_train = 'data/ucf101/ucf101_train_split_1_rawframes.txt'ann_file_val = 'data/ucf101/ucf101_val_split_1_rawframes.txt'ann_file_test = 'data/ucf101/ucf101_val_split_1_rawframes.txt'
然后执行
python tools/train.py configs/recognition/slowfast/my_slowfast_r50_4x16x1_256e_ucf101_rgb.py --work-dir work_dirs/my_slowfast_r50_4x16x1_256e_ucf101_rgb --validate --seed 0 --deterministic
报错一:
File "/my_app/anaconda3/envs/test/lib/python3.6/site-packages/mmcv-1.0.4-py3.6-linux-x86_64.egg/mmcv/runner/base_runner.py", line 339, in register_lr_hook hook = mmcv.build_from_cfg(lr_config, HOOKS) File "/my_app/anaconda3/envs/test/lib/python3.6/site-packages/mmcv-1.0.4-py3.6-linux-x86_64.egg/mmcv/utils/registry.py", line 157, in build_from_cfg f'{obj_type} is not in the {registry.name} registry')KeyError: 'CosineAnealingLrUpdaterHook is not in the hook registry'
修改configs/recognition/slowfast/my_slowfast_r50_4x16x1_256e_ucf101_rgb.py如下:
#lr_config = dict(policy='CosineAnealing', min_lr=0)lr_config = dict(policy='step', step=[40,60])
本人对于这里表示很奇怪,为什么不能使用CosineAnealing,暂且不去理会,我们后续慢慢去分析。
报错二:File "/work/2.ChiPeak/5.OpenMMLab/1.mmaction2/1.mmaction2/1.mmaction2-init-master/mmaction/models/backbones/resnet3d.py", line 279, in _inner_forward out = out + identityRuntimeError: CUDA out of memory. Tried to allocate 26.00 MiB (GPU 0; 5.81 GiB total capacity; 4.99 GiB already allocated; 6.62 MiB free; 5.06 GiB reserved in total by PyTorch)(test) root@ebe12713b2cb:/work/2.ChiPeak/5.OpenMMLab/1.mmaction2/1.mmaction2/1.mmaction2-init-master#
这里是显存不够了,修改configs/recognition/slowfast/my_slowfast_r50_4x16x1_256e_ucf101_rgb.py如下:
train_pipeline = [ #dict(type='SampleFrames', clip_len=32, frame_interval=2, num_clips=1), dict(type='SampleFrames', clip_len=16, frame_interval=2, num_clips=1),#checkpoint_config = dict(interval=4)checkpoint_config = dict(interval=1) #num_classes=400, num_classes=101,
这里表示每次次采样16帧,这样占用的显存就比较小了。设置interval=1,是为了在训练个 epoch 之后保存一次模型,方便后续的模型测试
正常运行
再次执行:python tools/train.py configs/recognition/slowfast/my_slowfast_r50_4x16x1_256e_ucf101_rgb.py --work-dir work_dirs/my_slowfast_r50_4x16x1_256e_ucf101_rgb --validate --seed 0 --deterministic
本人显示如下:
修改my_slowfast_r50_4x16x1_256e_ucf101_rgb.py文件如下:
test_cfg = dict(average_clips=None)#dataset_type = 'RawframeDataset'#data_root = 'data/kinetics400/rawframes_train'#data_root_val = 'data/kinetics400/rawframes_val'#ann_file_train = 'data/kinetics400/kinetics400_train_list_rawframes.txt'#ann_file_val = 'data/kinetics400/kinetics400_val_list_rawframes.txt'#ann_file_test = 'data/kinetics400/kinetics400_val_list_rawframes.txt'dataset_type = 'VideoDataset'data_root = 'data/ucf101/videos'data_root_val = 'data/ucf101/videos'ann_file_train = 'data/ucf101/ucf101_train_split_1_videos.txt'ann_file_val = 'data/ucf101/ucf101_val_split_1_videos.txt'ann_file_test = 'data/ucf101/ucf101_val_split_1_videos.txt'train_pipeline = [ dict(type='DecordInit'), #dict(type='SampleFrames', clip_len=32, frame_interval=2, num_clips=1), dict(type='SampleFrames', clip_len=16, frame_interval=2, num_clips=1), #dict(type='FrameSelector'), dict(type='DecordDecode'), dict(type='Resize', scale=(-1, 256)),val_pipeline = [ dict(type='DecordInit'), #dict(type='SampleFrames',clip_len=32,frame_interval=2,num_clips=1,test_mode=True), dict(type='SampleFrames', clip_len=16, frame_interval=2, num_clips=1, test_mode=True), #dict(type='FrameSelector'), dict(type='DecordDecode'), dict(type='Resize', scale=(-1, 256)), test_pipeline = [ dict(type='DecordInit'), #dict(type='SampleFrames',clip_len=32,frame_interval=2,num_clips=1,test_mode=True), dict(type='SampleFrames', clip_len=16, frame_interval=2, num_clips=1, test_mode=True), #dict(type='FrameSelector'), dict(type='DecordDecode'), dict(type='Resize', scale=(-1, 256)),
同样还是执行(本人感觉直接加载视频,比加载切割之后视频帧训练速度更快):
python tools/train.py configs/recognition/slowfast/my_slowfast_r50_4x16x1_256e_ucf101_rgb.py --work-dir work_dirs/my_slowfast_r50_4x16x1_256e_ucf101_rgb --validate --seed 0 --deterministic
执行指令:
python tools/test.py configs/recognition/slowfast/my_slowfast_r50_4x16x1_256e_ucf101_rgb.py work_dirs/my_slowfast_r50_4x16x1_256e_ucf101_rgb/epoch_1.pth --eval top_k_accuracy mean_class_accuracy --out result.json --average-clips=prob
本人显示如下:
后续我会对mmaction2架构进行讲解,SlowFast论文翻译以及SlowFast网络结构解析。下篇博客见,老铁!
转载地址:http://xvigz.baihongyu.com/