问题:
caffe模型测试代码中需要用到归一化操作:
1、Normalize_layer是caffe-windows中没有的;
2、InnerProduct_layer在caffe-windows中没有normalize这个参数。
解决办法:
修改对应层源代码,重新编译caffe,具体步骤如下:
1、原先已编译好的caffe工程,建议全部删除,重新下载caffe-windows并解压;
下载地址:https://github.com/BVLC/caffe/tree/windows
2、修改caffe-windows\src\caffe\proto中caffe.proto文件。
LayerParameter中添加【optional NormalizeParameter normalize_param = 147;】
// NOTE
// Update the next available ID when you add a new LayerParameter field.
//
// LayerParameter next available layer-specific ID: 147 (last added: recurrent_param)
message LayerParameter {
optional string name = 1; // the layer name
optional string type = 2; // the layer type
repeated string bottom = 3; // the name of each bottom blob
repeated string top = 4; // the name of each top blob
optional NormalizeParameter normalize_param = 147;
}
添加归一化层参数,代码如下:
message NormalizeParameter {
optional string normalize_type = 1 [default = "L2"];
optional bool fix_gradient = 2 [default = false];
optional bool bp_norm = 3 [default = false];
}
InnerProduct层中添加normalize参数【optional bool normalize = 7 [default = false];】,代码如下:
message InnerProductParameter {
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 FillerParameter weight_filler = 3; // The filler for the weight
optional FillerParameter bias_filler = 4; // The filler for the bias
optional int32 axis = 5 [default = 1];
optional bool transpose = 6 [default = false];
optional bool normalize = 7 [default = false];
}
3、在caffe-windows\src\caffe\layers中添加normalize_layer.cpp,normalize_layer.cu;在caffe-windows\include\caffe\layers中添加normalize_layer.hpp。
4、修改caffe-windows\src\caffe\layers中的inner_product_layer.cpp,inner_product_layer.cu;修改caffe-windows\include\caffe\layers中的inner_product_layer.hpp。
5、打开caffe工程,caffe.sln,在libcaffe中cu、include、src中添加normalize_layer.cu,normalize_layer.hpp,normalize_layer.cpp。
6、重新编译caffe工程,即可。