前言:本文參考博客denny402
在激活層中,對(duì)輸入數(shù)據(jù)進(jìn)行激活操作(實(shí)際上就是一種函數(shù)變換),是逐元素進(jìn)行運(yùn)算的。從bottom得到一個(gè)blob數(shù)據(jù)輸入,運(yùn)算后,從top輸入一個(gè)blob數(shù)據(jù)。在運(yùn)算過(guò)程中,沒(méi)有改變數(shù)據(jù)的大小,即輸入和輸出的數(shù)據(jù)大小是相等的。
輸入:n*c*h*w
輸出:n*c*h*w
常用的激活函數(shù)有sigmoid, tanh,relu等,下面分別介紹。
1、Sigmoid
對(duì)每個(gè)輸入數(shù)據(jù),利用sigmoid函數(shù)執(zhí)行操作。這種層設(shè)置比較簡(jiǎn)單,沒(méi)有額外的參數(shù)。

層類型:Sigmoid
示例:
layer {
name: "encode1neuron"
bottom: "encode1"
top: "encode1neuron"
type: "Sigmoid"
}
2、ReLU / Rectified-Linear and Leaky-ReLU
ReLU是目前使用最多的激活函數(shù),主要因?yàn)槠涫諗扛?,并且能保持同樣效果?br>
標(biāo)準(zhǔn)的ReLU函數(shù)為max(x, 0),當(dāng)x>0時(shí),輸出x; 當(dāng)x<=0時(shí),輸出0
f(x)=max(x,0)
層類型:ReLU
可選參數(shù):
negative_slope:默認(rèn)為0. 設(shè)置激活函數(shù)在負(fù)數(shù)部分的斜率。對(duì)于輸入數(shù)據(jù)小于0的話,則乘以這個(gè)因子;斜率為0時(shí),則為標(biāo)準(zhǔn)的ReLU。
RELU層支持in-place計(jì)算,這意味著bottom的輸出和輸入相同以避免內(nèi)存的消耗。
layer {
name: "relu1"
type: "ReLU"
bottom: "pool1"
top: "pool1"
}
3、TanH / Hyperbolic Tangent
利用雙曲正切函數(shù)對(duì)數(shù)據(jù)進(jìn)行變換。

層類型:TanH
layer {
name: "layer"
bottom: "in"
top: "out"
type: "TanH"
}
4、Absolute Value
求每個(gè)輸入數(shù)據(jù)的絕對(duì)值。
f(x)=Abs(x)
層類型:AbsVal
layer {
name: "layer"
bottom: "in"
top: "out"
type: "AbsVal"
}
5、Power
對(duì)每個(gè)輸入數(shù)據(jù)進(jìn)行冪運(yùn)算
f(x)= (shift + scale * x) ^ power
層類型:Power
可選參數(shù):
power: 默認(rèn)為1
scale: 默認(rèn)為1
shift: 默認(rèn)為0
layer {
name: "layer"
bottom: "in"
top: "out"
type: "Power"
power_param {
power: 2
scale: 1
shift: 0
}
}
6、BNLL
binomial normal log likelihood的簡(jiǎn)稱
f(x)=log(1 + exp(x))
層類型:BNLL
layer {
name: "layer"
bottom: "in"
top: "out"
type: “BNLL”
}