Accuracy Metric does not perform squeeze on input data #1233
-
|
Hello, I am not sure if this is a bug or not but according to https://torchmetrics.readthedocs.io/en/stable/pages/classification.html#input-types, prediction tensor is squeezed starting from dimension one. Accuracy seems not performing such operation and in validity checks raised an error:
This works ok, whilst when
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
@jungla88 — this was a real issue with the old unified Use from torchmetrics.classification import BinaryAccuracy
acc = BinaryAccuracy()
preds = torch.tensor([0.4, 0.51, 0.51, 0.6, 0.7])
target = torch.tensor([0, 1, 0, 0, 1])
# Works with 1D
acc(preds, target) # tensor(0.6000)
# Also works with extra dim — internally handled
acc(preds.unsqueeze(1), target) # same result, no errorFor spatial predictions (segmentation): acc = BinaryAccuracy(multidim_average="global") # flatten all spatial dims
acc = BinaryAccuracy(multidim_average="samplewise") # per-sample accuracyThe old
Docs: Accuracy |
Beta Was this translation helpful? Give feedback.
@jungla88 — this was a real issue with the old unified
Accuracyclass but has been resolved by the task-specific API refactor. As of v1.9.0:Use
BinaryAccuracyfor binary classification:For spatial predictions (segmentation):