Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with Spectral Distortion Index #1520

Closed
rddunphy opened this issue Feb 17, 2023 · 2 comments · Fixed by #1808
Closed

Issues with Spectral Distortion Index #1520

rddunphy opened this issue Feb 17, 2023 · 2 comments · Fixed by #1808
Assignees
Labels
bug / fix Something isn't working help wanted Extra attention is needed topic: Image v1.0.x

Comments

@rddunphy
Copy link

rddunphy commented Feb 17, 2023

🐛 Bug

I'm having a few issues with the implementation of Spectral Distortion Index.

  1. Since SDI is a reference free metric for super-resolution, the inputs are usually not going to be the same size, but the function throws an error if the resolutions are different. I believe only the batch and channel sizes should be validated.
  2. For some inputs, I'm getting nan value outputs. In a set of 49 hyperspectral images I'm working with, I have 14 that result in nan. I believe this happens whenever the denominator lower is 0 here:
    https://github.com/Lightning-AI/metrics/blob/780e9afa7316ab4439b888304eb5c14fdbaacbef/src/torchmetrics/functional/image/uqi.py#L117
    This is a known issue with UQI, which is the reason it was adapted into SSIM by adding a constant to the denominator. Would it make sense to add an option to use SSIM instead of UQI with SDI?
  3. As a result of the nested for loops, the implementation is very slow to run for images with many channels - I'm not sure that they can easily be vectorised, unfortunately, so maybe there's not much that can be done about this. For reference, here are execution times for the aforementioned test set:

PSNR: 32.4233 (total execution time 2.21s)
SSIM: 0.8302 (total execution time 27.60s)
MS-SSIM: 0.9573 (total execution time 35.06s)
SAM: 0.0819 (total execution time 1.37s)
SDI: nan (total execution time 16694.23s)

To Reproduce

Here's a MWE with an image that results in a nan value:

sdi_test.tar.gz

Environment

  • TorchMetrics version (and how you installed TM, e.g. conda, pip, build from source): 0.12.0dev, built from source
  • Python & PyTorch Version (e.g., 1.0): Python 3.10.6, PyTorch 1.13.1+cu117
  • Any other relevant information such as OS (e.g., Linux): Linux

Additional context

I have a fix for 1) here: rddunphy@ffcea15

Let me know if I should open a PR, or have a go at fixing 2) first. Thanks!

@rddunphy rddunphy added bug / fix Something isn't working help wanted Extra attention is needed labels Feb 17, 2023
@github-actions
Copy link

Hi! thanks for your contribution!, great first issue!

@SkafteNicki
Copy link
Member

Hi @rddunphy,
Please feel free to send the fixes for 1) and also feel free to include the proposed changes for 2). I do not see a problem with adding a small epsilon to the denominator to make sure we do not divide by 0.

For 3), it is possible to get rid of the inner for-loop fairly easy by stacking the input:

        stack1 = torch.cat([target[:, k : k + 1, :, :] for r in range(k, length)], dim=0)
        stack2 = torch.cat([target[:, r : r + 1, :, :] for r in range(k, length)], dim=0)

then running universal_image_quality_index on the stack with reduction="none" and afterwards do the averaging manually. This would most likely be faster but also require much more memory because we would need to store input multiple times in memory. So not sure what to do it in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug / fix Something isn't working help wanted Extra attention is needed topic: Image v1.0.x
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@Borda @rddunphy @justusschock @SkafteNicki and others