From f0fb4a7eb2221df74e857285c75c82100c4bc6c2 Mon Sep 17 00:00:00 2001 From: JessyD Date: Mon, 6 Feb 2023 17:16:30 -0500 Subject: [PATCH 1/2] Fix print messages for MS-SSIM --- generative/metrics/ms_ssim.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/generative/metrics/ms_ssim.py b/generative/metrics/ms_ssim.py index 2a5047c7..15c20a26 100644 --- a/generative/metrics/ms_ssim.py +++ b/generative/metrics/ms_ssim.py @@ -81,8 +81,8 @@ def _compute_metric(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor: if not x.shape == y.shape: raise ValueError( - f"Input images should have the same dimensions, \ - but got {x.shape} and {y.shape}." + f"Input images should have the same dimensions, " + "but got {x.shape} and {y.shape}." ) for d in range(len(x.shape) - 1, 1, -1): @@ -95,8 +95,8 @@ def _compute_metric(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor: avg_pool = F.avg_pool3d else: raise ValueError( - f"Input images should be 4-d or 5-d tensors, but \ - got {x.shape}" + f"Input images should be 4-d or 5-d tensors, but " + "got {x.shape}" ) if self.weights is None: @@ -109,14 +109,14 @@ def _compute_metric(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor: for idx, shape_size in enumerate(x.shape[2:]): if shape_size % divisible_by != 0: raise ValueError( - f"Image size needs to be divisible by {divisible_by} but \ - dimension {idx + 2} has size {shape_size}" + f"Image size needs to be divisible by {divisible_by} but " + "dimension {idx + 2} has size {shape_size}" ) if shape_size < bigger_than: raise ValueError( - f"Image size should be larger than {bigger_than} due to \ - the {len(self.weights) - 1} downsamplings in MS-SSIM." + f"Image size should be larger than {bigger_than} due to " + "the {len(self.weights) - 1} downsamplings in MS-SSIM." ) levels = self.weights.shape[0] From 86034ed8c512e58a288a0413f683526fba8f8dc7 Mon Sep 17 00:00:00 2001 From: JessyD Date: Tue, 7 Feb 2023 10:51:06 -0500 Subject: [PATCH 2/2] Fix f-strings print (#230) --- generative/metrics/ms_ssim.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/generative/metrics/ms_ssim.py b/generative/metrics/ms_ssim.py index 15c20a26..769a7ff3 100644 --- a/generative/metrics/ms_ssim.py +++ b/generative/metrics/ms_ssim.py @@ -80,10 +80,7 @@ def _compute_metric(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor: """ if not x.shape == y.shape: - raise ValueError( - f"Input images should have the same dimensions, " - "but got {x.shape} and {y.shape}." - ) + raise ValueError(f"Input images should have the same dimensions, but got {x.shape} and {y.shape}.") for d in range(len(x.shape) - 1, 1, -1): x = x.squeeze(dim=d) @@ -94,10 +91,7 @@ def _compute_metric(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor: elif len(x.shape) == 5: avg_pool = F.avg_pool3d else: - raise ValueError( - f"Input images should be 4-d or 5-d tensors, but " - "got {x.shape}" - ) + raise ValueError(f"Input images should be 4-d or 5-d tensors, but got {x.shape}") if self.weights is None: # as per Ref 1 - Sec 3.2. @@ -110,13 +104,13 @@ def _compute_metric(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor: if shape_size % divisible_by != 0: raise ValueError( f"Image size needs to be divisible by {divisible_by} but " - "dimension {idx + 2} has size {shape_size}" + f"dimension {idx + 2} has size {shape_size}" ) if shape_size < bigger_than: raise ValueError( f"Image size should be larger than {bigger_than} due to " - "the {len(self.weights) - 1} downsamplings in MS-SSIM." + f"the {len(self.weights) - 1} downsamplings in MS-SSIM." ) levels = self.weights.shape[0]