def information_pool(self, inputs, max_alpha, alpha_mode, lognorm_prior, num_outputs=None, stride=2, scope=None):
if num_outputs is None:
num_ouputs = inputs.get_shape()[-1]
# Creates the output convolutional layer
network = self.conv(inputs, num_outputs=int(num_outputs), stride=stride)
with tf.variable_scope(scope,'information_dropout'):
# Computes the noise parameter alpha for the output
alpha = conv2d(inputs, num_outputs=int(num_outputs), kernel_size=3,
stride=stride, activation_fn=tf.sigmoid, scope='alpha')
# Rescale alpha in the allowed range and add a small value for numerical stability
alpha = 0.001 + max_alpha * alpha
# Computes the KL divergence using either log-uniform or log-normal prior
if not lognorm_prior:
kl = - tf.log(alpha/(max_alpha + 0.001))
else:
mu1 = tf.get_variable('mu1', [], initializer=tf.constant_initializer(0.))
sigma1 = tf.get_variable('sigma1', [], initializer=tf.constant_initializer(1.))
kl = KL_div2(tf.log(tf.maximum(network,1e-4)), alpha, mu1, sigma1)
tf.add_to_collection('kl_terms', kl)
# Samples the noise with the given parameter
e = sample_lognormal(mean=tf.zeros_like(network), sigma = alpha, sigma0 = self.sigma0)
# Saves the log-output of the network (useful to compute the total correlation)
tf.add_to_collection('log_network', tf.log(network * e))
# Returns the noisy output of the dropout
return network * e
评论列表
文章目录