Dice Score calculation
varghesealex90 opened this issue · 2 comments
Hi
Could you please point me how you calculate the dice score?
You can find the code here.
Hello Shubham;
Thank you for the prompt reply and pointing me to the code. However I do have doubt regarding the same. For the sake of simplicity, lets say 1) The output from U-net is a 3x3 label image.
dice_score =0
u_net_output = torch.ones(4,3,3) :fill(2) ---[ batches, W, H] say the label associated was 2
targets = torch.ones(4,3,3) :fill(2) --- targets are also 2, ideally dice score should be 1
for i =1 , u_net_output :size(1) do
local output = u_net_output [i]
local target = targets [i]
numerator = torch.cmul(output,target)
dice_score= dice_score + 2*(numerator:sum())/(target:sum()+output:sum())
end
dice_coeff= dice_score/u_net_output:size(1)
print (dice_coeff) yields answer =2 .
Is this because I am calculating the dice score of batch ? Any thoughts?