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

speed up flip when rasterize #103

Open
ALLinLLM opened this issue Feb 22, 2021 · 0 comments
Open

speed up flip when rasterize #103

ALLinLLM opened this issue Feb 22, 2021 · 0 comments

Comments

@ALLinLLM
Copy link

ALLinLLM commented Feb 22, 2021

line 311 rasterize.py

    if return_rgb:
        rgb = rgb.permute((0, 3, 1, 2))
        # pytorch does not support negative slicing for the moment
        # may need to look at this again because it seems to be very slow
        # rgb = rgb[:, :, ::-1, :]
        rgb = rgb[:, :, list(reversed(range(rgb.shape[2]))), :]

after pytorch 0.4.0, we can use following native api to do reverse, which is really faster

import torch
def flip(x, dim):    
    indices = [slice(None)] * x.dim()
    indices[dim] = torch.arange(x.size(dim) - 1, -1, -1,
                                dtype=torch.long, device=x.device)
    return x[tuple(indices)]

And, in pytorch 1.2

just using tensor.flip()
refer to https://pytorch.org/docs/1.2.0/torch.html?highlight=flip#torch.flip

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

1 participant