From d0efb620deec4634d5f3d963f32e7d0704e33914 Mon Sep 17 00:00:00 2001 From: Zeeshan Modi <92383127+Zeesejo@users.noreply.github.com> Date: Sat, 11 Apr 2026 20:11:37 +0200 Subject: [PATCH 1/2] Fix: swap input_amplitude and target_amplitude in JukeboxLoss.forward Fixes #8820 - input_amplitude was incorrectly computed from `target` and target_amplitude from `input`. Corrected to match semantic meaning and standard forward(input, target) convention. Signed-off-by: Zeeshan Modi <92383127+Zeesejo@users.noreply.github.com> --- monai/losses/spectral_loss.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monai/losses/spectral_loss.py b/monai/losses/spectral_loss.py index 06714f3993..fcba03f132 100644 --- a/monai/losses/spectral_loss.py +++ b/monai/losses/spectral_loss.py @@ -55,8 +55,8 @@ def __init__( self.fft_norm = fft_norm def forward(self, input: torch.Tensor, target: torch.Tensor) -> torch.Tensor: - input_amplitude = self._get_fft_amplitude(target) - target_amplitude = self._get_fft_amplitude(input) + input_amplitude = self._get_fft_amplitude(input) + target_amplitude = self._get_fft_amplitude(target) # Compute distance between amplitude of frequency components # See Section 3.3 from https://arxiv.org/abs/2005.00341 From 4417d79b54de36f2677fc32e70cfa246a104f097 Mon Sep 17 00:00:00 2001 From: Zeeshan Modi <92383127+Zeesejo@users.noreply.github.com> Date: Sat, 11 Apr 2026 20:39:24 +0200 Subject: [PATCH 2/2] Fix: remove redundant `1-` from SSIMLoss docstring examples Fixes #8822 - The forward() docstring examples used `print(1-SSIMLoss()(x,y))`, but SSIMLoss already computes 1-ssim internally. The `1-` prefix made examples return ssim (not loss), misleading users into training with inverted loss. Signed-off-by: Zeeshan Modi <92383127+Zeesejo@users.noreply.github.com> --- monai/losses/ssim_loss.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/monai/losses/ssim_loss.py b/monai/losses/ssim_loss.py index 8ee1da7267..3fa578da29 100644 --- a/monai/losses/ssim_loss.py +++ b/monai/losses/ssim_loss.py @@ -111,17 +111,17 @@ def forward(self, input: torch.Tensor, target: torch.Tensor) -> torch.Tensor: # 2D data x = torch.ones([1,1,10,10])/2 y = torch.ones([1,1,10,10])/2 - print(1-SSIMLoss(spatial_dims=2)(x,y)) + print(SSIMLoss(spatial_dims=2)(x,y)) # pseudo-3D data x = torch.ones([1,5,10,10])/2 # 5 could represent number of slices y = torch.ones([1,5,10,10])/2 - print(1-SSIMLoss(spatial_dims=2)(x,y)) + print(SSIMLoss(spatial_dims=2)(x,y)) # 3D data x = torch.ones([1,1,10,10,10])/2 y = torch.ones([1,1,10,10,10])/2 - print(1-SSIMLoss(spatial_dims=3)(x,y)) + print(SSIMLoss(spatial_dims=3)(x,y)) """ ssim_value = self.ssim_metric._compute_tensor(input, target).view(-1, 1) loss: torch.Tensor = 1 - ssim_value