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

5740 metrics reloaded support #5741

Merged
merged 22 commits into from
Jan 12, 2023

Conversation

brudfors
Copy link
Contributor

@brudfors brudfors commented Dec 14, 2022

Signed-off-by: Mikael Brudfors [email protected]

part of #5740

Description

Makes the binary and categorical metrics from MetricsReloaded available in MONAI via a wrapper module (monai/metrics/wrapper.py).

This module allows to use the MetricsReloaded metrics as, e.g.:

import torch
from monai.metrics import MetricsReloadedBinary

metric_name = "Cohens Kappa"
metric = MetricsReloadedBinary(metric_name=metric_name)

# first iteration
# shape [batch=1, channel=1, 2, 2]
y_pred = torch.tensor([[[[1.0, 0.0], [0.0, 1.0]]]])
y = torch.tensor([[[[1.0, 0.0], [1.0, 1.0]]]])
print(metric(y_pred, y))

# second iteration
# shape [batch=1, channel=1, 2, 2]
y_pred = torch.tensor([[[[1.0, 0.0], [0.0, 0.0]]]])
y = torch.tensor([[[[1.0, 0.0], [1.0, 1.0]]]])
print(metric(y_pred, y))

# aggregate
# shape ([batch=2, channel=1])
print(metric.aggregate(reduction="none"))  # tensor([[0.5], [0.2]])

# reset
metric.reset()

Tests of all metrics are in tests/test_metrics_reloaded.py.

Note that MetricsReloaded is an optional dependency of MONAI; so in order to use the wrapper, MONAI needs to be installed with:

pip install '.[metricsreloaded]'

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

monai/metrics/wrapper.py Outdated Show resolved Hide resolved
@wyli
Copy link
Contributor

wyli commented Dec 14, 2022

/black
it looks great, any feedback and things we can improve for better integration (from both monai and MetricsReloaded perspectives)? I think once we confirm MetricsReloaded's API is stable, this PR can be merged

Signed-off-by: Mikael Brudfors <[email protected]>
@brudfors
Copy link
Contributor Author

it looks great, any feedback and things we can improve for better integration (from both monai and MetricsReloaded perspectives)? I think once we confirm MetricsReloaded's API is stable, this PR can be merged

Sounds good!

This PR is limited to supporting the semantic segmentation metrics from MetricsReloaded and for that I cannot, for now, think of any improvements on the MONAI side. This might change when we integrate the instance segmentation and object detection metrics, later down the line. On the MetricsReloaded side, there are still some improvements that can be made, but I don't think they would require changing the API that MONAI uses.

requirements-dev.txt Show resolved Hide resolved
monai/metrics/wrapper.py Show resolved Hide resolved
monai/metrics/wrapper.py Outdated Show resolved Hide resolved
monai/metrics/wrapper.py Show resolved Hide resolved
monai/metrics/wrapper.py Outdated Show resolved Hide resolved
@wyli
Copy link
Contributor

wyli commented Jan 12, 2023

/build

Copy link
Contributor

@wyli wyli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll add the ignite wrapper in a separate pr

@wyli wyli enabled auto-merge (squash) January 12, 2023 16:46
@wyli
Copy link
Contributor

wyli commented Jan 12, 2023

/build

@wyli wyli merged commit 4b464e7 into Project-MONAI:dev Jan 12, 2023
@wyli wyli added this to the MetricsReloaded [P0 v1.2] milestone Jan 17, 2023
@wyli wyli mentioned this pull request Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants