一、引言
在激活层中,对输入数据进行激活操作(实际上就是一种函数变换),是逐元素进行运算的。从bottom 得到一个 blob 数据输入,运算后从 top 输出一个 blob 数据。在运算过程中,没有改变数据的大小,即输入数据和输出数据大小是相等的。常用的激活函数由 sigmoid、tanh、relu 等,下文展开讲解。
二、 Sigmoid 激活函数
对于每个输入数据,利用 Sigmoid 函数执行操作。这种层设置比较简单,没有额外的参数。
Sigmoid函数公式:
type | Sigmoid |
layer {
name: "encode1neuron"
bottom: "encode1"
top: "encode1neuron"
type: "Sigmoid"
}
三、 ReLu / Rectified-Linear and Leaky-ReLu 激活函数
ReLu 是目前使用最多的激活函数,主要因为其收敛更快,并且能保持同样效果。ReLu层支持 in-place 计算,这意味着 bottom的输出和输入相同以避免内存的消耗。
ReLu 函数:
type | ReLu |
negative_slope | 默认为0。如果设置了这个值,当数据为负数时,就不再设置为0,而是用原始数据乘以 negative_slope。 |
layer {
name: "relu1"
type: "ReLU"
bottom: "pool1"
top: "pool1"
}
四、 Tanh / Hyperbolic Tangent
利用双曲正切函数对数据进行变换。
Tanh函数公式:
type | TanH |
layer {
name: "layer"
bottom: "in"
top: "out"
type: "TanH"
}
五、Absolute Value 激活函数
求每个输入数据的绝对值。
函数公式: f(x) = Abs(x) 层类型: AbsVal
layer {
name: "layer"
bottom: "in"
top: "out"
type: "AbsVal"
}
六、 Power 激活函数
对每一个输入数据进行幂运算。
函数公式:f(x) = (shift + scale * x) ^ power
type | Power |
power | 默认为1 |
scale | 默认为1 |
shift | 默认为0 |
layer {
name: "layer"
bottom: "in"
top: "out"
type: "Power"
power_param {
power: 2
scale: 1
shift: 0
}
}
七、BNLL 激活函数
Binomial Normal Log Likelihood 的简称。
函数公式: f(x) = log ( 1 + exp(x) )
层类型: BNLL
layer {
name: "layer"
bottom: "in"
top: "out"
type: "BNLL"
}