当前位置:网站首页>百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (上)
百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (上)
2022-07-06 18:06:00 【訢詡】
一、介绍
BMN模型是百度自研,2019年ActivityNet夺冠方案,为视频动作定位问题中proposal的生成提供高效的解决方案。
简单说,视频的时序动作定位就是给一段视频,分析出从xxx秒到xxx秒是一个什么动作,相比动作识别需要推断这个动作的起始时间和终止时间,指标主要涉及两个:(1)分类准确率(2)与GT的IoU。
项目地址:
算法主要分为三个阶段:
(1)视频理解
PP-TSM,音频特征:VGGish
(2)时序提名
BMN
(3)动作分类与定位
AttentionLSTM
每个阶段都包含了数据准备、训练、验证和导出推理模型等环节。
准备环境主要是依赖requirements.txt里面的内容安装,基本没什么问题,paddlepaddle-gpu的话最好安装最新版。
二、PP-TSM
数据集使用的是FootballAction飞桨开源的足球动作数据集
数据集由EuroCup2012, EuroCup2016, WorldCup2014, WorldCup2018四个赛事的比赛视频组成,共计272个训练集、25个测试集,支持15种足球精彩动作定位与识别,动作类别分别为:射门、进球、进球有欢呼、角球、任意球、黄牌、红牌、点球、换人、界外球、球门球、开球、越位挥旗、回放空中对抗和回放进球。
在项目中飞桨并未全部开源全部数据,总共是开源了49个数据集。
(1)下载数据集
使用bash文件下载,下载脚本文件位置在PaddleVideo-develop/applications/FootballAction/datasets/EuroCup2016/download_dataset.sh,给该文件执行权限后直接运行即可,下载完成后会在PaddleVideo-develop/applications/FootballAction/datasets/EuroCup2016/mp4这个文件夹下面存放49个MP4视频,合计78.1GB大小。标注数据直接在项目文件里面给出:
datasets/EuroCup2016/label.json 为分类的标签列表
datasets/EuroCup2016/label_cls8_train.json 为训练数据标签
datasets/EuroCup2016/label_cls8_train.json 为验证数据标签
datasets/EuroCup2016/url.list 为训练数据文件列表
datasets/EuroCup2016/url_val.list 为验证数据文件列表
(2)准备数据
在第一阶段需要准备PP-TSM的训练数据,使用如下命令:
在此之前需要有ffmpeg环境,sudo apt install ffmpeg
cd PaddleVideo-develop/applications/FootballAction/datasets/script
python get_frames_pcm.py
这个步骤是将原始的视频文件做采样处理,图像采样是以每秒5帧的频率,音频采样是按照16000的频率。需要处理很久,处理完成后会生成两个新的文件夹:
|-- datasets # 训练数据集和处理脚本
|-- EuroCup2016 # 数据集
|-- mp4 # 原始视频.mp4
|-- frames # 图像帧(新的)
|-- pcm # 音频pcm(新的)
|-- url.list # 视频列表
|-- label.json # 视频原始gts
(3)处理采样
将上述采样数据处理为PP-TSM的训练数据集
cd PaddleVideo-develop/applications/FootballAction/datasets/script
python get_instance_for_pptsm.py
这个步骤是根据标注把运动区间作为正样本,区间内所有帧生成一个pkl文件,非运动区间作为负样本,随机抽取N个区间生成N个pkl文件
完成该步骤后:
|-- datasets # 训练数据集和处理脚本
|-- EuroCup2016 # 数据集
|-- input_for_pptsm # pptsm训练的数据(新的)
(4)训练PP-TSM
首先需要下载一个预训练权重:
cd PaddleVideo-develop/applications/FootballAction
wget https://videotag.bj.bcebos.com/PaddleVideo/PretrainModel/ResNet50_vd_ssld_v2_pretrained.pdparams
mkdir pretrain
mv ResNet50_vd_ssld_v2_pretrained.pdparams pretrain/ResNet50_vd_ssld_v2_pretrained.pdparams
打开训练配置文件:
PaddleVideo-develop/applications/FootballAction/train_proposal/configs/pptsm_football_v2.0.yaml
第5行:写入刚才下载的预训练模型位置,注意要写绝对路径
第17,18行:batchsize大小,我是2080Ti-8G,只能写4/4
第19行:改为1
第23行:找到PaddleVideo-develop/applications/FootballAction/datasets/EuroCup2016/input_for_pptsm/train.list这个文件,然后写他的绝对路径
第28行:找到PaddleVideo-develop/applications/FootballAction/datasets/EuroCup2016/input_for_pptsm/val.list,然后写他的绝对路径,这个其实就是刚才在(3)那个步骤里面生成出来的索引文件
第33行:和28行一样,写一样的东西就可以
单卡的话使用如下命令开始训练:
python -B -m paddle.distributed.launch --gpus="0" --log_dir=./football/logs_pptsm main.py --validate -c applications/FootballAction/train_proposal/configs/pptsm_football_v2.0.yaml -o output_dir=./football/pptsm
大概需要3天3夜训练完成,下面修改代码为推理模式:
在转为预测模式前,需要修改
PaddleVideo/paddlevideo/modeling/framework/recognizers/recognizer2d.py
文件,将 init 和 infer_step 函数分别更新为如下代码:
def __init__(self, backbone=None, head=None):
super().__init__(backbone=backbone, head=head)
self.avgpool2d = paddle.nn.AdaptiveAvgPool2D((1, 1), data_format='NCHW')
def infer_step(self, data_batch):
"""Define how the model is going to test, from input to output."""
imgs = data_batch[0]
imgs = paddle.reshape_(imgs, [-1] + list(imgs.shape[2:]))
feature = self.backbone(imgs)
feat = self.avgpool2d(feature)
return feat
在PaddleVideo根目录执行
python tools/export_model.py -c applications/FootballAction/train_proposal/configs/pptsm_football_v2.0.yaml \
-p ./football/pptsm/ppTSM_best.pdparams \
-o ./football/inference_model
即可导出推理模型
(5)配置PP-TSM
将
PaddleVideo/applications/FootballAction/predict/action_detect/models/pptsm_infer.py
文件中41行的
self.output_tensor = self.predictor.get_output_handle(output_names[1])
替换为
self.output_tensor = self.predictor.get_output_handle(output_names[0])
进行图像和音频的特征提取,因为我们是用自己刚训练的权重进行特征提取,所以要修改配置文件:
在PaddleVideo-develop/applications/FootballAction/extractor/configs/configs.yaml这个文件里面,
第4行把index_label_football_8.json的路径配置为PaddleVideo-develop/applications/FootballAction/extractor/configs/index_label_football_8.json的绝对路径
第13行把默认的权重路劲改为PaddleVideo-develop/football/inference_model/ppTSM.pdmodel的绝对路径
第14行把默认参数文件改为PaddleVideo-develop/football/inference_model/ppTSM.pdiparams的绝对路径
第29行的音频模型权重路径改为PaddleVideo-develop/applications/FootballAction/checkpoints/AUDIO/__model__的绝对路径
第30行的音频模型参数文件路径改为PaddleVideo-develop/applications/FootballAction/checkpoints/AUDIO/__param__的绝对路径
第38行BMN模型的权重路径改为PaddleVideo-develop/applications/FootballAction/checkpoints/BMN/__model__的绝对路径
第39行BMN模型的参数文件路径改为PaddleVideo-develop/applications/FootballAction/checkpoints/BMN/__param__的绝对路径
第51行的LSTM模型权重路径改为PaddleVideo-develop/applications/FootballAction/checkpoints/LSTM/__model__的绝对路径
第52行的LSTM模型参数文件路径改为PaddleVideo-develop/applications/FootballAction/checkpoints/LSTM/__param__的绝对路径
再打开PaddleVideo-develop/applications/FootballAction/extractor/extract_feat.py
第83行路径改为EuroCup2016文件夹的路径:PaddleVideo-develop/applications/FootballAction/datasets/EuroCup2016
上述配置完成之后,进入到PaddleVideo-develop/applications/FootballAction目录下面运行
python extract_feat.py
完成该步骤后,数据存储位置
|-- datasets # 训练数据集和处理脚本
|-- EuroCup2016 # 数据集
|-- features # 视频的图像+音频特征
下一步用处理好的features训练BMN
边栏推荐
- 数据手册中的词汇
- 今日问题-2022/7/4 lambda体中修改String引用类型变量
- Today's question -2022/7/4 modify string reference type variables in lambda body
- Appium foundation - appium inspector positioning tool (I)
- 7.6模拟赛总结
- 736. Lisp 语法解析 : DFS 模拟题
- Docker method to install MySQL
- Gnet: notes on the use of a lightweight and high-performance go network framework
- Gazebo的安装&与ROS的连接
- 编译命令行终端 swift
猜你喜欢
dvajs的基础介绍及使用
1123. 最深叶节点的最近公共祖先
C language - array
Appium基础 — Appium Inspector定位工具(一)
Gin 入门实战
Clickhouse fields are grouped and aggregated, and SQL is queried according to the granularity of any time period
AI automatically generates annotation documents from code
Make Jar, Not War
Let's see how to realize BP neural network in Matlab toolbox
黑马笔记---创建不可变集合与Stream流
随机推荐
[JS] obtain the N days before and after the current time or the n months before and after the current time (hour, minute, second, year, month, day)
2022 Google CTF SEGFAULT LABYRINTH wp
Make Jar, Not War
Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform
Case development of landlord fighting game
Dark horse notes - exception handling
Sword finger offer II 035 Minimum time difference - quick sort plus data conversion
Gnet: notes on the use of a lightweight and high-performance go network framework
Taro2.* 小程序配置分享微信朋友圈
免费白嫖的图床对比
黑马笔记---创建不可变集合与Stream流
增加 pdf 标题浮窗
THREE. AxesHelper is not a constructor
Meet in the middle
云呐|工单管理办法,如何开展工单管理
Comparison of picture beds of free white whoring
mysqlbackup 还原特定的表
The difference between Tansig and logsig. Why does BP like to use Tansig
MySQL script batch queries all tables containing specified field types in the database
docker 方法安装mysql