Pad_sequence failing troubleshoot "The expanded size of the tensor () must match the existing size () at non-singleton dimension 2."

1 Like

Hi,

According to the doc, pad sequence only performs padding on a single dimension (either first or second depending on the batch_first argument). All the other dimensions after this should have the same size.
In your example, the third dimension is 1444 for one Tensor and 1936 for the other.

1 Like

Ahh that explains it! Thanks a lot.
Does anyone what function would be more suited for what iā€™m looking for?(padding images to match their size)

I guess you can modify the original pad_sequence that you can find here for your needs in the 2D case. By replacing things like out_tensor[i, :length, ...] = tensor by out_tensor[i, :height, :width ...] = tensor.

I will try that! Thanks a lot!