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

Better mesh grid generation #6

Open
OctoberKat opened this issue Nov 3, 2021 · 2 comments
Open

Better mesh grid generation #6

OctoberKat opened this issue Nov 3, 2021 · 2 comments

Comments

@OctoberKat
Copy link

OctoberKat commented Nov 3, 2021

Hi,
In siren_pytorch.py, the coordinate mesh grid is generated by the following codes:
tensors = [torch.linspace(-1, 1, steps = image_width), torch.linspace(-1, 1, steps = image_height)]
mgrid = torch.stack(torch.meshgrid(*tensors), dim=-1)
mgrid = rearrange(mgrid, 'h w c -> (h w) c')
self.register_buffer('grid', mgrid)
However, the shape of the mesh grid generated by the first two lines of code is (w, h, c). Thus, the output shape of the following codes should be ((w, h), c) (not ((h, w), c) ):
out = self.net(coords, mods)
It would be better to modify the original codes into:
tensors = tensors = [torch.linspace(-1, 1, steps = image_height), torch.linspace(-1, 1, steps = image_width)]
mgrid = torch.stack(torch.meshgrid(*tensors), dim=-1)
mgrid = rearrange(mgrid, 'h w c -> (h w) c')
self.register_buffer('grid', mgrid)
Several experiments have been conducted to verify the effectiveness of the modification.

@lucidrains
Copy link
Owner

@OctoberKat oh hey! crap, i believe you are right! can you let me know if the latest version fixes things? 🙏

@xnghu
Copy link

xnghu commented Dec 19, 2021

oh my! i really hope this was the source of a maddening inability to get something to work in my project that uses this!! definitely looks like the culprit! everything worked with square output, but broke and gave poor strange distorted results for anything where w != h ... i spent countless nights trying to find the cause or mistake, but eventually gave it a rest for a while. can't wait to get home and test the update.

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