Skip to content

Update SSIM metric to return contrastive sensitivity#5550

Merged
wyli merged 10 commits intoProject-MONAI:devfrom
PedroFerreiradaCosta:dev
Nov 24, 2022
Merged

Update SSIM metric to return contrastive sensitivity#5550
wyli merged 10 commits intoProject-MONAI:devfrom
PedroFerreiradaCosta:dev

Conversation

@PedroFerreiradaCosta
Copy link
Copy Markdown
Contributor

@PedroFerreiradaCosta PedroFerreiradaCosta commented Nov 21, 2022

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 full is True when calling _compute_metric()
Adds unit test to test_ssim_metric.py to check if contrastive sensitivity output is working as expected.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • New tests added to cover the changes.
  • 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.

…te unit test to cover changes

Signed-off-by: PedroFerreiradaCosta <[email protected]>
@PedroFerreiradaCosta PedroFerreiradaCosta changed the title Updadte SSIM metric to return contrastive sensitivity Update SSIM metric to return contrastive sensitivity Nov 21, 2022
Signed-off-by: PedroFerreiradaCosta <[email protected]>
…struct _compute_metric superclass dependency

Signed-off-by: PedroFerreiradaCosta <[email protected]>
Signed-off-by: PedroFerreiradaCosta <[email protected]>
@PedroFerreiradaCosta PedroFerreiradaCosta marked this pull request as ready for review November 23, 2022 09:27
@wyli
Copy link
Copy Markdown
Contributor

wyli commented Nov 23, 2022

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 pip install -U mypy and then run the type check: ./runtests.sh --mypy

@wyli
Copy link
Copy Markdown
Contributor

wyli commented Nov 24, 2022

/build

@wyli wyli enabled auto-merge (squash) November 24, 2022 00:15
@wyli wyli merged commit f75693f into Project-MONAI:dev Nov 24, 2022
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]>
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.

Updating of the SSIM metric class to be compliable with the MS SSIM Metric

2 participants