Skip to content

Fix SSIMLoss when batchsize bigger than 2#5908

Merged
wyli merged 1 commit intoProject-MONAI:devfrom
jak0bw:5886-fix_ssim_loss_when_batchsize_bigger_than_2
Jan 27, 2023
Merged

Fix SSIMLoss when batchsize bigger than 2#5908
wyli merged 1 commit intoProject-MONAI:devfrom
jak0bw:5886-fix_ssim_loss_when_batchsize_bigger_than_2

Conversation

@jak0bw
Copy link
Copy Markdown
Contributor

@jak0bw jak0bw commented Jan 27, 2023

Signed-off-by: Jakob Weigand [email protected]

Fixes #5886.

Description

When SSIMLoss is called with a tensor of batchsize > 1, SSIMMetric is called for each batch item individually. The result of each call to SSIMMetric is stored in ssim_val. Subsequently, ssim_val is concatenated to ssim_value, which is a collection of all calls to SSIMMetric. Before the concatenation both ssim_val and ssim_value are given a new view of size 1. As ssim_value collects the results of all earlier calls to SSIMMetric, .view(1) raises an error for the second call (as ssim_value has a different absolute size). This commit changes the behavior of the view call, to always use the current size of ssim_value, avoiding this issue but keeping the behavior to concatenate in a single row vector.

Types of changes

  • 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.

Copy link
Copy Markdown
Contributor

@wyli wyli left a comment

Choose a reason for hiding this comment

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

Thank you, it looks good to me. Im merging this PR, @Can-Zhao please also help verify and feel free to reopen the discussion if needed.

@wyli
Copy link
Copy Markdown
Contributor

wyli commented Jan 27, 2023

/build

@wyli wyli enabled auto-merge (squash) January 27, 2023 07:41
@wyli wyli merged commit ee38882 into Project-MONAI:dev Jan 27, 2023
@jak0bw jak0bw deleted the 5886-fix_ssim_loss_when_batchsize_bigger_than_2 branch March 3, 2023 18:50
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.

SSIM loss fail when batchsize>1

2 participants