-
Notifications
You must be signed in to change notification settings - Fork 32
Wrong code! #1
Comments
Emm, a typo? I don't see any differences. |
@hubutui
"+" in pytorch of a tensor and a scalar will be done on every index, so if you sum up the num, molecule is the sum of num and smooth multiply with the shape of the sum(not 1 but maybe millions). |
and miss multiply 2,
|
@Guocode Can you just do the following?
All in the same comment? It is hard for me to follow and understand what you are trying to tell me. @hubutui Can you review this issue? I was planning to use your loss on a segmentation deep learning pipeline. |
@diegovincent |
Let me try to work this out, this page:
So adds a I think diegovincent is saying that if you sum on dimension two only, but leave the others dimension, giving you a tensor of shape, say, [16, 4]. Now if you add smooth, pytorch will expand it's shape to [16, 4] and add it to each element. The results is you've added it many times. The alternative is to sum over all elements first, and then add smooth. But this changes the equation, and you're not actually calculating the dice loss for each element, but for the sum of all elements in all batches. There may be disagvantages to backprop if you sum too early as the gradient isn't traces through the dice loss of each element. The only disadvantage I see if adding smooth to each element is that it smooths more. But you can [actually measure] the effect smoothing has on the output, and it gives an outputs similar to MSELoss. Also I implemented dice loss in the same way in this gist and quite a few people reviewed it. I think it's fine as it is. |
The add of smooth is done on every index! It should be like this
The text was updated successfully, but these errors were encountered: