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

Add __repr__ and __str__ to Metrics baseclass #7487

Merged
merged 4 commits into from
Feb 28, 2024
Merged

Add __repr__ and __str__ to Metrics baseclass #7487

merged 4 commits into from
Feb 28, 2024

Conversation

MathijsdeBoer
Copy link
Contributor

@MathijsdeBoer MathijsdeBoer commented Feb 22, 2024

Description

When training a model using MONAI metrics for experiment tracking, I tend to log which metrics I am using. Unfortunately, just sending the metrics objects to Tensorboard will result in a list like [CustomMetric1, CustomMetric2, <monai.metrics.Metric ...>, etc.]

Adding __repr__ and __str__ methods to the base class will solve this small annoyance. The current implementation will only return the class name, but if a certain metric would wish to report more data for its __repr__ string, this can be easily overridden in any subclass.

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.

@MathijsdeBoer
Copy link
Contributor Author

Ideally one would exist for the Loss classes, too. But the baseclass for them is torch.nn.modules.loss._Loss, so either one could make a subclass of that class, add the __repr__ and __str__ methods to it, and point all existing loss classes to the new one instead, or these methods could be added to the baseclass in PyTorch with a pull request in that project.

KumoLiu and others added 2 commits February 22, 2024 14:22
Fixes #7013 #7478

### Description
replace `predict_from_raw_data` with `nnUNetPredictor` in
test_nnunetv2runner

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] 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.

---------

Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
@MathijsdeBoer
Copy link
Contributor Author

I always forget to do the signoff for these pull requests, followed the rebase method on the details page to fix it!

monai/metrics/metric.py Outdated Show resolved Hide resolved
@KumoLiu KumoLiu requested review from ericspod and Nic-Ma February 23, 2024 06:12
Mathijs de Boer and others added 2 commits February 27, 2024 14:44
Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
@KumoLiu
Copy link
Contributor

KumoLiu commented Feb 27, 2024

/build

2 similar comments
@KumoLiu
Copy link
Contributor

KumoLiu commented Feb 28, 2024

/build

@KumoLiu
Copy link
Contributor

KumoLiu commented Feb 28, 2024

/build

@KumoLiu KumoLiu merged commit 9830525 into Project-MONAI:dev Feb 28, 2024
28 checks passed
juampatronics pushed a commit to juampatronics/MONAI that referenced this pull request Mar 25, 2024
### Description

When training a model using MONAI metrics for experiment tracking, I
tend to log which metrics I am using. Unfortunately, just sending the
metrics objects to Tensorboard will result in a list like
[CustomMetric1, CustomMetric2, <monai.metrics.Metric ...>, etc.]

Adding `__repr__` and `__str__` methods to the base class will solve
this small annoyance. The current implementation will only return the
class name, but if a certain metric would wish to report more data for
its `__repr__` string, this can be easily overridden in any subclass.

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] 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.

---------

Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
Co-authored-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Co-authored-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
Signed-off-by: Juan Pablo de la Cruz Gutiérrez <juampatronics@gmail.com>
Yu0610 pushed a commit to Yu0610/MONAI that referenced this pull request Apr 11, 2024
### Description

When training a model using MONAI metrics for experiment tracking, I
tend to log which metrics I am using. Unfortunately, just sending the
metrics objects to Tensorboard will result in a list like
[CustomMetric1, CustomMetric2, <monai.metrics.Metric ...>, etc.]

Adding `__repr__` and `__str__` methods to the base class will solve
this small annoyance. The current implementation will only return the
class name, but if a certain metric would wish to report more data for
its `__repr__` string, this can be easily overridden in any subclass.

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] 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.

---------

Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
Co-authored-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Co-authored-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
Signed-off-by: Yu0610 <612410030@alum.ccu.edu.tw>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants