Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions pytorch_msssim/ssim.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def ssim(


def ms_ssim(
X, Y, data_range=255, size_average=True, win_size=11, win_sigma=1.5, win=None, weights=None, K=(0.01, 0.03)
X, Y, data_range=255, size_average=True, win_size=11, win_sigma=1.5, win=None, weights=None, K=(0.01, 0.03), nonnegative_ssim=False,
):

r""" interface of ms-ssim
Expand Down Expand Up @@ -220,7 +220,8 @@ def ms_ssim(
X = avg_pool(X, kernel_size=2, padding=padding)
Y = avg_pool(Y, kernel_size=2, padding=padding)

ssim_per_channel = torch.relu(ssim_per_channel) # (batch, channel)
if nonnegative_ssim:
ssim_per_channel = torch.relu(ssim_per_channel) # (batch, channel)
mcs_and_ssim = torch.stack(mcs + [ssim_per_channel], dim=0) # (level, batch, channel)
ms_ssim_val = torch.prod(mcs_and_ssim ** weights.view(-1, 1, 1), dim=0)

Expand Down Expand Up @@ -284,6 +285,7 @@ def __init__(
spatial_dims=2,
weights=None,
K=(0.01, 0.03),
nonnegative_ssim=True,
):
r""" class for ms-ssim
Args:
Expand All @@ -303,6 +305,7 @@ def __init__(
self.data_range = data_range
self.weights = weights
self.K = K
self.nonnegative_ssim = nonnegative_ssim

def forward(self, X, Y):
return ms_ssim(
Expand All @@ -313,4 +316,5 @@ def forward(self, X, Y):
win=self.win,
weights=self.weights,
K=self.K,
nonnegative_ssim=self.nonnegative_ssim,
)
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pytorch_msssim",
version="0.2.1",
version="0.2.2",
author="Gongfan Fang",
author_email="fgf@zju.edu.cn",
description="Fast and differentiable MS-SSIM and SSIM for pytorch.",
Expand All @@ -19,4 +19,4 @@
"Operating System :: OS Independent",
],
install_requires=['torch']
)
)