Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.
Merged
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
18 changes: 6 additions & 12 deletions generative/metrics/ms_ssim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand All @@ -109,14 +103,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 "
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"Image size should be larger than {bigger_than} due to "
f"the {len(self.weights) - 1} downsamplings in MS-SSIM."
)

levels = self.weights.shape[0]
Expand Down