Tensorflow 预测的中间结果有很多 NAN,如下图
看一下计算 loss 的时候是否有类似下面的代码
cross_entropy = tf.reduce_mean(-tf.reduce_sum(ys * tf.log(prediction), reduction_indices=[1]))
把上面的代码改为下面这样即可解决
cross_entropy = tf.reduce_mean(-tf.reduce_sum(ys * tf.log(tf.clip_by_value(prediction, 1e-10,1.0)), reduction_indices=[1]))
参考:http://stackoverflow.com/questions/33712178/tensorflow-nan-bug
本文介绍如何解决TensorFlow预测过程中出现NAN值的问题。通过调整计算交叉熵损失的代码,采用tf.clip_by_value函数限制prediction的取值范围,避免log函数中出现0而导致的结果为NAN。
2753

被折叠的 条评论
为什么被折叠?



