Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

fix mean_iou and confusion_matrix type checkings

edgarribafef19f4c1228
diff --git a/torchgeometry/metrics/confusion_matrix.py b/torchgeometry/metrics/confusion_matrix.py
index 0d221f3dd..f77e73bd3 100644
--- a/torchgeometry/metrics/confusion_matrix.py
+++ b/torchgeometry/metrics/confusion_matrix.py
@@ -29,12 +29,12 @@ def confusion_matrix(
torch.Tensor: a tensor containing the confusion matrix with shape
:math:`(B, K, K)` where K is the number of classes.
"""
- if not isinstance(input, torch.LongTensor):
- raise TypeError("Input input type is not a torch.LongTensor. Got {}"
- .format(type(input)))
- if not isinstance(target, torch.LongTensor):
- raise TypeError("Input target type is not a torch.LongTensor. Got {}"
- .format(type(target)))
+ if not torch.is_tensor(input) and input.dtype is not torch.uint64:
+ raise TypeError("Input input type is not a torch.Tensor with "
+ "torch.int64 dtype. Got {}".format(type(input)))
+ if not torch.is_tensor(target) and target.dtype is not torch.uint64:
+ raise TypeError("Input target type is not a torch.Tensor with "
+ "torch.int64 dtype. Got {}".format(type(target)))
if not input.shape == target.shape:
raise ValueError("Inputs input and target must have the same shape. "
"Got: {}".format(input.shape, target.shape))
diff --git a/torchgeometry/metrics/mean_iou.py b/torchgeometry/metrics/mean_iou.py
index 67feaccf8..5be42166a 100644
--- a/torchgeometry/metrics/mean_iou.py
+++ b/torchgeometry/metrics/mean_iou.py
@@ -25,12 +25,12 @@ def mean_iou(
torch.Tensor: a tensor representing the mean intersection-over union
with shape :math:`(B, K)` where K is the number of classes.
"""
- if not isinstance(input, torch.LongTensor):
- raise TypeError("Input input type is not a torch.LongTensor. Got {}"
- .format(type(input)))
- if not isinstance(target, torch.LongTensor):
- raise TypeError("Input target type is not a torch.LongTensor. Got {}"
- .format(type(target)))
+ if not torch.is_tensor(input) and input.dtype is not torch.uint64:
+ raise TypeError("Input input type is not a torch.Tensor with "
+ "torch.int64 dtype. Got {}".format(type(input)))
+ if not torch.is_tensor(target) and target.dtype is not torch.uint64:
+ raise TypeError("Input target type is not a torch.Tensor with "
+ "torch.int64 dtype. Got {}".format(type(target)))
if not input.shape == target.shape:
raise ValueError("Inputs input and target must have the same shape. "
"Got: {}".format(input.shape, target.shape))