Closed michael080808 closed 8 months ago
To solve this issue, one approach can be using Fractions instead of floats to represent numbers with high denominators. Since tensors only work with floats and integers, you can create two seperate tensors for representing numerators and denominators.
π 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 https://github.com/Lightning-AI/torchmetrics/blob/62adb4022b30e0fe5c47589d9ecd82d3ff041117/src/torchmetrics/functional/image/uqi.py#L105-L106 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