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

Invalid output is provided when input is not contiguous #7

Open
botcs opened this issue Oct 21, 2022 · 0 comments
Open

Invalid output is provided when input is not contiguous #7

botcs opened this issue Oct 21, 2022 · 0 comments

Comments

@botcs
Copy link

botcs commented Oct 21, 2022

If the 2D code is applied on a tensor that is a 2D slice of a larger tensor, e.g.

x.shape == [B, H, W, C]

correct_out = connected_components_labeling(x[0, :, :, 0].contiguous())
incorrect_out = connected_components_labeling(x[0, :, :, 0])

the expected output correct_out:
image

then incorrect_out will be a weird strided version of the correct_out:
image

the input was generated as follows, reusing the example code:
x = torch.tensor(cleared_copy).to("cuda", torch.uint8)[None, :, :, None].repeat(1024, 1, 1, 2)

Fixes

The quick fix is to call .contiguous() on every slice, the correct fix would be to either throw an error if the input is not contiguous or take the tensor strides into consideration on the cuda backend.

Hope this might help someone who got unexpected results.
Nevertheless, this implementations is very quick and is an awesome starting point, so thank you! <3

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