Repository navigation
Metrics for segmentation #374
Answered
by
Borda
talhaanwarch
asked this question in
Q&A
|
Do, we have metrics for segmentation tasks? |
Answered by
Borda
Mar 18, 2026
Replies: 2 comments 2 replies
|
Hi @talhaanwarch, |
2 replies
|
@talhaanwarch @paudom @Sarmadfismael — TorchMetrics now has a dedicated segmentation module! Here's what's available (v1.9.0):
Quick example — semantic segmentation: from torchmetrics.segmentation import DiceScore, MeanIoU
dice = DiceScore(num_classes=21, average="macro", input_format="index")
miou = MeanIoU(num_classes=21, input_format="index")
# preds: (N, H, W) — predicted class indices
# target: (N, H, W) — ground truth
dice_score = dice(preds, target)
miou_score = miou(preds, target)With Lightning: from torchmetrics import MetricCollection
from torchmetrics.segmentation import DiceScore, MeanIoU
seg_metrics = MetricCollection({
"dice": DiceScore(num_classes=21, average="macro", input_format="index"),
"miou": MeanIoU(num_classes=21, input_format="index"),
})
self.val_metrics = seg_metrics.clone(prefix="val/")
def validation_step(self, batch, batch_idx):
preds = self(batch["image"]).argmax(dim=1)
self.log_dict(self.val_metrics(preds, batch["mask"])) |
0 replies
Answer selected by
Borda
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@talhaanwarch @paudom @Sarmadfismael — TorchMetrics now has a dedicated segmentation module! Here's what's available (v1.9.0):
torchmetrics.segmentation:DiceScoreMeanIoUHausdorffDistanceGeneralizedDiceScorePanopticQualityQuick example — semantic segmentation: