I am getting a different result from torchvisions dice function, than what I would expect. I am sure there is a very simple explanation for this, but I can't figure it out.
import torch
from torchmetrics.functional import dice
preds = torch.Tensor([1, 0, 1, 1]).to(int)
targets = torch.Tensor([1, 1, 1, 0]).to(int)
dice_score = dice(preds, targets)
print(dice_score)
The result of the above example is 0.5, but with the formula for the dice score,I would expect a result of 0.6667:
dice = 2*TP / (2*TP + FN + FP)
In my example above that would be:
TP = 2
FP = 1
FN = 1
So, dice = 4/(4+1+1) = 4/6 = 0.6667