转载自https://blog.csdn.net/qq_32782339/article/details/78877908
Highway Network主要解决的问题是,网络深度加深,梯度信息回流受阻造成网络训练困难的问题。
假设定义一个非线性变换为
定义门函数
,携带函数
。
门函数取sigmoid,值在0-1之间,不含0,1.
一个网络的输出最终变为x,
门函数作用类似于抽样。输出的范围在输入
和
之间,有效的缓解了梯度消失和爆炸问题。
具体的代码实现为:
<code class="language-html">def highway(input_, size, num_layers=1, bias=-2.0, f=tf.nn.relu, scope='Highway'):
"""Highway Network (cf. http://arxiv.org/abs/1505.00387).
t = sigmoid(Wy + b)
z = t * g(Wy + b) + (1 - t) * y
where g is nonlinearity, t is transform gate, and (1 - t) is carry gate.
"""
with tf.variable_scope(scope):
for idx in range(num_layers):
g = f(linear(input_, size, scope='highway_lin_%d' % idx))
t = tf.sigmoid(linear(input_, size, scope='highway_gate_%d' % idx) + bias)
output = t * g + (1. - t) * input_
input_ = output
return output</code>