jorge-pessoa / pytorch-msssim

PyTorch differentiable Multi-Scale Structural Similarity (MS-SSIM) loss
Other
449 stars 69 forks source link

Possible mistake in your implementation? #7

Closed kuoweilai closed 4 years ago

kuoweilai commented 5 years ago

In your implementation: https://github.com/jorge-pessoa/pytorch-msssim/blob/master/pytorch_msssim/__init__.py line 96: output = torch.prod(pow1[:-1] pow2[-1]) Should it be: output = torch.prod(pow1[:-1]) pow2[-1] Otherwise the pow2 would be multiplied too many times? Thanks!

XiaotianM commented 5 years ago

Hi, I find the official implement in tensorflow. The implementation is similar with this author's. https://github.com/tensorflow/tensorflow/blob/r1.14/tensorflow/python/ops/image_ops_impl.py#L3143-L3267

Ir1d commented 4 years ago

output = torch.prod(pow1[:-1] * pow2[-1]) I meet NaN during training on this line. pytorch module tells me that Function 'ProdBackward0' returned nan values in its 0th output. I've set normalize=True in the code, but nan still happens. After changing to output = torch.prod(pow1[:-1]) * pow2[-1] it turned out to Function 'MulBackward0' returned nan values in its 1th output.

jorge-pessoa commented 4 years ago

Hello, I apologize for the delay in answering your question. As I understand from the official implementation, the product method (which is what is implemented in this repository) requires the multiplication of each value of the mcs array by the ssim of the last iteration of the SSIM calculation. See line 99 of msssim.m from https://ece.uwaterloo.ca/~z70wang/research/iwssim/ :

overall_mssim = prod(mcs_array(1:level-1).^weight(1:level-1))*(mssim_array(level).^weight(level));

Regarding your stability issues, I will be merging a different approach to ensure stability in the initial iterations which may help you (if you're still interested).

Thank you for your contributions. I will be closing this issue for now due to its age. If you still have any questions feel free to open a new one.