How to split a tensor into different dimension?

Hi, I’m new to Pytorch .
Let’s say I have a tensor that has this shape torch.size([1, 25200, 11]
I want to split it into 3 smaller tensors , each of 3 smaller tensors has the shape of 1st.
torch.size([1, 3, 80, 80, 11]) and 2nd torch.size([1, 3, 40, 40 , 11]) and 3rd torch.size([1, 3, 20, 20, 11)].
Really appreciate your help.
thanks
Explain those number:

  • 80x80x3 = 19200
  • 40x40x3 = 4800
  • 20x20x3=1200 , add these result we have 25200, 1 is batch size, 11 is classes + xywh

You can proceed as follows :


import torch

torch.manual_seed(0)

x = torch.rand(1, 25200, 11)

i=80*80*3#= 19200

j=40*40*3#= 4800

#k=20*20*3#=1200

x1=x[:,:i,:].reshape(1, 3, 80, 80, 11)

x2=x[:,i:i+j,:].reshape(1, 3, 40, 40 , 11)

x3=x[:,i+j:,:].reshape(1, 3, 20, 20, 11)

"""
x1=x[:,:i].reshape(1, 3, 80, 80, 11)
x2=x[:,i:i+j].reshape(1, 3, 40, 40 , 11)
x3=x[:,i+j:].reshape(1, 3, 20, 20, 11)
"""

1 Like

hey Thank for the answer .