Shortcuts

IoU#

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

Calculates Intersection over Union using ConfusionMatrix metric.

J(A,B)=ABAB\text{J}(A, B) = \frac{ \lvert A \cap B \rvert }{ \lvert A \cup B \rvert }
Parameters
  • cm (ConfusionMatrix) – instance of confusion matrix metric

  • ignore_index (Optional[int]) – index to ignore, e.g. background index

Returns

MetricsLambda

Return type

MetricsLambda

Examples:

train_evaluator = ...

cm = ConfusionMatrix(num_classes=num_classes)
IoU(cm, ignore_index=0).attach(train_evaluator, 'IoU')

state = train_evaluator.run(train_dataset)
# state.metrics['IoU'] -> tensor of shape (num_classes - 1, )