Tensorflow accuracy at .99 but predictions awful

后端 未结 1 1202
天命终不由人
天命终不由人 2021-01-03 10:12

Maybe I\'m making predictions wrong?

Here\'s the project... I have a greyscale input image that I am trying to segment. The segmentation is a simple binary classific

相关标签:
1条回答
  • 2021-01-03 10:58

    Errors in the code

    There are multiple errors in your code:

    • you shouldn't call tf.nn.sigmoid_cross_entropy_with_logits with the output of a softmax layer, but with the unscaled logits:

    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 !

    0 讨论(0)
提交回复
热议问题