I have the following tensor and am attempting to extract the RGB channels. The torch size is ([3, 3, 3]). How do I go about doing this?
tensor([[[ 0.0968, -0.1558, 0.1071],
[ 0.0619, 0.0805, -0.1376],
[ 0.1503, 0.0461, -0.0443]],
[[ 0.1112, -0.1045, -0.1144],
[ 0.1630, -0.1243, -0.1621],
[-0.1156, 0.1858, -0.0574]],
[[-0.1317, 0.1630, 0.0421],
[-0.0513, 0.0113, 0.0913],
[-0.1606, 0.1905, 0.0819]]])
Hello Piotr,
I have a tensor torch.Size([5, 3, 256, 256]). I am trying to get a vector with the highest values of each RGB channel so I am doing this:
rgb = torch.argmax(mytensor, dim=1, keepdims=True)
and I am having a new tensor with torch size torch.Size([5, 1, 256, 256]).
Is this the correct approach? Thank you
Iām not sure if you want to keep the highest value, as in pixel intensity, or the corresponding index of the color channel.
Currently, rgb
will contain the argmax
, i.e. the channel index corresponding to the max
value in the range [0, 1, 2]
. If you want to keep the actual pixel intensity, use rgb = torch.max(x, dim=1)
and index the values afterwards via rgb[0]
or rgx.values
.
1 Like