caffe-windows中添加normalize_layer

问题:
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工程,即可。
在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值