0

I have a 84x84 pytorch tensor named target. I need to mask it with an 84x84 boolean numpy array which consists of True and False.

When I do target = target[mask], I get the error TypeError: can't convert np.ndarray of type numpy.bool_. The only supported types are: double, float, float16, int64, int32, and uint8.

Surprisingly, I get this error only when running on a GPU. When running on a CPU, everything works fine. How can I fix this?

3
  • What about the answer provided here: discuss.pytorch.org/t/… ? Commented Jan 5, 2020 at 23:11
  • convert it to np.uint8 Commented Jan 6, 2020 at 3:36
  • It would be great if you would provide a minimal example. Commented Jan 6, 2020 at 11:20

1 Answer 1

2

I think there is some confusion with the types. But this works.

import torch
tensor = torch.randn(84,84)
c = torch.randn(tensor.size()).bool()
c[1, 2:5] = False
x = tensor[c].size()

For testing I created a tensor with random values. Afterwards 3 elements are set to False. In the last step I look get the size 7053 resulting from 84^2 - 3.

Hope that helps somehow.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.