Change Tensor shape

Hi,

I had a very noob question:
I want to change my tensor shape from [5, 3, 84, 84] to [5, 1, 28, 28]
That is, change image size from 84x84 to 28x28, and convert RGB to GrayScale.

P.S. I don’t want to make use of transforms, as I want to keep the original tensor [5, 3, 84, 84] for a different operation.

Thank you!

You could still use transformations and keep the original tensor alive as seen here:

trans = transforms.Compose([
    transforms.Grayscale(),
    transforms.Resize((28, 28)),
])

x = torch.randn([5, 3, 84, 84])
out = trans(x)
print(x.shape)
# > torch.Size([5, 3, 84, 84])
print(out.shape)
# > torch.Size([5, 1, 28, 28])
1 Like