Skip to content

Commit

Permalink
feat: set data_range as a property (#6788)
Browse files Browse the repository at this point in the history
Fixes #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]>
  • Loading branch information
SauravMaheshkar authored Jul 27, 2023
1 parent d89b457 commit 11546e8
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 11546e8

Please sign in to comment.