siren-pytorch icon indicating copy to clipboard operation
siren-pytorch copied to clipboard

Better mesh grid generation

Open OctoberKat opened this issue 4 years ago • 2 comments

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.

OctoberKat avatar Nov 03 '21 14:11 OctoberKat

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

lucidrains avatar Dec 03 '21 18:12 lucidrains

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.

xnghu avatar Dec 19 '21 05:12 xnghu