一、检查缺少的文件:
windows下的caffe缺少了以下文件:
在include/caffe/layers文件中缺少:
lstm_layer.hpp
parameter_layer.hpp
recurrent_layer.hpp
rnn_layer.hpp
在src/caffe/layers文件中缺少:
lstm_layer.cpp
lstm_unit_layer.cpp
parameter_layer.cpp
recurrent_layer.cpp
rnn_layer.cpp
对应的文件可点击链接下载,然后把这些文件全部都拷贝到caffe-windows的对应位置;
二、添加层
在vs2013中打开caffe文件夹中windows下的caffe.sln打开项目
1、 添加parameter_layer层
作用:add parameter layer for learning any bottom
(1)先添加头文件libcaffe->include->layers->添加->现有项
将include/caffe/layers中parameter_layer.hpp选中
(2)先添加头文件libcaffe->src->layers->添加->现有项
(3)右键parameter_layer.cpp,编译一下:
编译成功!
(4)对libcaffe重新生成一次,可能需要几分钟
2、添加LSTM层
(1)添加头文件lstm_layer.hpp、recurrent_layer.hpp、rnn_layer.hpp到libcaffe->include->layers->添加->现有项
(2)添加源文件lstm_layer.cpp、lstm_unit_layer.cpp、recurrent_layer.cpp、rnn_layer.cpp到libcaffe->src->layers->添加->现有项
(3)编译一下新添加的.cpp文件
发现lstm_unit_layer.cpp无需添加到caffe.proto中便可直接编译成功,但是其使用方法还有待斟酌,因为没有添加到caffe.proto中。其它的层都无法直接编译成功,那么就得添加到caffe.proto中了。
(4)添加到caffe.proto
在caffe.proto的387行添加对应recurrent层的ID(因为它是由LSTM和RNN层组成的,因而给一个ID即可,在参数中进行区分)
optional RecurrentParameter recurrent_param = 146;
添加对应参数描述:
// Message that stores parameters used by RecurrentLayer
message RecurrentParameter {
// The dimension of the output (and usually hidden state) representation --
// must be explicitly set to non-zero.
optional uint32 num_output = 1 [default = 0];
optional FillerParameter weight_filler = 2; // The filler for the weight
optional FillerParameter bias_filler = 3; // The filler for the bias
// Whether to enable displaying debug_info in the unrolled recurrent net.
optional bool debug_info = 4 [default = false];
// Whether to add as additional inputs (bottoms) the initial hidden state
// blobs, and add as additional outputs (tops) the final timestep hidden state
// blobs. The number of additional bottom/top blobs required depends on the
// recurrent architecture -- e.g., 1 for RNNs, 2 for LSTMs.
optional bool expose_hidden = 5 [default = false];
}
(5)添加完毕ID和参数描述,不要忽略了对libcaffe重新生成一次,然后尝试对lstm_layer.cpp、recurrent_layer.cpp、rnn_layer.cpp重新编译试试。
显示成功即完成添加!
参考:https://blog.csdn.net/zb1165048017/article/details/59112034