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

sinkhorn_divergence for 1D images not workin #63

Open
rsanchezgarc opened this issue Jun 7, 2022 · 4 comments
Open

sinkhorn_divergence for 1D images not workin #63

rsanchezgarc opened this issue Jun 7, 2022 · 4 comments

Comments

@rsanchezgarc
Copy link

Hi, I think that sinkhorn_divergence is not working for 1D images despite what the documentation says.

import torch
from geomloss import sinkhorn_divergence
sinkhorn_divergence(torch.zeros(1,40), torch.zeros(1,40))

  File "python3.7/site-packages/geomloss/sinkhorn_images.py", line 110, in sinkhorn_divergence
    a_s, b_s = pyramid(a)[1:], pyramid(b)[1:]
  File "python3.7/site-packages/geomloss/utils.py", line 94, in pyramid
    for i in range(int(np.log2(I.shape[HEIGHT]))):
IndexError: tuple index out of range

It would be great if you can fix it

Thanks
Ruben

@albeltra
Copy link

The code assumes the input has batch and channel dimensions and at least 2 spatial dimensions.

@rsanchezgarc
Copy link
Author

Hi @albeltra And how can it be used for 1D inputs. I want to compare histograms. Using a BxNx1x1 tensor as input?

@albeltra
Copy link

If you want something that just runs you could replicate this histogram an additional two dimensions. Then maybe set return potentials to True and index them to ignore the additional dimensions.

But if you look at the code its pretty easy to copy the if else blocks to add an additional case for 1D data. You could pull the repo and do pip install -e to run the modified code

Or you could use the closed form Wasserstein distance in 1D which is basically just a cumsum of differences operation. But not sure what ur eventual goal is.

@jeanfeydy
Copy link
Owner

Hi @albeltra, @rsanchezgarc,

Thanks for your interest in this library!
As said by @Alberta, 1D optimal sorting amounts to sorting / histogram equalization so there is probably no need to use GeomLoss here.
Nevertheless, I am currently adding support for this case in the ot_api branch: I will close the issue once it is merged in the main repo, probably at some point in July :-)

Best regards,
Jean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants