reference : https://www.zhihu.com/question/52242037/answer/184101547

 

问题:使用tensorflow lenet5做minst识别,使用如下损失函数,在训练几轮后loss出现nan

loss = tf.reduce_mean(-tf.reduce_sum(self.y * tf.log(output), reduction_indices=1))

tensorflow识别minst出现loss nan情况

 

解决:当预测出现0时tf.log(0)无意义,出现nan;可在输出项增加微小的项

loss = tf.reduce_mean(-tf.reduce_sum(self.y * tf.log(output+1e-10), reduction_indices=1))

 

 

相关文章: