C3D Introduction
卷积神经网络(CNN)近年被广泛应用于计算机视觉中,包括分类、检测、分割等任务。这些任务一般都是针对图像进行的,使用的是二维卷积(即卷积核的维度为二维)。而对于基于视频分析的问题,2D convolution不能很好得捕获时序上的信息。因此3D convolution就被提出来了。
简而言之,C3D适合学习时序特征。
C3D Installation
C3D User Guide
Du Tran (Last modified Mar 20, 2017) C3D-v1.1 is released with new models (Mar 01, 2017). No documentation for v1.1 yet, but some examples for feature extraction, training, and fine-tuning are provided.
文档介绍了C3D 1.0的用法,至于1.1,只有examples。
I.C3D Feature Extration
-
安装好C3D,下载预训练的模型,保存到
YOUR_PATH_TO_C3D/C3D-master/C3D-v1.0/examples/c3d_feature_extraction
-
change dir to
YOUR_PATH_TO_C3D/C3D-master/C3D-v1.0/examples/c3d_feature_extraction
-
Run:
sh c3d_sport1m_feature_extraction_frm.sh or sh c3d_sport1m_feature_extraction_video.sh
运行成功将在output文件夹找到特征文件。
遇到“out of memeory”内存不足的错误,调整min_batch_size参数。参见章节 I.B。
如能使用图片输入,不能使用视频输入。请确保编译OpenCV和Ffmpeg时”shared-flags”为”on”。
I.A Extract C3D features for your own videos or frames
a.准备输入文件
输入为视频或视频帧
对于视频文件,由于使用opencv获得帧,帧数从0开始。
对于视频帧,命名为“video_folder/%06d.jpg”,帧数从1开始。一个文件夹最多999999个帧,如果视频超出999999帧,需要分成多个文件夹。
b.准备配置文件
两个设置选项:输入列表(input_list) 和 输出前缀(output_prefix)
在example中,输入列表的配置文件为: “prototxt/input_list_video.txt”和”prototxt/input_list_frm.txt”。
input_list文件需要制定输入的列表,格式为每行制定一个输入。每行的格式为
<string_path> <starting_frame> <label>
“string_path”: 为路径,对视频,为视频路径和文件名;对frames,是包含视频截图的目录路径。
“starting_frame”: C3D能从长为16帧的视频中提取特征。一个视频包含了大量的帧,我们需要指定C3D从哪一帧开始提取特征。
“label”: 这个仅对训练、测试、调优起作用,提取特征的时候会被忽略,设置为0。
output_prefix文件要为每一个输入指定一个输出前缀。即行数与input_list一致。每行的格式为:<output_prefix>
C3D将特征输出到 output_prefix.[feature_name]文件(例如prefix.fc6)。为了与输入对应,输出建议采用如下格式`sprintf(“output_folder/%06d”, starting_frame)。
c.提取特征
在prototxt中,通过后缀名为.prototxt的文档来指向你的输入列表文件。
主要修改这两行:
source: “prototxt/input_list_video.txt” use_image: false shuffle: false
source 修改为输入列表文件
如果使用图像文件,use_image修改为true。
提取特征时确保”shuffle”为false。
(.prototxt文件第一行是name,接下来是若干个layer,layer用json表示,我们只需要修改第一个输入layer。)
接下来使用”extract_image_features”工具来提取特征。
该工具使用的参数如下
extract_image_features.bin <feature_extractor_prototxt_file> <c3d_pre_trained_model> <gpu_id> <mini_batch_size> <number_of_mini_batches> <output_prefix_file> <feature_name1> <feature_name2> ...
-
feature_extractor_prototxt_file:
.prototxt文件,指向input_list_file
-
c3d_pre_trained_model:
下载的C3D预训练模型
-
gpu_id:
GPU ID,从0开始。设为-1则使用CPU
-
mini_batch_size:
批处理大小。默认值为50。根据GPU的性能修改。
-
number_of_mini_batches
批处理数量。
如果有100个clips,<mini_batch_size>设置为50,则<number_of_mini_batches>为2。
如果有101个clips,<mini_batch_size>设置为50,则<number_of_mini_batches>为3。
(就是ceil除法嘛)
-
output_prefix_file:
输出前缀文件
-
feature_name1:
特征名。(参见.prototxt文件的layers, 如 fc6-1, fc7-1, fc8-1, pool5, conv5b, prob,…)
example中的命令行如下:
GLOG_logtosterr=1 ../../build/tools/extract_image_features.bin prototxt/c3d_sport1m_feature_extractor_frm.prototxt conv3d_deepnetA_sport1m_iter_1900000 0 50 1 prototxt/output_list_prefix.txt fc7-1 fc6-1 prob