jakeret / tf_unet

Generic U-Net Tensorflow implementation for image segmentation
GNU General Public License v3.0
1.9k stars 748 forks source link

Issue with prediction #197

Closed Rakshith-Manandi closed 5 years ago

Rakshith-Manandi commented 6 years ago

The model is training with 99% accuracy but there's no prediction. I assume there's overfitting happening and I needed some guidance overcoming this issue. A brief gist of what I've done so far: I've used the SimpleDataProvider class from the image_util.py file to generate my images. In the BaseProviderClass under the process_labels function you use the ~label which was converting my data to -1 and 0. 1) I assume you're doing this to onehotencode the labels. I used np.logical_not(label) and now my data is 0 & 1. Is this correct? 2) My model is training at 99% accuracy but there's no prediction happening. What could be the problem? I'm training on 165 images for 10 epochs and 32 iterations each. Should I increase my epochs given that my training data is high? I tried increasing the layers to 5 from 3 and I got like a weird output, which is what makes me think that there's something wrong with what I'm doing and maybe the model didn't train at 99% when I had 3 layers.

Any help on this is appreciated! Thanks

Rakshith-Manandi commented 6 years ago

Also, can you please advise on what should be given in the cost_kwargs argument to make use of the regularizer. I tried cost_kwargs = {"regularizer":[l2]} and I got name l2 not defined.

Thanks, Rakshith.

jakeret commented 6 years ago

Before using a deeper architecture I would rather try to increase the number of filters (features_root=XX). Have you checked the output in the tensorboard. Is the loss decreasing? Do the other metrics look "reasonable"? Could it be that your data is very unbalanced i.e. 99% of the pixel belong to one class? As for the regularizer: the implementation expects the power of the l2 regularizer i.e. a float e.g. 0.001

Rakshith-Manandi commented 6 years ago

I'll try increasing the number of filters. Thanks.

The loss is decreasing but I'm still not getting the output. Your guess is correct, 99% of the pixels belong to one class. How do I overcome this?

jakeret commented 6 years ago

This kind of class inbalance is quite difficult to deal with. You could experiment with the dice_coefficient loss or using some class weights. An other thing to try would be to produce "synthetic" data by creating snippets of the relevant regions. Such that the network sees the minority class more often so that it can learn its characteristics

Rakshith-Manandi commented 6 years ago

I tried both 'dice_coefficient' and class weights, didn't seem to have much luck. I'll try the synthetic data method and see if I'm getting any results. Thank you for the response :)

Rakshith-Manandi commented 6 years ago

With dice_coefficient I'm getting negative minibatch loss. Does that seem right to you?

jakeret commented 6 years ago

Yes that's fine. It's because SGD is minimizing the loss and a large dice corresponds to a great overlap, hence * -1