Skip to content
Discussion options

You must be logged in to vote

@digital-idiot's clarification on shapes was helpful. The API has changed significantly since 2022 — here's the current approach (v1.9.0).

For binary segmentation masks, use the task-specific classes:

from torchmetrics.classification import BinaryRecall, BinaryJaccardIndex

# preds: (N, H, W) — binary predictions (0 or 1)
# target: (N, H, W) — binary ground truth
recall = BinaryRecall()
jaccard = BinaryJaccardIndex()

# Both accept flat or spatial tensors — they get flattened internally
score_r = recall(preds, target)
score_j = jaccard(preds, target)

For per-image scores (which was unanswered in the original thread):

TorchMetrics computes globally across the batch by default. To get per-i…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Borda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants