Po-Hsun-Su / pytorch-ssim

pytorch structural similarity (SSIM) loss
Other
1.89k stars 368 forks source link

SSIM are negative #31

Open icey-zhang opened 3 years ago

icey-zhang commented 3 years ago

Hello, what's wrong with code that comes out with negative values?

nickdalfarra commented 3 years ago

I'm not 100% sure, but there seem to be different conventions on the range of SSIM implementations. Some output to [0,1], others to [-1,1]. I don't have an example of two images producing a perfectly bad SSIM of -1, but you could always just linearly transform the SSIM output via (SSIM + 1)/2 to make the range [0,1].

TalTaiber commented 2 years ago

Hello, what's wrong with code that comes out with negative values?

Just a guess, since the author did not repond: Higher SSIM corresponds to greater similarity between the two images. However, notice that in the author's explanation we have: ssim_loss = pytorch_ssim.SSIM() Since the optimizer tries to minimize the loss, we have to define the SSIM loss as negative SSIM, so that when the loss is low the SSIM will be high.