From aaf49acb55bdd92502f36ce8265c2401da3351ee Mon Sep 17 00:00:00 2001 From: yanming Date: Wed, 29 Jul 2020 09:49:18 +0800 Subject: [PATCH] fix potential NaN bug in tf.log --- examples/2_BasicModels/logistic_regression.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/2_BasicModels/logistic_regression.py b/examples/2_BasicModels/logistic_regression.py index f38ea81c..ee685901 100644 --- a/examples/2_BasicModels/logistic_regression.py +++ b/examples/2_BasicModels/logistic_regression.py @@ -33,7 +33,7 @@ pred = tf.nn.softmax(tf.matmul(x, W) + b) # Softmax # Minimize error using cross entropy -cost = tf.reduce_mean(-tf.reduce_sum(y*tf.log(pred), reduction_indices=1)) +cost = tf.reduce_mean(-tf.reduce_sum(y*tf.log(tf.clip_by_value(pred,1e-10,1.0)), reduction_indices=1)) # Gradient Descent optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)