Skip to content

Commit

Permalink
feat: set data_range as a property (Project-MONAI#6788)
Browse files Browse the repository at this point in the history
Fixes Project-MONAI#6441 

### Description

Creates a setter method for `data_range` by setting it as a property
using the **`@property`** decorator.

### 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: Saurav Maheshkar <[email protected]>
Signed-off-by: KumoLiu <[email protected]>
  • Loading branch information
SauravMaheshkar authored and KumoLiu committed Jul 28, 2023
1 parent b18b31b commit c976790
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions monai/losses/ssim_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(
"""
super().__init__(reduction=LossReduction(reduction).value)
self.spatial_dims = spatial_dims
self.data_range = data_range
self._data_range = data_range
self.kernel_type = kernel_type

if not isinstance(win_size, Sequence):
Expand All @@ -77,14 +77,23 @@ def __init__(

self.ssim_metric = SSIMMetric(
spatial_dims=self.spatial_dims,
data_range=self.data_range,
data_range=self._data_range,
kernel_type=self.kernel_type,
win_size=self.kernel_size,
kernel_sigma=self.kernel_sigma,
k1=self.k1,
k2=self.k2,
)

@property
def data_range(self) -> float:
return self._data_range

@data_range.setter
def data_range(self, value: float) -> None:
self._data_range = value
self.ssim_metric.data_range = value

def forward(self, input: torch.Tensor, target: torch.Tensor) -> torch.Tensor:
"""
Args:
Expand Down

0 comments on commit c976790

Please sign in to comment.