faustomilletari / VNet

GNU General Public License v3.0
286 stars 122 forks source link

Dice greater than 1 #13

Closed RSly closed 7 years ago

RSly commented 7 years ago

Hi,

I am trying to use the dice loss function here. My training diceloss is greater than 1. however, my validation error is in the correct range [0,1] How can this happen? I dont know what is the source of this bug.

any suggestion?

is it the same Dice function that runs for both training and validation ?

faustomilletari commented 7 years ago

I think this happens if you have batch_size more than 1. because it just sums the dices of all the volumes together instead of taking their average.

just a guess

On Jan 25, 2017, at 11:46 AM, RSly notifications@github.com wrote:

Hi,

I am trying to use the dice loss function here. My training diceloss is greater than 1. however, my validation error is in the correct range [0,1] How can this happen? I dont know what is the source of this bug.

any suggestion?

is it the same Dice function that runs for both training and validation ?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/faustomilletari/VNet/issues/13, or mute the thread https://github.com/notifications/unsubscribe-auth/AMtsvowzRfAXDlw7H7QQ-0bQe49EUIZuks5rV3x-gaJpZM4Ltt0M.

RSly commented 7 years ago

Exactly!! thanks

any suggestion how to bring the batch_size to the implementation? lets make it work for all batch sizes :)

faustomilletari commented 7 years ago

it is in the python layer. you need to divide the final dice by the number of volumes in the batch. in the derivative you should do the same.

On Jan 25, 2017, at 12:13 PM, RSly notifications@github.com wrote:

Exactly!! thanks

any suggestion how to bring the batch_size to the implementation? lets make it work for all batch sizes :)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/faustomilletari/VNet/issues/13#issuecomment-275169815, or mute the thread https://github.com/notifications/unsubscribe-auth/AMtsvtqWHWYxldA5PHjHDLJ5jvskjhUiks5rV4KlgaJpZM4Ltt0M.

RSly commented 7 years ago

Thanks, Also I wonder that the loss should be 1-dice and not dice so shouldnt we use top[0].data[0]=1-np.sum(dice) instead of top[0].data[0]=np.sum(dice)

??

faustomilletari commented 7 years ago

Sure. You can do that as well. Derivatives should be correct as they are though

Fausto Milletarì Sent from my iPhone

On 25 Jan 2017, at 12:26, RSly notifications@github.com wrote:

Thanks, Also I wonder that the loss should be 1-dice and not dice so shouldnt we use top[0].data[0]=1-np.sum(dice) instead of top[0].data[0]=np.sum(dice)

??

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

RSly commented 7 years ago

Hi again,

I am playing with these loss functions, and have some questions

faustomilletari commented 7 years ago

On Jan 31, 2017, at 8:41 AM, RSly notifications@github.com wrote:

Hi again,

I am playing with these loss functions, and have some questions

Could you please explain how you have calculated the backward function? that would be the derivative of the forward part :) (the derivative of 2AB / (A + B)) we are using an approximate version though. it uses both the continuous segmentation outcome in range [0, 1] and the thresholded segmentation(at 0.5) in the computation. is it specific to your network definition or can I use it with other networks, FC8s, alexnet, Unet, etc?

you should be able to use it everywhere.

Do you have experience with defining of a loss function in tensorflow? I think there tensorflow does the backward and there is no need for writing down the backward specifically. I am not sure though should be possible to do in tensor flow without writing anything more than the forward part. — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/faustomilletari/VNet/issues/13#issuecomment-276365504, or mute the thread https://github.com/notifications/unsubscribe-auth/AMtsvhq7F5CWP6K0eh4wAZfaIAwDREo0ks5rXzn-gaJpZM4Ltt0M.

faustomilletari commented 7 years ago

please consider doing a pull request to solve this "problem" even though i don't think it actually impairs learning...

13331112522 commented 4 years ago

I use 1-2(XY+smooth)/(X+Y+smooth) for my Dice Loss according most of the open source code. I have found the smooth really plays important part for it. BUT, I think it should be 1-(2XY+smooth)/(X+Y+smooth) because if both x and y equal to zero, the smooth*2 will be much higher than just one smooth. Am I right? @faustomilletari