Shortcuts

DiceCoefficient#

ignite.metrics.DiceCoefficient(cm, ignore_index=None)[source]#

Calculates Dice Coefficient for a given ConfusionMatrix metric.

Parameters
Return type

ignite.metrics.metrics_lambda.MetricsLambda

Examples

cm = ConfusionMatrix(num_classes=3)
metric = DiceCoefficient(cm, ignore_index=0)
metric.attach(default_evaluator, 'dice')
y_true = torch.Tensor([0, 1, 0, 1, 2]).long()
y_pred = torch.Tensor([
    [0.0, 1.0, 0.0],
    [0.0, 1.0, 0.0],
    [1.0, 0.0, 0.0],
    [0.0, 1.0, 0.0],
    [0.0, 1.0, 0.0],
])
state = default_evaluator.run([[y_pred, y_true]])
print(state.metrics['dice'])
tensor([0.6667, 0.0000], dtype=torch.float64)