Tensorflow accuracy at .99 but predictions awful

孤街浪徒 提交于 2019-11-30 16:06:19

Errors in the code

There are multiple errors in your code:

WARNING: This op expects unscaled logits, since it performs a softmax on logits internally for efficiency. Do not call this op with the output of softmax, as it will produce incorrect results.

  • in fact since you have 2 classes, you should use a loss with softmax, using tf.nn.softmax_cross_entropy_with_logits

  • When using tf.argmax(pred, 1), you only apply argmax over axis 1, which is the height of the output image. You should use tf.argmax(pred, 3) on the last axis (of size 2).

    • This might explain why you get 0.99 accuracy
    • On the output image, it will take the argmax over the height of the image, which is by default 0 (as all values are equal for each channel)

Wrong model

The biggest drawback is that your model in general will be very hard to optimize.

  • You have a softmax over 40,000 classes, which is huge.
  • You do not take advantage at all of the fact that you want to output an image (the prediction foreground / background).
    • for instance prediction 2,345 is highly correlated with prediction 2,346 and prediction 2,545 but you don't take that into account

I recommend reading a bit about semantic segmentation first:

  • this paper: Fully Convolutional Networks for Semantic Segmentation
  • these slides from CS231n (Stanford): especially the part about upsampling and deconvolution

Recommendations

If you want to work with TensorFlow, you will need to start small. First try a very simple network with maybe 1 hidden layer.

You need to plot all the shapes of your tensors to make sure they correspond to what you thought. For instance, if you had plotted tf.argmax(y, 1), you would have realized the shape is [batch_size, 200, 2] instead of the expected [batch_size, 200, 200].

TensorBoard is your friend, you should try to plot the input image here, as well as your predictions to see what they look like.

Try small, with a very small dataset of 10 images and see if you can overfit it and predict almost the exact response.


To conclude, I am not sure of all my suggestions but they are worth trying, and I hope this will help you on the path to success !

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!