- Layer type: Convolution
- 頭文件位置:./include/caffe/layers/conv_layer.hpp
- CPU 執行源文件位置: ./src/caffe/layers/conv_layer.cpp
- CUDA GPU 執行源文件位置: ./src/caffe/layers/conv_layer.cu
- Convolution層的功能:使用一組可學習的濾波器對輸入圖像進行卷積,每個濾波器在輸出圖像中生成一個特徵映射。
- 輸入
n * c_i * h_i * w_i - 輸出
n * c_o * h_o * w_o, where h_o = (h_i + 2 * pad_h - kernel_h) / stride_h + 1 and w_o likewise.
參數解讀
layer {
name: "conv1"
type: "Convolution"
bottom: "data"
top: "conv1"
# 實際學習率 = 根據slover.prototxt中的base乘以下面係數
# 權重學習率
param {
lr_mult: 1
decay_mult: 1
}
# 偏置學習率
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 96
kernel_size: 11
stride: 4
weight_filler {
type: "gaussian" # 用高斯來初始化權重
std: 0.01 #
}
bias_filler {
type: "constant" # 初始化偏置
value: 0
}
}
}
參數定義
Parameters (ConvolutionParameter convolution_param)
- 需要的參數
num_output (c_o): 濾波器個數
kernel_size (or kernel_h and kernel_w): 濾波器尺寸 - 強烈推薦
weight_filler [default type: ‘constant’ value: 0] - 可選參數
bias_term [default true]: 指定是否學習並將一組加法偏差應用於濾波器輸出,就是有沒有偏置項。
pad (or pad_h and pad_w) [default 0]: 指定(隱式)添加到輸入的每一側的像素數
stride (or stride_h and stride_w) [default 1]:指定將過濾器在圖像上滑動的間隔
group (g) [default 1]: 如果g> 1,我們將每個過濾器的連接限制爲輸入的子集。 具體地,輸入和輸出通道被分成g組,並且第i個輸出組通道將僅連接到第i個輸入組通道。這個操作可以參考shfflenet網絡。
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
// 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
// For 2D convolution only, the *_h and *_w versions may also be used to
// specify both spatial dimensions.
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)
optional uint32 stride_w = 14; // The stride width (2D only)
optional uint32 group = 5 [default = 1]; // The group size for group conv
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];
// 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.)
optional bool force_nd_im2col = 17 [default = false];
}