Skip to content
Discussion options

You must be logged in to vote

@tridivb — the shape handling issue (Nx1xHxW vs NxHxW) was a real pain point with the old unified API. Completely resolved with task-specific metrics in v1.9.0.

For binary segmentation with sigmoid output (Nx1xHxW):

from torchmetrics.classification import BinaryAccuracy, BinaryF1Score, BinaryJaccardIndex

# Squeeze the channel dim
preds = model(x).squeeze(1)  # (N, H, W) — sigmoid probabilities
target = target               # (N, H, W) — 0 or 1

acc = BinaryAccuracy(multidim_average="global")
f1 = BinaryF1Score(multidim_average="global")
iou = BinaryJaccardIndex()

acc(preds, target)
f1(preds, target)
iou(preds, target)

Key differences from the old API:

  • No more num_classes for binary tasks

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
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
2 participants