You could use a custom collate_fn to create batches containing tensors with e.g. different shapes.
The default collate function creates a batch by stacking the tensors in dim0. However, this is not possible, if the spatial size of each tensor is different, so that a custom collate function gives you more flexibility to create the batches for your use case.