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 numbers:
80x80x3 = 19200
40x40x3 = 4800
20x20x3=1200 , add these result we have 25200, 1 is batch size, 11 is classes + xywh
Something like this should work.
import torch
tensor = torch.ones((1, 25200, 11))
first_break = tensor[:, 0:19200, :].view((1, 3, 80, 80, 11))
second_break = tensor[:, 19200:19200+4800, :].view((1, 3, 40, 40, 11))
third_break = tensor[:, 19200+4800:19200+4800+1200, :].view((1, 3, 20, 20, 11))
If you give a bit more explanation and context the code could get cleaned up and not be so hardcoded, or maybe this gives you enough to run with.
Have you tried:
T1= torch.narrow(YourTensor, 1,0 , 80*80*3)
T1v = T1.view(1,3,80,80,11)
T2= torch.narrow(YourTensor, 1,80*80*3 , 40*40*3)
T2v = T2.view(1,3,40,40,11)
T3= torch.narrow(YourTensor, 1,80*80*3 + 40*40*3 , 20*20*3)
T3v = T3.view(1,3,20,20,11)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.