ocl.metrics.masks
Metrics related to the evaluation of masks.
ARIMetric
Bases: torchmetrics.Metric
Computes ARI metric.
Source code in ocl/metrics/masks.py
update
Update this metric.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prediction |
torch.Tensor
|
Predicted mask of shape (B, C, H, W) or (B, F, C, H, W), where C is the number of classes. |
required |
target |
torch.Tensor
|
Ground truth mask of shape (B, K, H, W) or (B, F, K, H, W), where K is the number of classes. |
required |
ignore |
Optional[torch.Tensor]
|
Ignore mask of shape (B, 1, H, W) or (B, 1, K, H, W) |
None
|
Source code in ocl/metrics/masks.py
PatchARIMetric
Bases: ARIMetric
Computes ARI metric assuming patch masks as input.
Source code in ocl/metrics/masks.py
update
Update this metric.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prediction |
torch.Tensor
|
Predicted mask of shape (B, C, P) or (B, F, C, P), where C is the number of classes and P the number of patches. |
required |
target |
torch.Tensor
|
Ground truth mask of shape (B, K, H, W) or (B, F, K, H, W), where K is the number of classes. |
required |
Source code in ocl/metrics/masks.py
UnsupervisedMaskIoUMetric
Bases: torchmetrics.Metric
Computes IoU metric for segmentation masks when correspondences to ground truth are not known.
Uses Hungarian matching to compute the assignment between predicted classes and ground truth classes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
use_threshold |
bool
|
If |
False
|
threshold |
float
|
Value to use for thresholding masks. |
0.5
|
matching |
str
|
Approach to match predicted to ground truth classes. For "hungarian", computes assignment that maximizes total IoU between all classes. For "best_overlap", uses the predicted class with maximum overlap for each ground truth class. Using "best_overlap" leads to the "average best overlap" metric. |
'hungarian'
|
compute_discovery_fraction |
bool
|
Instead of the IoU, compute the fraction of ground truth classes that were "discovered", meaning that they have an IoU greater than some threshold. |
False
|
correct_localization |
bool
|
Instead of the IoU, compute the fraction of images on which at least one ground truth class was correctly localised, meaning that they have an IoU greater than some threshold. |
False
|
discovery_threshold |
float
|
Minimum IoU to count a class as discovered/correctly localized. |
0.5
|
ignore_background |
bool
|
If true, assume class at index 0 of ground truth masks is background class that is removed before computing IoU. |
False
|
ignore_overlaps |
bool
|
If true, remove points where ground truth masks has overlappign classes from predictions and ground truth masks. |
False
|
Source code in ocl/metrics/masks.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
|
update
Update this metric.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prediction |
torch.Tensor
|
Predicted mask of shape (B, C, H, W) or (B, F, C, H, W), where C is the number of classes. Assumes class probabilities as inputs. |
required |
target |
torch.Tensor
|
Ground truth mask of shape (B, K, H, W) or (B, F, K, H, W), where K is the number of classes. |
required |
ignore |
Optional[torch.Tensor]
|
Ignore mask of shape (B, 1, H, W) or (B, 1, K, H, W) |
None
|
Source code in ocl/metrics/masks.py
unsupervised_mask_iou
Compute intersection-over-union (IoU) between masks with unknown class correspondences.
This metric is also known as Jaccard index. Note that this is a non-batched implementation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pred_mask |
torch.Tensor
|
Predicted mask of shape (C, N), where C is the number of predicted classes and N is the number of points. Masks are assumed to be binary. |
required |
true_mask |
torch.Tensor
|
Ground truth mask of shape (K, N), where K is the number of ground truth classes and N is the number of points. Masks are assumed to be binary. |
required |
matching |
str
|
How to match predicted classes to ground truth classes. For "hungarian", computes assignment that maximizes total IoU between all classes. For "best_overlap", uses the predicted class with maximum overlap for each ground truth class (each predicted class can be assigned to multiple ground truth classes). Empty ground truth classes are assigned IoU of zero. |
'hungarian'
|
reduction |
str
|
If "mean", return IoU averaged over classes. If "none", return per-class IoU. |
'mean'
|
iou_empty |
float
|
IoU for the case when a class does not occur, but was also not predicted. |
0.0
|
Returns:
Type | Description |
---|---|
torch.Tensor
|
Mean IoU over classes if reduction is |
torch.Tensor
|
otherwise. |