I have been trying to understand the below code (written in Tensorflow), but unable to do so as I am not very proficient with Tensorflow. I am looking for some help. Below is the code:
if model == 'mse': rec_loss = tf.losses.mean_squared_error(img, img_rec) kld_loss = -tf.reduce_mean(0.5 * (1 + z_log_sigma_sq - z_mu ** 2 - tf.exp(z_log_sigma_sq))) else: if model == 'gaussian': log_sigma = tf.Variable(0.0, trainable=False) elif model == 'sigma': log_sigma = tf.Variable(0.0, trainable=True) elif model == 'optimal': log_sigma = tf.log(tf.sqrt(tf.reduce_mean((img - img_rec) ** 2, [0, 1, 2, 3], keepdims=True))) rec_loss = tf.reduce_sum(gaussian_nll(img_rec, log_sigma, img))
gaussian_nll function is defined below:
def gaussian_nll(mu, log_sigma, x): return 0.5 * ((x - mu) / tf.exp(log_sigma)) ** 2 + log_sigma + 0.5 * np.log(2 * np.pi)
I have these questions:
- What is the difference between
model == 'gaussian'and under
model == 'sigma'? (only difference in the definition of the variable is the flag
- What is the difference between the
model == 'optimal'? Aren't they both similar?
They are correct, but I am unable to correctly read it. Any help regarding the code would be greatly appreciated. For those of you who wants to take a look at the full code on github, here is the link github page (the above piece of code appears between lines 34 and 44)
Thanks once again for your help.