WARNING: this library has been superseded by https://github.com/VainF/pytorch-msssim
This small utiliy provides a differentiable MS-SSIM implementation for PyTorch based on Po Hsun Su's implementation of SSIM @ https://github.com/Po-Hsun-Su/pytorch-ssim. I provide asmall changes compared to the method provided by Jorge Pessoa. At the moment only a direct method is supported.
To install the current version of pytorch_mssim:
- Clone this repo.
- Go to the repo directory.
- Run
python3 -m pip install -e .
or
- Clone this repo.
- Copy "pytorch_msssim" folder in your project.
or
python3 -m pip install git+https://github.com/SpikeAI/pytorch-msssim
import pytorch_msssim
import torch
from torch.autograd import Variable
m = pytorch_msssim.NMSSSIM(val_range=1., normalize=True)
img1 = torch.rand(1, 1, 256, 256)
img2 = torch.rand(1, 1, 256, 256)
print('direct call to MSSSIM:', pytorch_msssim.msssim(img1, img2))
print('Negative MSSSIM as a (derivable) function:', m(img1, img2))
For a detailed example on how to use msssim
for training, look at the file test/max_ssim.py
.
We recommend using the flag normalized=True
when training unstable models using MS-SSIM (for example, Generative Adversarial Networks) as it will guarantee that at the start of the training procedure, the MS-SSIM will not provide NaN results.
https://ece.uwaterloo.ca/~z70wang/research/ssim/
https://github.com/Po-Hsun-Su/pytorch-ssim
Thanks to @z70wang for providing the initial SSIM implementation and all the contributors with fixes to this fork and @jorge-pessoa for continuing this work.