Caffe下卷積神經網路中的一些特殊層
Caffe下卷積神經網路(CNN)中的一些特殊層
作者:xg123321123
宣告:版權所有,轉載請聯絡作者並註明出處
Batch Normalization
- 意義: 網路訓練時,用來加速收斂速度
- 提醒:
- 已經將BN整合為一個layer了,使用時需要和scale層一起使用
- 訓練的時候,將BN層的use_global_stats設定為false; 測試的時候將use_global_stats設定為true,不然訓練的時候會報“NAN”或者模型不收斂 – 師兄的經驗,我還沒試驗過
Dropout
- 意義: 防止模型過擬合;訓練模型時,隨機讓網路某些隱含層節點的權重不工作(不工作的那些節點可以暫時認為不是網路結構的一部分,但是它的權重得保留下來,只是暫時不更新而已,因為下次樣本輸入時它可能又得工作了)
- 用法:
layer {
name: “drop7”
type: “Dropout”
bottom: “fc7-conv”
top: “fc7-conv”
dropout_param {
dropout_ratio: 0.5
}
}
ReLU
- 意義: 啟用函式的一種;對於給定的一個輸入值x,如果x > 0,ReLU層的輸出為x,如果x < 0,ReLU層的輸出為0。
- 提醒: 可選引數
negative_slope
,此引數使得x < 0時,ReLU層的輸出為negative_slope * x;目前已經有了ReLU的進化版 – - 用法:
layer {
name: “relu1”
type: “ReLU”
bottom: “conv1”
top: “conv1”
relu_param{
negative_slope: [預設:0]
}
}
PReLU
- 意義: ReLu的進化版;。
- 提醒: 在負半軸的輸出乘以一個係數,而這個係數是可學習的(你可以為其指定學習率),其中value是係數的初始值,channel_shared指定是否在各個通道間共享這個係數。 據說有的實驗更快更好地收斂,但有的實驗準確率卻有所下降 - 具體效果還是得以具體實驗為準(自己沒有用過,不加評論
-用法:
layer {
name: “relu1”
type: “PReLU”
bottom: “conv1”
top: “conv1”
param {
lr_mult: 1
decay_mult: 0
}
prelu_param {
filler: {
value: 0.33 #: 預設為0.25
}
channel_shared: false
}
}
Split
- 意義: 將一份blob複製為n份
- 提醒: caffe會隱式地做這個操作,我也不知道什麼時候會顯式地用到這個操作,先擱這兒吧(沒實際用過這個操作,所以下面的用法不一定對)
- 用法:
layer {
name: “split”
type: “split”
bottom: “rois”
top: “rois1”
top: “rois2”
}
Reshape
- 意義: 改變blob的維度,而不改變其自身的資料
- 提醒: 每個blob為4維,故有4個dim引數【0代表不改變維度的值,-1代表由caffe計算出值,正數代表將維度更改為對應的值】
layer {
name: “reshape”
type: “Reshape”
bottom: “conv1”
top: “conv1”
reshape_param {
shape {
dim: 0 # copy the dimension from below
dim: 2
dim: 3
dim: -1 # infer it from the other dimensions
}
}
}
注: 若1個引數分別為 dim:1 dim:3 dim:2 dim:-1的reshape層,輸入為1個維度為1*2*3*4的blob,那麼輸出的blob維度為1*3*2*4(其中4是由caffe計算而來的)
InnerProduct
- 意義: 將輸入資料以簡單的向量形式進行處理,並且輸出一個簡單的向量;簡單來說,這是一個卷積操作,只不過卷積核尺寸和feature map相同,故輸出向量大小為1*1
- 缺點:使用包含全連線層的模型(如AlexNet)必須使用固定大小的輸入,有時這是非常不合理的,因為必須對輸入圖片進行變形。
- 提醒:
- 必要引數:
num_output (c_o):濾波器數量 - 強烈建議引數:
weight_filler:濾波器的初始分佈和分佈引數。 - 可選引數:
bias_filler:[預設: type: ‘constant’ value: 0]
bias_term:[預設:true] 指定是否在濾波器輸出之後學習並應用附加的偏置。
- 必要引數:
用法:
layer {
name: “fc8”
type: “InnerProduct”
bottom: “fc7”
top: “fc8”param { # learning rate and decay multipliers for the weights
lr_mult: 1 decay_mult: 1
}param { # learning rate and decay multipliers for the biases
lr_mult: 2 decay_mult: 0
}inner_product_param {
num_output: 1000weight_filler {
type: “xavier”
std: 0.01
}bias_filler {
type: “constant”
value: 0
}
}
}
注: 比如上面層的輸入為 n * c_i * h_i * w_i,那麼輸入為 n * 1000 * 1 * 1
Crop
- 意義:輸入兩個blob,將bottom[0] 按照bottom[1]的尺寸進行剪裁
- 提醒:
- axis=0,1,2,3分別表示為N,C,H,W;預設axis等於2,即預設從H開始裁剪(裁剪H和W);可以只設置1個,也可以為每個dimension分別設定
- offset表示裁剪時的偏移量(如果還是不太清楚的話,戳這兒
- 用法:
layer {
type: “Crop”
name: ‘crop’
bottom: ‘score-dsn1-up’
bottom: ‘data’
top: ‘upscore-dsn1’
crop_param {
axis: 2
offset: 5
}
}