C3D USER GUIDE(Du Tran博士,为C3D-v1.0编写的)

1.C3D特征提取

如果已成功安装C3D(安装caffe及其依赖项),请执行以下步骤:

下载预先训练的模型并将其保存到YOUR_C3D_HOME / examples / c3d_feature_extraction

将目录更改为YOUR_C3D_HOME / examples / c3d_feature_extraction

运行:sh c3d_sport1m_feature_extraction_frm.sh

或sh c3d_sport1m_feature_extraction_video.sh

如果可以成功运行示例,则应在输出文件夹中找到提取的功能。

如果您遇到“内存不足”错误,那么您应该考虑减少批量大小

如果您可以成功地使用帧运行特征提取,但视频输入失败。原因可能来自视频编解码器。确保已编译OpenCV和Ffmpeg并打开了共享标志。

使用C3D作为特征提取器时,请确保数据层中的“shuffle:false”。这有助于我们保持输入剪辑和输出功能之间的对应关系。

(1)为自己的视频或帧提取C3D功能

a.准备输入文件

C3D允许您将视频输入用作帧序列或视频文件。对于视频文件(.mp4,.avi,.mov),请确保您的计算机正确安装了编解码器,opencv和ffmpeg。在使用帧的情况下,C3D假设每个视频是具有从1到N(帧数)开始编号的帧的文件夹。帧名称格式为“video_folder /%06d.jpg”。

注意:从1开始的帧号(例如1..N)用于使用帧作为输入,并且从0开始(例如[0..N-1])以使用视频作为输入。

b.准备设置文件

需要准备两个设置文件:input-list和output prefix。在提供的示例中,它们是:在YOUR_C3D_HOME / examples / c3d_feature_extraction / prototxt中的input_list_frm.txt,input_list_video.txt和output_list_prefix.txt

输入列表文件是一个文本文件,其中每行包含要输入C3D以提取特征的剪辑的信息。每行具有以下格式:

<string_path> <starting_frame> <label>

其中仅用于训练,测试或微调,但不用于提取特征,因此可以忽略(在提供的示例中,它们用0填充)。因为,我们有两个案例。

对于具有视频文件输入的设置,是视频的完整路径和文件名(例如,input/ avi / v_ApplyEyeMakeup_g01_c01.avi)。

对于带帧输入的设置,是包含视频帧的文件夹的完整路径(例如,input / frm / v_ApplyEyeMakeup_g01_c01 /)。

最后,用于指定剪辑的起始帧。

C3D每16帧/s速度提取一次,从1开始就是(1,16),从17开始就是(17,32) 。你也可以不使用16帧的提取步长使用你的自定义步长比如32帧/s。

output prefix file用于指定用于提取要保存的要素的位置。

output prefix file的每行对应于 input list file中的每行

C3D以output_prefix.[feature_name] (e.g. prefix.fc6)的形式保存特征,建议为每个视频创建一个输出文件夹,prefix lines格式为sprintf(“output_folder /%06d”,starting_frame)。这意味着每个剪辑都有起始帧,标识符和文件扩展名用于不同的功能。 记住创建输出文件夹,因为C3D不会创建它们。

c.提取C3D特征

假设已准备好设置文件,则需要修改prototxt文件以指向输入列表文件。 在prototxt文件中,寻找:

source: “prototxt/input_list_frm.txt”

使用图片作为输入:设置 use_image: truer

使用视频作为输入:设置 use_image: false

使用extract_image_features工具提取特征,此工具集使用的参数如下:

extract_image_features.bin …

+: is prototxt file (provided in example) which points to your input list file.

+: is the C3D pre-trained model that you downloaded.

+: GPU ID you would like to run (starting from 0), if this is set to -1, then it will use CPU.

+: your mini batch size. Default is 50, but you can modify this number, depend on your GPU memory.

+: Number of mini-batches you want to extract features. For examples, if you have 100 clips to extract features and you are using mini-batch size of 50, then this parameter should be set to 2. However, if you have 101 clips to be extracted features, then this number should be set to 3.

+: Your output prefix file.

+: You can list as many feature names as possible as long as they are in the names of the output blobs of the network (see prototxt file for all layers, but they look like fc6-1, fc7-1, fc8-1, pool5, conv5b, prob,…).

你可以在下面的示例中找到以下命令行:

     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

d.使用更小或更大batch-size提取C3D特征

根据需要在Prototxt中改变参数:batch_size: 50

并且还需要在命令行中输入和的新调整参数。

提取C3D特征后,可以使用提供的MATLAB脚本(read_binary_blob.m)来读取特征进行进一步分析。

 2.训练3D CNN

(1)计算均值文件

该工具允许你为自己的数据集计算均值,这可以对C3D在你自己的数据集上的零碎训练或微调有用。

用法:

GLOG_logtostderr=1 compute_volume_mean_from_list input_chunk_list length height width sampling_rate output_file [dropping rate]

参数:

input_chunk_list:与特征提取中使用的列表文件相同

Length:训练中使用的剪辑的长度(例如16)

Height,width:框架的尺寸,例如128,171

sampling_rate:用于调整剪辑中的帧速率(例如剪辑长度= 16,采样= 1,然后剪辑是16个连续的帧视频块。或者如果剪辑长度= 16,采样率= 2,则你剪辑是32帧长剪辑,但你每2帧抽样1)

output_file:输出均值文件。

dropping_rate:如果数据集太大(例如1M),您可能希望从剪辑的子集计算均值。将此值设置为n,表示丢弃率为1:n,在每n个剪辑中选择1个样本进行计算均值。

如果你喜欢使用mean_value,而不是volume_mean文件,那么你可以在数据层中设置mean_value。这相当于 volume mean ,所有值都设置为mean_value。

(2)从头开始训练自己的网络

假设你有你的input_data_list,你的train / test prototxt和你的solver prototxt,你可以用train_net来训练网络

(3)在UCF101上从零开始的一个例子

将目录更改为YOUR_C3D_HOME / examples / c3d_train_ucf101 /

运行sh create_volume_mean.sh来计算均值文件

运行sh train_ucf101.sh来训练,期待几天完成

运行sh test_ucf101.sh进行测试,期望大约15'完成,你应该有~45%的准确度(这是剪辑精度)

3.微调C3D

假设您已经下载了C3D预训练模型。您可以通过以下方式尝试微调示例:

将目录更改为YOUR_C3D_HOME / examples / c3d_finetuning

运行:sh ucf101_finetuning.sh

完成微调后,您可以通过运行以下命令测试您的微调模型:sh ucf101_testing.sh

[新增05/10/2016]如果没有时间在UCF101上自行微调C3D,在这里提供在UCF101上微调的C3D模型:https://www.dropbox.com/s/mkc9q7g4wnqnmcv / c3d_ucf101_finetune_whole_iter_20000只需将此模型下载到YOUR_C3D_HOME / examples / c3d_finetuning并运行sh ucf101_testing.sh(假设您确保test_01.lst文件指向您的UCF101帧)。这将提供80.19%的准确度(剪辑精度)。注意:此型号在UCF101“train split 1”上进行了微调,因此仅对“test split 1”进行测试有效。

 4.常见问题解答

可以在CPU上使用C3D吗?

此版本的C3D构建在旧的caffe分支上,因此没有“CPU_ONLY”模式

Makefile文件。但你可以通过以下方式做到这一点:

正常编译C3D(它需要CUDA驱动程序才能编译,但如果你没有GPU,你仍然可以在CPU上运行)。要训练使用CPU,您可以将求解器文件修改为solver_mode:CPU

(https://github.com/facebook/C3D/blob/master/examples/c3d_train_ucf101/conv3d_ucf101_solver.prototxt#L19)

要使用CPU进行测试,请在命令行中使用CPU而不是GPU(https://github.com/facebook/C3D/blob/master/examples/c3d_train_ucf101/test_ucf101.sh),不需要GPU_ID。

要使用CPU提取功能,请使用GPU_ID = -1,而不是像此处的示例中那样使用0(https://github.com/facebook/C3D/blob/master/examples/c3d_feature_extraction/c3d_sport1m_feature_extraction_frm.sh)

 

 

猜你喜欢

转载自blog.csdn.net/weixin_41991401/article/details/81672943