PaddlePaddle 中的时序偏移模块推理#
此演示展示了如何在 PaddlePaddle 中使用 DALI 管道进行视频分类。
此演示使用的模型是 TSM: Temporal Shift Module for Efficient Video Understanding。
它在 kinetics400 上训练,权重将自动下载。
对于推理,视频应调整大小为 300p 并裁剪为 10 秒长度,这可以使用 ffpmeg
完成。
运行以下命令以下载和预处理来自 kinetics400 valset 的一些视频。
mkdir demo
youtube-dl --quiet --no-warnings -f mp4 -o demo/tmp.mp4 \
'https://www.youtube.com/watch?v=iU3ByohkPaM'
ffmpeg -y -i demo/tmp.mp4 -filter:v scale=-1:300 -ss 0 -t 10 -c:a copy demo/1.mp4
youtube-dl --quiet --no-warnings -f mp4 -o demo/tmp.mp4 \
'https://www.youtube.com/watch?v=C0J6EQYYLzI'
ffmpeg -y -i demo/tmp.mp4 -filter:v scale=-1:300 -ss 0 -t 10 -c:a copy demo/2.mp4
rm demo/tmp.mp4
该脚本将从输入视频中提取 8 帧,步长为 s
(默认为 30),并将为每个视频输出前 k
个预测标签(默认为 1 个)。
python infer.py -k 1 -s 30 demo
# will output
# prediction for demo/1.mp4 is: ['carving_pumpkin']
# prediction for demo/2.mp4 is: ['blowing_out_candles']
要求#
通过 pip 或其他方式安装以下 python 包。
PaddlePaddle (1.6 或更高版本)
可选地,准备输入视频需要以下程序。
用法#
usage: infer.py [-h] [--topk K] [--stride S] DIR
Paddle Temporal Shift Module Inference
positional arguments:
DIR Path to video files
optional arguments:
-h, --help show this help message and exit
--topk K, -k K Top k results (default: 1)
--stride S, -s S Distance between frames (default: 30)