以下链接是个人关于mmaction2(SlowFast-动作识别) 所有见解,如有错误欢迎大家指出,我会第一时间纠正。有兴趣的朋友可以加微信:17575010159 相互讨论技术。若是帮助到了你什么,一定要记得点赞!因为这是对我最大的鼓励。
文末附带
\color{blue}{文末附带}
文末附带
公众号
−
\color{blue}{公众号 -}
公众号−
海量资源。
\color{blue}{ 海量资源}。
海量资源。
动作识别0-00:mmaction2(SlowFast)-目录-史上最新无死角讲解
极度推荐的商业级项目:
\color{red}{极度推荐的商业级项目:}
极度推荐的商业级项目:这是本人落地的行为分析项目,主要包含(1.行人检测,2.行人追踪,3.行为识别三大模块):行为分析(商用级别)00-目录-史上最新无死角讲解
注意,本人编写该博客的时间为
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报错的过程,以及解决办法
anconda环境搭建
cd $MMACTION2
conda create -n mmaction2-pytorch1.5-py3.6 -y python=3.6
conda activate mmaction2-pytorch1.5-py3.6
pip install torch==1.5.0+cu101 torchvision==0.6.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html
pip install -r requirements/build.txt
python setup.py develop
pip install decord -i https://pypi.douban.com/simple
数据摆放
上一篇博客已经给出数据的下载链接,并且告示了需要的内容,下载下来之后本人摆放如下(没有的目录请自行创建):
进入到第二个红箭头标识的Dataset/ucf101目录,请自行解压两个文件,获得目录如下:
重命名UCF-101为videos,重命名ucfTrainTestlist为annotations。本人显示如下:
数据制作
本人的数据制作流程主要参考如下链接(有兴趣的朋友可以自行探索):
https://github.com/open-mmlab/mmaction2/blob/master/docs/getting_started.md#training-setting
执行如下指令
cd $MMACTION2
ln -s /work/2.ChiPeak/5.OpenMMLab/1.mmaction2/Dataset data
cd 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 240
cd ucf101
bash generate_rawframes_filelist.sh
bash 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/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='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 + identity
RuntimeError: 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=16, frame_interval=2, num_clips=1),
checkpoint_config = dict(interval=1)
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
本人显示如下:
本人在训练一个epoch之后就停止了,然后进行后面的模型测试。
源视频数据进行训练:
修改my_slowfast_r50_4x16x1_256e_ucf101_rgb.py文件如下:
test_cfg = dict(average_clips=None)
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=16, frame_interval=2, num_clips=1),
dict(type='DecordDecode'),
dict(type='Resize', scale=(-1, 256)),
val_pipeline = [
dict(type='DecordInit'),
dict(type='SampleFrames', clip_len=16, frame_interval=2, num_clips=1, test_mode=True),
dict(type='DecordDecode'),
dict(type='Resize', scale=(-1, 256)),
test_pipeline = [
dict(type='DecordInit'),
dict(type='SampleFrames', clip_len=16, frame_interval=2, num_clips=1, test_mode=True),
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网络结构解析。下篇博客见,老铁!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)