2/25/2022

list tensor to batch tensor, Pytorch

 4 length list tensor -> 4 x 200 x 200 x 3 tensor

--

print('---- input list tensor')
print('length: ', len(list_torch) )
for g in list_torch:
print(g.shape)
print('---- convert batch tensor')
b = torch.Tensor(4, 200, 200, 3)
torch_batch = torch.cat(grid, out=b)
print(torch_batch.shape)
print('----')

--

output

---- input list tensor
length: 4
torch.Size([1, 200, 200, 3])
torch.Size([1, 200, 200, 3])
torch.Size([1, 200, 200, 3])
torch.Size([1, 200, 200, 3])
---- convert batch tensor
torch.Size([4, 200, 200, 3])
----

--


Thank you.

www.marearts.com

πŸ™‡πŸ»‍♂️