Hello,
I want to iterate over a 5d tensor ‘images’, extract 4d tensors and do some operation on the 4d tensors which is an individual bag of (batch size, channels, height, width).So in a 5d tensor, 1st dimension is batch size, 2nd dimension is bag size which is number of images in a bag (lets say 20),3rd dimension is RGB, 4th and 5th dimension are height and width.here is my for loop which I am using but this very slow.is there any other way to make this code faster? the for loop is very slow.
new_output = []
for i in range(args.bag_size):
individual_bag = images[:,i,:,:,:]
print('individual_bag shape',individual_bag.shape)
intermediate_output = model.get_intermediate_layers(individual_bag, n)
output = torch.cat([x[:, 0] for x in intermediate_output], dim=-1)
new_output.append(output)
output = torch.mean(torch.stack(new_output),dim = 0)
Thanks,
Rohan