Correct way to reshape a 4D tensor?

Hi, I have a tensor of size (3, 256, 133, 133).
Assuming batch size is 3, channels is 256 and the width and height are 133 respectively.
I would like to reshape it such that it is (3x256, 133x133).
But is the safest way to reshape such that (133x133) is a vectorized form of an image?

Can I do this?

x.view((batch*channels, -1))

Yes that works. To help convince yourself, recommend inserting some random data, reshaping with view(), checking to convince yourself it was reshaped as planned. Also you only need one set of parens

1 Like