Skip to content
Snippets Groups Projects
Commit ae439031 authored by Daniel CARRON's avatar Daniel CARRON :b:
Browse files

Moved computation of binary mask to its own function

parent f01f65e4
No related branches found
No related tags found
1 merge request!12Adds grad-cam support on classifiers
......@@ -260,6 +260,40 @@ def _compute_proportional_energy(
return float(numpy.sum(saliency_map * gt_mask) / denominator) # type: ignore
def _compute_binary_mask(
gt_bboxes: BoundingBoxes,
saliency_map: numpy.typing.NDArray[numpy.double],
) -> numpy.typing.NDArray[numpy.bool_]:
"""Computes a binary mask for the saliency map using BoundingBoxes.
The binary_mask will be ON/True where the gt boxes are located.
Parameters
----------
gt_bboxes
Ground-truth bounding boxes in the format ``(x, y, width,
height)``.
saliency_map
A real-valued saliency-map that conveys regions used for
classification in the original sample.
Returns
-------
A numpy array of the same size as saliency_map with
the value False everywhere except at the positions inside
the bounding boxes, which will be True.
"""
binary_mask = numpy.zeros_like(saliency_map, dtype=numpy.bool_)
for bbox in gt_bboxes:
binary_mask[
bbox.ymin : bbox.ymin + bbox.height,
bbox.xmin : bbox.xmin + bbox.width,
] = True
return binary_mask
def _process_sample(
gt_bboxes: BoundingBoxes,
saliency_map: numpy.typing.NDArray[numpy.double],
......@@ -291,13 +325,7 @@ def _process_sample(
# # Calculate localization metrics
# iou, ioda = _compute_max_iou_and_ioda(detected_box, gt_bboxes)
# The binary_mask will be ON/True where the gt boxes are located
binary_mask = numpy.zeros_like(saliency_map, dtype=numpy.bool_)
for bbox in gt_bboxes:
binary_mask[
bbox.ymin : bbox.ymin + bbox.height,
bbox.xmin : bbox.xmin + bbox.width,
] = True
binary_mask = _compute_binary_mask(gt_bboxes, saliency_map)
return (
# iou,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment