Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mednet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
medai
software
mednet
Commits
ae439031
Commit
ae439031
authored
1 year ago
by
Daniel CARRON
Browse files
Options
Downloads
Patches
Plain Diff
Moved computation of binary mask to its own function
parent
f01f65e4
No related branches found
No related tags found
1 merge request
!12
Adds grad-cam support on classifiers
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ptbench/engine/saliency/interpretability.py
+35
-7
35 additions, 7 deletions
src/ptbench/engine/saliency/interpretability.py
with
35 additions
and
7 deletions
src/ptbench/engine/saliency/interpretability.py
+
35
−
7
View file @
ae439031
...
...
@@ -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,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment