def _apply_func(self, activations, is_training, reuse):
'''
apply own functionality
Args:
activations: the ioutputs to the wrapped activation function
is_training: whether or not the network is in training mode
reuse: wheter or not the variables in the network should be reused
Returns:
the output to the activation function
'''
with tf.variable_scope('l2_norm', reuse=reuse):
#compute the mean squared value
sig = tf.reduce_mean(tf.square(activations), 1, keep_dims=True)
#divide the input by the mean squared value
normalized = activations/sig
#if the mean squared value is larger then one select the normalized
#value otherwise select the unnormalised one
return tf.select(tf.greater(tf.reshape(sig, [-1]), 1),
normalized, activations)
评论列表
文章目录