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 loss_fn to IgniteMetric and rename to IgniteMetricHandler #6695

Merged
merged 27 commits into from
Jul 13, 2023

Conversation

matt3o
Copy link
Contributor

@matt3o matt3o commented Jul 3, 2023

Description

As explained in #6693 I would like to use the DiceCELoss as a train metric as well. This branch adds a very crude but working version of that.
The added tests, which I copied from the MeanDice metric, do still fail. It would be cool if someone more experienced could check, what needs to be done there.
I ran the code with my full DeepEdit setup and it appears to be working just fine there.

No formatting checks done so far - I want to find out first if this code is useful for others. Docs not updated yet either.

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.

matt3o and others added 3 commits July 3, 2023 20:18
Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
matt3o and others added 3 commits July 4, 2023 13:14
Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
monai/handlers/dice_ce_metric.py Outdated Show resolved Hide resolved
monai/handlers/ignite_loss_metric.py Outdated Show resolved Hide resolved
monai/handlers/ignite_loss_metric.py Outdated Show resolved Hide resolved
monai/handlers/ignite_loss_metric.py Outdated Show resolved Hide resolved
monai/handlers/ignite_loss_metric.py Outdated Show resolved Hide resolved
monai/handlers/ignite_loss_metric.py Outdated Show resolved Hide resolved
monai/handlers/ignite_loss_metric.py Outdated Show resolved Hide resolved
@matt3o
Copy link
Contributor Author

matt3o commented Jul 5, 2023

Okay, I will implement the changes this weekend. Just to make sure I am understanding you @wyli and @ericspod correctly:

  1. I will delete all the code added so far (so no new class IgniteLossMetric) and
  2. move it to IgniteMetric where it will become the new loss_fn parameter
  3. I'll add a few new tests for that. If anyone has any ideas what would be could possibly even with the expected outcome, that would be nice.
  4. (optional) I'll check out if I can change the name of IgniteMetric to IgniteMetricHandler easily

Sounds good?

@wyli
Copy link
Contributor

wyli commented Jul 5, 2023

Okay, I will implement the changes this weekend. Just to make sure I am understanding you @wyli and @ericspod correctly:

  1. I will delete all the code added so far (so no new class IgniteLossMetric) and
  2. move it to IgniteMetric where it will become the new loss_fn parameter
  3. I'll add a few new tests for that. If anyone has any ideas what would be could possibly even with the expected outcome, that would be nice.
  4. (optional) I'll check out if I can change the name of IgniteMetric to IgniteMetricHandler easily

Sounds good?

thanks @matt3o, the plan looks good to me.

@ericspod
Copy link
Member

ericspod commented Jul 6, 2023

Sounds good?

Sounds good to me too. If changing the name isn't a big problem we should do it but keep IgniteMetric as an alias. We can discuss how to do a deprecation warning for it later as well.

matt3o and others added 6 commits July 10, 2023 08:32
Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
@matt3o
Copy link
Contributor Author

matt3o commented Jul 10, 2023

I started the implementation as discussed. Also I added a first test and copied it over from MeanDice to TestHandlerIgniteMetricHandler. I am using the DiceLoss as the training loss.
However the MeanDice appears to return the inverse value of the loss, so 1 - DiceLoss, i.e. 0.75 (MeanDice) instead of 0.25 (DiceLoss). This means the copied tests fail.
Now my question would be how to handle that. I can of course of simply change the tests to check for the loss result and thus 0.25.
Imho however LossMetric should convert the loss to a metric and thus return 0.75 instead of 0.25. However this might break quite a lot of code.
Shall I just leave this is it is and fix only the expected test values?

matt3o added 2 commits July 10, 2023 13:45
Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
@wyli
Copy link
Contributor

wyli commented Jul 10, 2023

Sure, please simply change the expected results, there would be some discrepancies between MeanDice and DiceLoss…

matt3o added 3 commits July 11, 2023 10:10
Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
@matt3o matt3o force-pushed the Add_dice_ce_metric branch from 8c173fc to acceeab Compare July 11, 2023 09:08
@matt3o
Copy link
Contributor Author

matt3o commented Jul 11, 2023

Finally I need instructions how to generate the alias and how to set the rename warning for IgniteMetricHandler. Apart from that the code is already running and all tests should pass. I updated the class name in the docs, tell me if there is anything more to do.

matt3o added 2 commits July 11, 2023 11:18
Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
@wyli
Copy link
Contributor

wyli commented Jul 11, 2023

Finally I need instructions how to generate the alias and how to set the rename warning for IgniteMetricHandler. Apart from that the code is already running and all tests should pass. I updated the class name in the docs, tell me if there is anything more to do.

looks good to me, please add the unit tests to this list https://github.com/Project-MONAI/MONAI/blob/dev/tests/min_tests.py#L75 so that it's skipped when running in a minimal environment

@matt3o matt3o force-pushed the Add_dice_ce_metric branch from 73f4a84 to b800496 Compare July 11, 2023 12:45
matt3o and others added 3 commits July 11, 2023 14:46
Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
for more information, see https://pre-commit.ci

Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
@matt3o matt3o force-pushed the Add_dice_ce_metric branch from b800496 to c8027b2 Compare July 11, 2023 12:46
Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
@matt3o matt3o force-pushed the Add_dice_ce_metric branch from 8d93ea0 to eaf7fd0 Compare July 12, 2023 18:31
Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
@matt3o matt3o force-pushed the Add_dice_ce_metric branch from eaf7fd0 to 966c99a Compare July 12, 2023 18:50
@wyli
Copy link
Contributor

wyli commented Jul 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.

thanks, it looks good to me, premerge tests all good

@wyli wyli requested a review from Nic-Ma July 12, 2023 20:15
Signed-off-by: Matthias Hadlich <matthiashadlich@posteo.de>
@matt3o matt3o changed the title Add DiceCEMetric Add loss_fn to IgniteMetric and rename to IgniteMetricHandler Jul 13, 2023
@wyli
Copy link
Contributor

wyli commented Jul 13, 2023

/build

@wyli wyli marked this pull request as ready for review July 13, 2023 08:20
@wyli wyli enabled auto-merge (squash) July 13, 2023 08:20
@wyli wyli merged commit c1c0cdc into Project-MONAI:dev Jul 13, 2023
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.

4 participants