user4054919
user4054919

Reputation: 129

Tensorflow - Convolutionary Net: Grayscale vs Black/White training

I took the mnist example for the cnn. https://www.tensorflow.org/versions/r0.10/tutorials/mnist/pros/index.html I changed it slightly to process my own 28x28 images. I have 2 classes, an image is either an eye or a wall.

I noticed that rgb and grayscale images did not led to any training improvement the accuracy was constant 0.5 . While images converted to black and white (with image.convert('1')) were trained quite fast. After 200 iterations with a batch size of 20 the accuracy is around 0.9.

What might be the reasons the grayscale images are not leading to any improvement?

What can be done to improve their performance?

Edit 1: I just used TensorBoard to visualize what's going on and I found out that the cross-entropy returns NaN the whole time, when training with grayscale images..

Edit 2: The calculation of the cross-entropy I used was bad. Tensorflow NaN bug?

Now there is a still no progress when using grayscale images.

Upvotes: 0

Views: 468

Answers (1)

user4054919
user4054919

Reputation: 129

As mentioned in my edits, it turns out that the cross-entropy was not calculated correctly. Be carefull using code from the examples, they might only work in the exact example case.

The second awnser at Tensorflow NaN bug? finally solved my problem:

with tf.name_scope('cross_entropy'):
    diff = y_ * (tf.nn.log_softmax(y_conv))
    with tf.name_scope('total'):
        cross_entropy = tf.reduce_mean(-tf.reduce_sum(diff, reduction_indices=[1]))
    tf.scalar_summary('cross entropy', cross_entropy)

instead of

y_conv=tf.nn.softmax(...)
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y_conv), reduction_indices=[1])) 

Upvotes: 0

Related Questions