I am training an autoencoder whose input is a matrix P in [0,1] using the following loss function:
And here is my code:
# Define loss and optimizer, minimize the squared error
with tf.device("/device:GPU:0"):
L = -tf.reduce_sum(self.p*tf.math.log(self.p_pred+1e-10) + 0.55*(1 - self.p)*tf.math.log(1-self.p_pred+1e-10), axis = 1)
self.loss = tf.reduce_mean(L)
self.optimizer = tf.compat.v1.train.AdamOptimizer(self.learning_rate).minimize(self.loss)
In main.py, I run session like this:
_, l, y_pred, y = sess.run([model.optimizer, model.loss, model.y_pred, model.y], feed_dict=...)
But the loss returns nan at different epoch whenever I'm training. The activation function is sigmoid and learning_rate = 0.01. The number of epoch is 20. I'm trying to save p and p_pred when the loss is nan, then I run the same loss function in google colab, the result is not nan! I don't understand.
Any ideas for what I did wrong?
