How to select specific channels in an image tensor?

If the input has a shape [N,C,H,W], the output’s shape should be [N,masked_C,H,W]. Where masked_C is the channels of interest. For example, if C=4, then, masked_C is indices 0,2,3

Can you try this?

tensor=tensor[:, [0,2,3]]

1 Like