0
votes

I have set of masks on cuda/GPU corresponding to different objects in an image (shapes and sizes below)

masks.shape:            torch.Size([10, 240, 320, 1])
masks[0].shape:         torch.Size([240, 320, 1])
masks[0][:,:,0].shape:  torch.Size([240, 320])

1: Can I produce union of the these masks using torch.tensor operation? so that I can apply all of those once on the image?

2: How do I invert the values in torch tensor? I mean for 1, turn into 0 and vice versa. I have tried to ~mytensor but it says the operator is only applicable to integer or bool values. I have got float values in my tensors i.e. [1.] etc.

I intent to do all these operations on GPU without moving data back on CPU.

Thank you.

1
1. (torch.sum(masks, dim=0) > 0).astype('float') will do the tricksoumith

1 Answers

0
votes

2: How do I invert the values in torch tensor?

t = torch.tensor([1., 0., 0., 1., 0., 1., 1.])

You can subtract values from 1 if you don't want to change type

1 - t
tensor([0., 1., 1., 0., 1., 0., 0.])

Or better you can convert it into boolean type and then use ~

~t.type(torch.bool)
tensor([False,  True,  True, False,  True, False, False])