Skip to content

Commit 07b3137

Browse files
committed
revert filters
1 parent ff6695c commit 07b3137

5 files changed

Lines changed: 257 additions & 206 deletions

File tree

src/valor_lite/semantic_segmentation/computation.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,59 @@ def compute_label_metadata(
2929
return label_metadata
3030

3131

32+
def filter_cache(
33+
confusion_matrices: NDArray[np.int64],
34+
datum_mask: NDArray[np.bool_],
35+
label_mask: NDArray[np.bool_],
36+
number_of_labels: int,
37+
) -> tuple[NDArray[np.int64], NDArray[np.int64]]:
38+
"""
39+
Performs the filter operation over the internal cache.
40+
41+
Parameters
42+
----------
43+
confusion_matrices : NDArray[int64]
44+
The internal evaluator cache.
45+
datum_mask : NDArray[bool]
46+
A mask that filters out datums.
47+
datum_mask : NDArray[bool]
48+
A mask that filters out labels.
49+
50+
Returns
51+
-------
52+
NDArray[int64]
53+
Filtered confusion matrices.
54+
NDArray[int64]
55+
Filtered label metadata.
56+
"""
57+
if label_mask.any():
58+
# add filtered labels to background
59+
null_predictions = confusion_matrices[:, label_mask, :].sum(
60+
axis=(1, 2)
61+
)
62+
null_groundtruths = confusion_matrices[:, :, label_mask].sum(
63+
axis=(1, 2)
64+
)
65+
null_intersection = (
66+
confusion_matrices[:, label_mask, label_mask]
67+
.reshape(confusion_matrices.shape[0], -1)
68+
.sum(axis=1)
69+
)
70+
confusion_matrices[:, 0, 0] += (
71+
null_groundtruths + null_predictions - null_intersection
72+
)
73+
confusion_matrices[:, label_mask, :] = 0
74+
confusion_matrices[:, :, label_mask] = 0
75+
76+
confusion_matrices = confusion_matrices[datum_mask]
77+
78+
label_metadata = compute_label_metadata(
79+
confusion_matrices=confusion_matrices,
80+
n_labels=number_of_labels,
81+
)
82+
return confusion_matrices, label_metadata
83+
84+
3285
def compute_intermediate_confusion_matrices(
3386
groundtruths: NDArray[np.bool_],
3487
predictions: NDArray[np.bool_],

0 commit comments

Comments
 (0)