ocl.metrics.dataset
Metrics computed on a whole dataset.
DatasetSemanticMaskIoUMetric
Bases: torchmetrics.Metric
Unsupervised IoU metric for semantic segmentation using dataset-wide matching of classes.
The input to this metric is an instance-level mask with objects, and a class id for each object. This is required to convert the mask to semantic classes. The number of classes for the predictions does not have to match the true number of classes.
Note that contrary to the other metrics in this module, this metric is not supposed to be added
in the online metric computation loop, which is why it does not inherit from RoutableMixin
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_predicted_classes |
int
|
Number of predictable classes, i.e. highest prediction class id that can occur. |
required |
n_classes |
int
|
Total number of classes, i.e. highest class id that can occur. |
required |
threshold |
float
|
Value to use for thresholding masks. |
0.5
|
use_threshold |
bool
|
If |
False
|
matching |
str
|
Method to produce matching between clusters and ground truth classes. If "hungarian", assigns each class one cluster such that the total IoU is maximized. If "majority", assigns each cluster to the class with the highest IoU (each class can be assigned multiple clusters). |
'hungarian'
|
ignore_background |
bool
|
If true, pixels labeled as background (class zero) in the ground truth are not taken into account when computing IoU. |
False
|
use_unmatched_as_background |
bool
|
If true, count predicted classes not selected after Hungarian matching as the background predictions. |
False
|
Source code in ocl/metrics/dataset.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 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 267 |
|
update
Update metric by computing confusion matrix between predicted and target classes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
predictions |
torch.Tensor
|
Probability mask of shape (B, K, H, W) or (B, F, K, H, W), where K is the number of object instances in the image. |
required |
targets |
torch.Tensor
|
Mask of shape (B, K, H, W) or (B, F, K, H, W), where K is the number of object instances in the image. Class ID of objects is encoded as the value, i.e. densely represented. |
required |
prediction_class_ids |
torch.Tensor
|
Tensor of shape (B, K), containing the class id of each predicted object instance in the image. Id must be 0 <= id <= n_predicted_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/dataset.py
preprocess_predicted_mask
Preprocess predicted masks for metric computation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mask |
torch.Tensor
|
Probability mask of shape (B, K, H, W) or (B, F, K, H, W), where K is the number of object instances in the prediction. |
required |
Returns:
Type | Description |
---|---|
torch.Tensor
|
Binary tensor of shape (B, P, K), where P is the number of points. If |
torch.Tensor
|
True, overlapping objects for the same point are possible. |
Source code in ocl/metrics/dataset.py
preprocess_ground_truth_mask
Preprocess ground truth mask for metric computation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mask |
torch.Tensor
|
Mask of shape (B, K, H, W) or (B, F, K, H, W), where K is the number of object instances in the image. Class ID of objects is encoded as the value, i.e. densely represented. |
required |
Returns:
Type | Description |
---|---|
torch.Tensor
|
One-hot tensor of shape (B, P, J), where J is the number of the classes and P the number |
torch.Tensor
|
of points, with object instances with the same class ID merged together. In the case of |
torch.Tensor
|
an overlap of classes for a point, the class with the highest ID is assigned to that |
torch.Tensor
|
point. |
Source code in ocl/metrics/dataset.py
compute
Compute per-class IoU using matching.
Source code in ocl/metrics/dataset.py
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 |
|
SklearnClustering
Wrapper around scikit-learn clustering algorithms.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_clusters |
int
|
Number of clusters. |
required |
method |
str
|
Clustering method to use. |
'kmeans'
|
clustering_kwargs |
Optional[Dict[str, Any]]
|
Dictionary of additional keyword arguments to pass to clustering object. |
None
|
use_l2_normalization |
bool
|
Whether to L2 normalize the representations before clustering (but after PCA). |
False
|
use_pca |
bool
|
Whether to apply PCA before fitting the clusters. |
False
|
pca_dimensions |
Optional[int]
|
Number of dimensions for PCA dimensionality reduction. If |
None
|
pca_kwargs |
Optional[Dict[str, Any]]
|
Dictionary of additional keyword arguments to pass to PCA object. |
None
|
Source code in ocl/metrics/dataset.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
|