faustomilletari / VNet

GNU General Public License v3.0
284 stars 123 forks source link

Problem with Dice and its Derivative formula? #18

Closed navidsamavati closed 7 years ago

navidsamavati commented 7 years ago

Hello Fausto,

I have been trying to understand your definition of Dice in the paper, and its derivative implemented in pyLayer.py

The issues are:

1) Why do you have squared terms for each voxel in the denominator of Dice formula? Shouldn't they be just the voxels and not the squared of voxel values, which are (0 or 1)?

2) Given your derivative calculation in the paper (which seems alright to me), you have a different (perhaps mistakenly) implementation in pylayer.py! You have the following:

bottom[btm].diff[i, 0, :] += 2.0 ( (self.gt[i, :] self.union[i]) / ((self.union[i]) 2) - 2.0prob[i,1,:](self.intersection[i]) / ( (self.union[i]) 2))

But, it really should be:

bottom[btm].diff[i, 0, :] += 2.0 ( (self.gt[i, :] self.union[i]) - 2.0prob[i,1,:](self.intersection[i]) / ( (self.union[i]) ** 2))

in which "((self.union[i]) ** 2)" has been eliminated from the denominator of the first term.

Can you please look into this, and clarify?

Having raised these ambiguities, I have to say that I really appreciate your great work, and have been studying it for a while now.

Thanks! Navid

faustomilletari commented 7 years ago

Hello, I appreciate your comments.

the formula in the paper has squared denominator. the reason is that that’s the correct formula that gives you derivatives that are 0 when you reach the optimum. (you can try that yourself, look how everything would behave at optimum in the two cases). Also it is the formula that is reported on wikipedia when the dice is computed between two binary vectors.

The derivative should be correct, according to the formula in the paper, following the division derivation rule.

i hope this clarifies your doubts and I hope that you are finding this repository useful for your work.

Fausto

On 08 Mar 2017, at 11:58, navidsamavati notifications@github.com wrote:

Hello Fausto,

I have been trying to understand your definition of Dice in the paper, and its derivative implemented in pyLayer.py

The issues are:

Why do you have squared terms for each voxel in the denominator of Dice formula? Shouldn't they be just the voxels and not the squared of voxel values, which are (0 or 1)?

Given your derivative calculation in the paper (which seems alright to me), you have a different (perhaps mistakenly) implementation in pylayer.py! You have the following:

bottom[btm].diff[i, 0, :] += 2.0 ( (self.gt[i, :] self.union[i]) / ((self.union[i]) 2) - 2.0probi,1,: / ( (self.union[i]) 2))

But, it really should be:

bottom[btm].diff[i, 0, :] += 2.0 ( (self.gt[i, :] self.union[i]) - 2.0probi,1,: / ( (self.union[i]) ** 2))

in which "((self.union[i]) ** 2)" has been eliminated from the denominator of the first term.

Can you please look into this, and clarify?

Having raised these ambiguities, I have to say that I really appreciate your great work, and have been studying it for a while now.

Thanks! Navid

— 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/18, or mute the thread https://github.com/notifications/unsubscribe-auth/AMtsviGtgGNzX4cwGHYDhozGnC7wbgrDks5rjt43gaJpZM4MXCYr.

navidsamavati commented 7 years ago

Awesome! Thanks for clarifying this. I worked out the Dice formula with squared terms. You are indeed right. Great work!

I still think that the derivative implementation in pyLayer.py is not exactly the same as the derivative formula in the paper. I did the derivative myself, and got your formula in the paper. So, I guess there might be a typo in the brackets provided in the pyLayer.py in lines 61 - 66. I actually provided the modifications, that I think are necessary, in my comment above.

Do you agree?

Thanks again for your response!

Best, Navid

faustomilletari commented 7 years ago

Sure. Try it out and let me know if you can :-)

Fausto Milletarì Sent from my iPhone

On 8 Mar 2017, at 13:36, navidsamavati notifications@github.com wrote:

Awesome! Thanks for clarifying this. I worked out the Dice formula with squared terms. You are indeed right. Great work!

I still think that the derivative implementation in pyLayer.py is not exactly the same as the derivative formula in the paper. I did the derivative myself, and got your formula in the paper. So, I guess there might be a typo in the brackets provided in the pyLayer.py in lines 61 - 66. I actually provided the modifications, that I think are necessary, in my comment above.

Do you agree?

Thanks again for your response!

Best, Navid

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

navidsamavati commented 7 years ago

Indeed your implementation was correct :) 👍 👍

Sorry for the confusion!

Best, Navid