Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow evaluating with no lesion candidates #23

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading