DataLoader gives:stack expects each tensor to be equal size,due to different image has different objects number

This discussion may be helpful.

Usually, in such situations some sort of padding has to be introduced for each batch so all elements match in size. This can be achieved by defining your own collate_fn that is then passed to DataLoader as an argument.