Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TensorFlow's ReluGrad claims input is not finite

I'm trying out TensorFlow and I'm running into a strange error. I edited the deep MNIST example to use another set of images, and the algorithm converges nicely again, until around iteration 8000 (accuracy 91% at that point) when it crashes with the following error.

tensorflow.python.framework.errors.InvalidArgumentError: ReluGrad input is not finite

At first I thought maybe some coefficients were reaching the limit for a float, but adding l2 regularization on all weights & biases didn't resolve the issue. It's always the first relu application that comes out of the stacktrace:

h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)

I'm working on CPU only for now. Any idea what could cause this and how to work around it?

Edit: I traced it down to this problem Tensorflow NaN bug?, the solution there works.

like image 250
user1111929 Avatar asked Nov 13 '15 18:11

user1111929


2 Answers

Error is due to 0log(0)

This can be avoided by:

cross_entropy = -tf.reduce_sum(y*tf.log(yconv+ 1e-9))
like image 138
Muaaz Avatar answered Sep 28 '22 02:09

Muaaz


Since I had another topic on this issue [ Tensorflow NaN bug? ] I didn't keep this one updated, but the solution has been there for a while and has since been echoed by posters here. The problem is indeed 0*log(0) resulting in an NaN.

One option is to use the line Muaaz suggests here or the one I wrote in the linked topic. But in the end TensorFlow has this routine embedded: tf.nn.softmax_cross_entropy_with_logits and this is more efficient and should hence be preferred when possible. This should be used where possible instead of the things me and Muaaz suggested earlier, as pointed out by a commentor on said link.

like image 41
user1111929 Avatar answered Sep 28 '22 03:09

user1111929