Update SSIM metric to return contrastive sensitivity#5550
Merged
wyli merged 10 commits intoProject-MONAI:devfrom Nov 24, 2022
Merged
Update SSIM metric to return contrastive sensitivity#5550wyli merged 10 commits intoProject-MONAI:devfrom
wyli merged 10 commits intoProject-MONAI:devfrom
Conversation
…te unit test to cover changes Signed-off-by: PedroFerreiradaCosta <[email protected]>
Signed-off-by: PedroFerreiradaCosta <[email protected]>
Signed-off-by: PedroFerreiradaCosta <[email protected]>
…struct _compute_metric superclass dependency Signed-off-by: PedroFerreiradaCosta <[email protected]>
Signed-off-by: PedroFerreiradaCosta <[email protected]>
Signed-off-by: PedroFerreiradaCosta <[email protected]>
Signed-off-by: PedroFerreiradaCosta <[email protected]>
Contributor
|
the latest mypy reports some typing issues https://github.com/Project-MONAI/MONAI/actions/runs/3531335280/jobs/5924380826, if it can't be reproduced locally, please upgrade mypy |
Signed-off-by: PedroFerreiradaCosta <[email protected]>
wyli
approved these changes
Nov 24, 2022
Contributor
|
/build |
1 task
wyli
pushed a commit
that referenced
this pull request
Dec 9, 2022
Fixes #5668 . ### Description The SSIM loss wasn't feeding into autograd - it wasn't allowing gradient to be calculated. Now they can be calculated. As per my previous PR (#5550), the loss function is now calculated using the SSIMMetric (and not the other way around). The SSIMMetric in inheriting from class `IterationMetric` that runs `.detach()` on all inputs before running `._compute_tensor()`. https://github.com/Project-MONAI/MONAI/blob/0737a33d62ce1e18023712a000828235b7758536/monai/metrics/metric.py#L70 I'm now calling the `SSIMMetric()._compute_tensor()` explicitly, removing the step where it detaches from the current graph. **To Reproduce** ``` import torch from monai.losses.ssim_loss import SSIMLoss x = torch.ones([1,1,10,10])/2 y = torch.ones([1,1,10,10])/2 y.requires_grad_(True) data_range = x.max().unsqueeze(0) loss = SSIMLoss(spatial_dims=2)(x,y,data_range) print(loss.requires_grad) ``` **Expected behavior** `loss.requires_grad` will now be True. ### Types of changes - [x] Non-breaking change (fix or new feature that would not break existing functionality). Signed-off-by: PedroFerreiradaCosta <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Signed-off-by: PedroFerreiradaCosta [email protected]
Fixes #5417 .
Description
Makes SSIM loss depend on metric instead of the other way around (the loss was computing the metric).
Returns contrastive sensitivity if the boolean
fullis True when calling_compute_metric()Adds unit test to
test_ssim_metric.pyto check if contrastive sensitivity output is working as expected.Types of changes
./runtests.sh --quick --unittests --disttests.make htmlcommand in thedocs/folder.