Skip to content

Commit 1af9a87

Browse files
committed
fix: exclude NaN scores from FROC counts
1 parent 1551cb8 commit 1af9a87

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎monai/metrics/froc.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ def compute_froc_curve_data(
149149
# smallest score) while avoiding a full scan of both arrays at every threshold.
150150
all_probs = sorted(set(list(fp_probs) + list(tp_probs)))
151151
thresholds = all_probs[1:]
152-
sorted_fp_probs = np.sort(fp_probs)
153-
sorted_tp_probs = np.sort(tp_probs)
152+
sorted_fp_probs = np.sort(fp_probs[~np.isnan(fp_probs)])
153+
sorted_tp_probs = np.sort(tp_probs[~np.isnan(tp_probs)])
154154
total_fps = len(sorted_fp_probs) - np.searchsorted(sorted_fp_probs, thresholds, side="left")
155155
total_tps = len(sorted_tp_probs) - np.searchsorted(sorted_tp_probs, thresholds, side="left")
156156
total_fps = np.append(total_fps, 0)

‎tests/metrics/test_compute_froc.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ def test_matches_reference(self, _, fp_probs, tp_probs):
199199
np.testing.assert_array_equal(actual_array, expected_array)
200200
self.assertEqual(actual_array.dtype, expected_array.dtype)
201201

202+
def test_nan_fp_probs_are_not_counted(self):
203+
fp_probs = np.asarray([np.nan])
204+
tp_probs = np.asarray([0.5, 0.8])
205+
fps_per_image, _ = compute_froc_curve_data(fp_probs, tp_probs, num_targets=2, num_images=1)
206+
np.testing.assert_array_equal(fps_per_image, np.zeros_like(fps_per_image))
207+
202208

203209
if __name__ == "__main__":
204210
unittest.main()

0 commit comments

Comments
 (0)