I have a tensor of size BxCxHxW
i want to mask the values in each channel as if they are larger than 0.25*mean of that channel the value be 1 and if they are lower than that the value be 0.
How we can do it fast in pytorch?
Iโve used None to unsqueeze the tensor. Alternatively, you could use .mean(2).unsqueeze(2).unsqueeze(3), but I prefer to use this notation if I need to add more than one dimension.
In older versions this will probably work:
@ptrblck
Sorry for coming back, I faced an error on your last answer for old version of pytorch (0.3.0)
so it works when i test, but when my input is [torch.cuda.FloatTensor of size 1x1024x50x89 (GPU 0)] it trowed me an error that *** AssertionError: MaskedFill can't differentiate the mask and i had to change the lst two lines to:
z = (x > x.view(B, C, -1).mean(2)[:, :, None, None]).float()
z = (x <= x.view(B, C, -1).mean(2)[:, :, None, None]).float()