The divided by zeros
problem in low precision when use uqi
, sdi
, ssim
and ms-ssim
#2281
Labels
divided by zeros
problem in low precision when use uqi
, sdi
, ssim
and ms-ssim
#2281
🐛 Bug
Hi, guys! Thanks for your fast response and fix! I really appreciate that.
When I tried to compute the
uqi
function, I found that there is still some situation that the quotients will be zeros.Accroding to https://en.wikipedia.org/wiki/Variance, I know that
And I tried to debug the code for understanding why I got NaN values. I noticed that
torchmetrics/src/torchmetrics/functional/image/uqi.py
Lines 105 to 106 in 62adb40
produces very small negative values around 5e-7. It seems that the results give the "negative variance" values due to float deviations, which is impossible for math. Although there is a eps to avoid zero, the absolute value of "negative variance" is much greater than eps, and the "negative variance" finally leads to this NaN or "divided by zeros" problems.
sdi
uses theuqi
results so it produced the same NaN. Besides,ssim
andms-ssim
use C1 and C2 to prevent this thing but in fact they also suffer the same situation.To Reproduce
I'm sorry that I can't give the original data due to the upload limitations. Each file is 1.15GB. It's very tricky to reproduce the problem. If there are some other methods to upload data, I’m glad to provide my data. 😊
Expected behavior
I'm not sure how to solve the problem.
torch.unfold
can compute as the variance defination but will cost huge amount of memory which is not acceptable. I think it's better to add a check of the variance to prevent negetive ones join the quotients. However, I don't know which is better between using the absolute values of negetive results and just leaving them as zeros.Environment
The text was updated successfully, but these errors were encountered: