Pytorch dataloader Error: RuntimeError: stack expects each tensor to be equal size, but got [4] at entry 0 and [5] at entry 1

In this case, you can also find batch_ When the size is 1, no error will be reported,

batch_ If the size is greater than 1, an error will be reported because the dimensions of entries in the same batch are different

For example, batch = [[2,3,5,1], [3,4,5,2,3]]


Make up to the same length

# Complement the length of all vectors to max_length
multi = np.pad(multi, (0, max_length-multi.shape[0]), 'constant', constant_values=(0, 0))

Note that in the dataset class__get__Supplement in item() method

Similar Posts: