Skip to content

Fix PSNR/SSIM crashes on common inputs - #196

Merged
AnderBiguri merged 3 commits into
CambridgeCIA:mainfrom
cslht:fix/metrics-crashes
Aug 5, 2026
Merged

Fix PSNR/SSIM crashes on common inputs#196
AnderBiguri merged 3 commits into
CambridgeCIA:mainfrom
cslht:fix/metrics-crashes

Conversation

@cslht

@cslht cslht commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Four fixes in PSNR/SSIM:

  • unbatched mode passed torch tensors to skimage (TypeError); now uses the numpy-converted x_/target_.
  • SSIM defaulted to channel_axis=1, wrong for LION's channels-first layout — crashed on multichannel, silently wrong on 2D. Now None, inferred per sample.
  • vals[i] = skim_ssim(...) assigned a numpy.float32 into a torch tensor; wrapped in torch.tensor(...).
  • reduce=str | None was a default value, not a type hint, so calling without reduce always raised ValueError; now reduce: str | None = None.

- psnr/ssim: unbatched mode passed torch tensors to skimage (TypeError);
  now uses the numpy-converted x_/target_
- ssim: default channel_axis=1 was wrong for LION's channels-first layout;
  crashed on multichannel input and silently returned wrong values on 2D.
  Now None, inferred per sample (2D -> None, 3D+ -> 0)
- ssim: vals[i] = skim_ssim(...) assigned numpy.float32 into a torch tensor
  (TypeError); wrapped in torch.tensor(...)
- psnr/ssim: reduce=str | None was a default value, not a type hint, so
  calling without reduce always raised ValueError; now reduce: str | None = None
@cslht
cslht force-pushed the fix/metrics-crashes branch from b32125c to 911c76a Compare August 5, 2026 02:24
cslht added 2 commits August 4, 2026 19:28
black --all-files in pre-commit flags LIONmodel.py and two
classical_algorithms tests (from CambridgeCIA#194). Formatting only, no
behavioural changes.
@AnderBiguri
AnderBiguri merged commit 32f57c8 into CambridgeCIA:main Aug 5, 2026
1 check passed
cslht11 pushed a commit to cslht11/LION that referenced this pull request Sep 6, 2026
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.

2 participants