Caffe层系列:Slice Layer

版权声明:未经博主允许,不得转载! https://blog.csdn.net/u011681952/article/details/86150930

Slice Layer 的作用是将bottom按照需要切分成多个tops,一般特点是:一个输入多个输出

首先我们先看一下 SliceParameter

message SliceParameter {
  // The axis along which to slice -- may be negative to index from the end
  // (e.g., -1 for the last axis).   //-1表示最后一个维度
  // By default, SliceLayer concatenates blobs along the "channels" axis (1).   //默认按通道切分
  optional int32 axis = 3 [default = 1];
  repeated uint32 slice_point = 2;

  // DEPRECATED: alias for "axis" -- does not support negative indexing. //该参数 已弃用
  optional uint32 slice_dim = 1 [default = 1];
}

slice layer 在prototxt里面的书写:

layer {
	  name: "slice"
	  type: "Slice"
	  bottom: "input"   #假设维度:N×5×H*W
	  top: "output1"    #N×1×H*W
	  top: "output2"    #N×2×H*W
	  top: "output3"    #N×1×H*W
	  top: "output4"    #N×1×H*W
	  slice_param {
	    axis: 1   #axis:切分的维度轴; 1:表示按通道切分,CNN网络常用
	    			#slice_point: 表示切分的位置,如当前:
	    slice_point: 1   #1:表示将input从通道1的位置切分,将通道1及之前的通道赋值给output1
	    slice_point: 3   #3:表示将input从通道3的位置切分,将通道3及上一个slice_point之间的通道赋值给output2
	    slice_point: 4   #4:表示将input从通道4的位置切分,将通道4及上一个slice_point之间的通道赋值给output3
						 #最后将通道4之后的通道赋值给output4
  }
}

值得注意的是,如果有slice_point,slice_point的个数一定要等于top的个数-1;有点类似刀切豆腐,同一维度切3刀,得4块豆腐;
axis表示要进行分解的维度;
slice_point的作用是将axis按照slic_point 进行分解;
slice_point没有设置的时候则对axis进行均匀分解;

举个例子:

layer {
	  name: "vec_weight"
	  type: "Slice"
	  bottom: "label"     #N×114×H*W
	  top: "vec_weight"
	  top: "heat_weight"
	  top: "vec_temp"
	  top: "heat_temp"
	  slice_param {
	    slice_point: 38
	    slice_point: 57
	    slice_point: 95
	    axis: 1
	  }
}

top输出:

  top: "vec_weight"   #N×38×H*W
  top: "heat_weight"  #N×19×H*W
  top: "vec_temp"     #N×38×H*W
  top: "heat_temp"    #N×19×H*W

猜你喜欢

转载自blog.csdn.net/u011681952/article/details/86150930