jakeret / tf_unet

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

Weighted Loss #196

Open mateovilla2 opened 6 years ago

mateovilla2 commented 6 years ago

Could you please give me an example of how apply the weighted cross entropy for training ? Thanks

Mateo

jakeret commented 6 years ago

You can pass an array that defines how much each class should be weighted. But take it with a grain of salt - possibly it's not the ideal rebalancing scheme

mateovilla2 commented 6 years ago

Thank you for your answer . That means, for example, if I write this,

net = unet.Unet(layers=6, features_root=32, channels=1, n_class=2,cost_kwargs={"class_weights":[0.3333,0.6666]})

I am giving the double of importance to the second class ?

Mateo

jakeret commented 6 years ago

Yes exactly You can also try the dice loss if the dataset is unbalanced

On Jul 20, 2018 12:59, "mateovilla2" notifications@github.com wrote:

Thank you for your answer . That means, for example, if I write this,

net = unet.Unet(layers=6, features_root=32, channels=1, n_class=2,cost_kwargs={"class_weights":[0.3333,0.6666]})

I am giving the double of importance to the second class ?

Mateo

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/jakeret/tf_unet/issues/196#issuecomment-406567436, or mute the thread https://github.com/notifications/unsubscribe-auth/ALSFv0M6f1_YMVfpjlSKAc4RF1dsd781ks5uIbgngaJpZM4VTF7d .

mateovilla2 commented 6 years ago

Thank you, I will try with both.

I have another question ( I think this obvious but just to verify) concerning the parameter "training_iters" used in the trainer.train method.

What I can understand from source code , it is only used to manage the size of my epoch (for showing stats), but I am concerned about its influence on the optimization frequency .

If I set for example , training_iters=50 (suppose a batch of 1 ), that means that :

(1) it will do 50 forward-backward passes to the same image, accumulates the gradients and then updating the weights ? or (2) it will always do the forward-backward pass + weights updating with a single image (independent of the value of training_iters ) ?

I suppose that (2) is the right answer; so what I am doing is setting training_iters=#training_images in order to visualize the average loss over the entire training set. Is that correct ?

Thank you for your answer

jakeret commented 6 years ago

Yes two is correct

mateovilla2 commented 6 years ago

Thank you