sigmoid 和 ReLU
s i g m o i d ( x ) = 1 1 + e − x sigmoid(x) = \frac{1}{1+e^{-x}} sigmoid(x)=1+e−x1
s i g m o i d sigmoid sigmoid激活函数的问题是随着输入趋近 ± ∞ \pm\infty ±∞时,梯度会迅速变为0,梯度回传时,浅层的参数无法得到有效更新。
R
e
L
U
(
x
)
=
m
a
x
(
0
,
x
)
ReLU(x) = max(0, x)
ReLU(x)=max(0,x)
R
e
L
U
ReLU
ReLU在x>0时,梯度恒为1,不会存在梯度消失问题。在x<0时,梯度为0,不再反传,可类似
d
r
o
p
o
u
t
dropout
dropout引入更多非线性。加入模型后,训练稳定性和效果均优于
s
i
g
m
o
i
d
sigmoid
sigmoid。
ReLU 和 ReLU6
R
e
L
U
6
(
x
)
=
m
i
n
(
6
,
m
a
x
(
0
,
x
)
)
ReLU6(x) = min(6, max(0, x))
ReLU6(x)=min(6,max(0,x))
限制了
R
e
L
U
ReLU
ReLU的最大输出不超过6,可以增强端上小模型,低精度推理时的鲁棒性。
sigmoid 和 hard sigmoid
h
a
r
d
_
s
i
g
m
o
i
d
(
x
)
=
(
R
e
L
U
(
x
)
+
3
)
/
6
hard\_sigmoid(x) = (ReLU(x) + 3)/6
hard_sigmoid(x)=(ReLU(x)+3)/6
可近似
s
i
g
m
o
i
d
sigmoid
sigmoid函数,计算量更低。
swish 和 hard swish
s
w
i
s
h
(
x
)
=
x
⋅
s
i
g
m
o
i
d
(
β
x
)
swish(x) = x\cdot sigmoid(\beta x)
swish(x)=x⋅sigmoid(βx)
h
a
r
d
_
s
w
i
s
h
(
x
)
=
x
⋅
(
R
e
L
U
6
(
x
)
+
3
)
/
6
hard\_swish(x) = x \cdot (ReLU6(x) + 3)/6
hard_swish(x)=x⋅(ReLU6(x)+3)/6
s w i s h swish swish中的 s i g m o i d sigmoid sigmoid操作,在端上计算量过重,于是用 h a r d _ s i g m o i d hard\_sigmoid hard_sigmoid来近似。 h _ s w i s h h\_swish h_swish激活操作在 m o b i l e n e t v 3 mobilenetv3 mobilenetv3中被使用。