1. 程式人生 > >Caffe Prototxt層系列:Convolution Layer

Caffe Prototxt層系列:Convolution Layer

Convolution Layer是CNN中最常見最重要的特徵提取層,形式多種多樣

首先我們先看一下 InnerProductParameter

message ConvolutionParameter {
	  optional uint32 num_output = 1; // The number of outputs for the layer  輸出特徵圖個數(常以特徵圖為單位)
	  optional bool bias_term = 2 [default = true]; // whether to have bias terms  是否使用bias項
	
	  // Pad, kernel size, and stride are all given as a single value for equal
	  // dimensions in all spatial dimensions, or once per spatial dimension.
	  repeated uint32 pad = 3; // The padding size; defaults to 0   填充大小(畫素為單位)
	  repeated uint32 kernel_size = 4; // The kernel size    卷積核大小 
	  repeated uint32 stride = 6; // The stride; defaults to 1   步幅大小
	  // Factor used to dilate the kernel, (implicitly) zero-filling the resulting
	  // holes. (Kernel dilation is sometimes referred to by its use in the
	  // algorithme à trous from Holschneider et al. 1987.)
	  repeated uint32 dilation = 18; // The dilation; defaults to 1       空洞大小  預設1(空洞卷積中常用,如某些語義分割網路)
	
	  // For 2D convolution only, the *_h and *_w versions may also be used to
	  // specify both spatial dimensions.
	  //2D卷積,當高寬不一致時,常常用下列引數
	  optional uint32 pad_h = 9 [default = 0]; // The padding height (2D only)  高度填充大小      
	  optional uint32 pad_w = 10 [default = 0]; // The padding width (2D only) 寬度填充大小
	  optional uint32 kernel_h = 11; // The kernel height (2D only)  卷積核高度
	  optional uint32 kernel_w = 12; // The kernel width (2D only)  卷積核寬度
	  optional uint32 stride_h = 13; // The stride height (2D only)  y軸步幅
	  optional uint32 stride_w = 14; // The stride width (2D only)  x軸步幅
	
	  optional uint32 group = 5 [default = 1]; // The group size for group conv   組卷積 預設1    例項見shufflenet
	
	  optional FillerParameter weight_filler = 7; // The filler for the weight      卷積權重引數
	  optional FillerParameter bias_filler = 8; // The filler for the bias   偏置項引數
	  enum Engine {
	    DEFAULT = 0;
	    CAFFE = 1;
	    CUDNN = 2;
	  }
	  optional Engine engine = 15 [default = DEFAULT];
	
	  // The axis to interpret as "channels" when performing convolution.
	  // Preceding dimensions are treated as independent inputs;
	  // succeeding dimensions are treated as "spatial".
	  // With (N, C, H, W) inputs, and axis == 1 (the default), we perform
	  // N independent 2D convolutions, sliding C-channel (or (C/g)-channels, for
	  // groups g>1) filters across the spatial axes (H, W) of the input.
	  // With (N, C, D, H, W) inputs, and axis == 1, we perform
	  // N independent 3D convolutions, sliding (C/g)-channels
	  // filters across the spatial axes (D, H, W) of the input.
	  optional int32 axis = 16 [default = 1];     卷積軸,預設通道(3D卷積中,有時序軸卷積情況)
	
	  // Whether to force use of the general ND convolution, even if a specific
	  // implementation for blobs of the appropriate number of spatial dimensions
	  // is available. (Currently, there is only a 2D-specific convolution
	  // implementation; for input blobs with num_axes != 2, this option is
	  // ignored and the ND implementation will be used.)
	  //是否強制使用一般的ND卷積,即使對於具有適當空間維數的blob有特定的實現。(目前只有2d特有的卷積實現;對於num_axes != 2的輸入blob,將忽略此選項,並使用ND卷積)
	  optional bool force_nd_im2col = 17 [default = false];
}

卷積形式太多,一時難以收集全,先舉個例子,以後慢慢更新
例如在MobileNet中:

layer {
	  name: "conv6_3/dwise"
	  type: "Convolution"
	  bottom: "conv6_3/expand/bn"
	  top: "conv6_3/dwise"
	  param {
		    lr_mult: 1        
		    decay_mult: 1  
	  }
	  convolution_param {
		    num_output: 960     //輸出個數
		    bias_term: false     //不使用bias項
		    pad: 1   //填充1個畫素
		    kernel_size: 3   //卷積核大小3*3
		    group: 960   //組個數    則一組個數:num_output/ group (必須整除)
		    weight_filler {
		      type: "msra"    
		    }
		    engine: CAFFE
		  }
}