Skip to content

Commit

Permalink
Allow evaluating predictions with only background (#23)
Browse files Browse the repository at this point in the history
In the previous implementation, having no lesion candidates broke the evaluation.
Added tests for having zero or one lesion candidate.
  • Loading branch information
joeranbosma authored Nov 1, 2024
1 parent e499134 commit cc134eb
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def run(self):
long_description = fh.read()

setuptools.setup(
version='1.4.9', # also update version in metrics.py -> version
version='1.4.10', # also update version in metrics.py -> version
author_email='[email protected]',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
9 changes: 7 additions & 2 deletions src/picai_eval/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,13 @@ def calculate_counts(self, subject_list: Optional[List[str]] = None) -> "Dict[st
TP[i] = tp

# extend curve to infinity
TP[-1] = TP[-2]
FP[-1] = np.inf
if len(TP) >= 2:
TP[-1] = TP[-2]
FP[-1] = np.inf
else:
# no lesions detected
TP = np.array([0, 0])
FP = np.array([0, np.inf])

return {
'TP': TP,
Expand Down
4 changes: 2 additions & 2 deletions tests/Development-README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ AutoPEP8 for formatting (this can be done automatically on save, see e.g. https:
# Push release to PyPI
1. Increase version in setup.py, and set below
2. Build: `python -m build`
3. Test package distribution: `python -m twine upload --repository testpypi dist/*1.4.9*`
4. Distribute package to PyPI: `python -m twine upload dist/*1.4.9*`
3. Test package distribution: `python -m twine upload --repository testpypi dist/*1.4.10*`
4. Distribute package to PyPI: `python -m twine upload dist/*1.4.10*`
44 changes: 44 additions & 0 deletions tests/test_calculate_counts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import numpy as np

from picai_eval import Metrics


def test_calculate_counts():
"""
Test the lesion TPR and FPR function
"""
lesion_results = {
"0": [(0, 0, 0.)],
"1": [(0, 0, 0.)],
"2": [(1, 1, 0.)],
"3": [(1, 0, 0.), (1, 0, 0.)],
"4": [(0, 0, 0.)],
"5": [(1, 0, 0.), (1, 0, 0.)],
}
metrics = Metrics(lesion_results=lesion_results)
np.testing.assert_allclose(metrics.lesion_TPR, [0.2, 0.2])
np.testing.assert_allclose(metrics.lesion_FPR, [0.0, np.inf])
assert metrics.AP == 0.2


def test_calculate_counts_empty():
"""
Test the lesion TPR and FPR function
"""
lesion_results = {
"0": [(0, 0, 0.)],
"1": [(0, 0, 0.)],
"2": [(1, 0, 0.)],
"3": [(1, 0, 0.), (1, 0, 0.)],
"4": [(0, 0, 0.)],
"5": [(1, 0, 0.), (1, 0, 0.)],
}
metrics = Metrics(lesion_results=lesion_results)
np.testing.assert_allclose(metrics.lesion_TPR, [0., 0.0])
np.testing.assert_allclose(metrics.lesion_FPR, [0.0, np.inf])
assert metrics.AP == 0.0


if __name__ == "__main__":
test_calculate_counts()
test_calculate_counts_empty()

0 comments on commit cc134eb

Please sign in to comment.