Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions monai/losses/spectral_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines 57 to +59
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description indicates "In-line docstrings updated", but this diff only swaps the input_amplitude/target_amplitude assignments and doesn’t modify any docstrings/comments. Either update the PR checklist/description to match the actual change set or include the intended docstring update in this PR.

Copilot uses AI. Check for mistakes.

Comment on lines 57 to 60
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing unit tests for JukeboxLoss validate numeric output/shape, but they won’t fail if input/target amplitudes are swapped because MSE is symmetric. To prevent regressions of this specific semantics fix, consider adding a test that patches/spies on _get_fft_amplitude (e.g., via unittest.mock) and asserts it is called first with input and then with target inside forward().

Copilot uses AI. Check for mistakes.
# Compute distance between amplitude of frequency components
# See Section 3.3 from https://arxiv.org/abs/2005.00341
Expand Down
6 changes: 3 additions & 3 deletions monai/losses/ssim_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading