Make batch with different size tensors

Let we have four images per a batch. (4 x 3 x W x H)
During the loop, I extract features from the images using CNN. (4 x C x w x h)

Here, for every image, we have pre-defined mask with different size. (Let, M1 ~ M4)
I want to select and concatenate the features at the given positions only.
So, now the features are C x M1 ~ C X M4.

As you can see, this process makes the selected features to have different size.
So I failed to make them as a batch.

I want to put the features to another CNN based network.
Of course I can put them separately, but this took really long time.
How can I do this?

Hi,

I’m afraid you won’t be able to create a single Tensor with different sizes on a single dim.
You might be able to create a Tensor with the largest size though and copy all the elements in it. Padding with 0s for the Tensors that are smaller than the full size.

1 Like

Hi,

I already considered your idea, but it requires additional dummy memory for zeros…
Anyway thank you for your response.