新版的caffe和旧版caffe稍微有些不同,旧版caffe需要改/src/caffe/layer_factory.cpp,新版则不需要。可参考
首先,修改caffe.proto
在caffe.proto文件中的message LayerParameter { } 中添加:
optional MylayerParameter mylayer_param = ID2;
下面以添加3D卷积层为例:optional Convolution3DParameter convolution3d_param = 149;
卷积层要定义自己的参数,要添加L:
message Convolution3DParameter {
optional uint32 num_output = 1; // The number of outputs for the layer
optional bool bias_term = 2 [default = true]; // whether to have bias terms
optional uint32 pad = 3 [default = 0]; // The padding size
optional uint32 kernel_size = 4; // The kernel size
optional uint32 group = 5 [default = 1]; // The group size for group conv
optional uint32 kernel_depth = 6; // The kernel size
optional uint32 stride = 7 [default = 1]; // The stride
optional uint32 temporal_stride = 8 [default = 1]; // The stride for temporal
optional FillerParameter weight_filler = 9; // The filler for the weight
optional FillerParameter bias_filler = 10; // The filler for the bias
optional uint32 filter_group = 11 [default = 1]; // divide filters into groups to reduce memory consumption
optional uint32 temporal_pad = 12 [default = 0]; // padding size for temporal
}
添加头文件和源文件
头文件和源文件直接从C3D获取,头文件放在/include/caffe/layers中,源文件放在/src/caffe/layers中,如果用到cuda要编写cu文件。
添加测试文件
在/src/caffe/test中添加测试文件,测试文件并不是必须添加的。
这些都完事后重新编译caffe。
主要参考这位同学.