Fix simplify ssim implementation#2563
Merged
vfdev-5 merged 7 commits intopytorch:masterfrom May 4, 2022
Merged
Conversation
vfdev-5
reviewed
May 4, 2022
…/sadra-barikbin/ignite into Fix-simplify-SSIM-implementation
vfdev-5
approved these changes
May 4, 2022
Collaborator
vfdev-5
left a comment
There was a problem hiding this comment.
Thanks @sadra-barikbin , lgtm!
3 tasks
Collaborator
|
@sadra-barikbin I had to run in on cuda to make sure :( |
vfdev-5
reviewed
May 4, 2022
| def reset(self) -> None: | ||
| # Not a tensor because batch size is not known in advance. | ||
| self._sum_of_batchwise_ssim = 0.0 # type: Union[float, torch.Tensor] | ||
| self._sum_of_ssim = torch.tensor(0.0, device=self._device) |
vfdev-5
reviewed
May 4, 2022
|
|
||
| @sync_all_reduce("_sum_of_batchwise_ssim", "_num_examples") | ||
| @sync_all_reduce("_sum_of_ssim", "_num_examples") | ||
| def compute(self) -> torch.Tensor: |
Collaborator
There was a problem hiding this comment.
Let's return just python float instead of a tensor ?
vfdev-5
reviewed
May 4, 2022
Comment on lines
99
to
+102
| assert isinstance(ignite_ssim, torch.Tensor) | ||
| assert ignite_ssim.dtype == torch.float64 | ||
| assert ignite_ssim.device == torch.device(device) | ||
| assert np.allclose(ignite_ssim.cpu().numpy(), skimg_ssim, atol=atol) | ||
|
|
||
|
|
||
| def test_ssim(): | ||
| device = "cuda:0" if torch.cuda.is_available() else "cpu" | ||
| y_pred = torch.rand(8, 3, 224, 224, device=device) | ||
| y = y_pred * 0.8 | ||
| _test_ssim( | ||
| y_pred, y, data_range=1.0, kernel_size=7, sigma=1.5, gaussian=False, use_sample_covariance=True, device=device | ||
| ) | ||
| assert ignite_ssim.device.type == torch.device(device).type | ||
| assert np.allclose(ignite_ssim.cpu().numpy(), skimg_ssim, atol=7e-5) |
Collaborator
There was a problem hiding this comment.
As we can return float instead of Tensor, let's update tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2532
Description:
Based on #2562 ,
updatemethod became simpler.Check list: