The collate function cannot call torch.stack on tensors with different shapes in two or more dimensions.
Basically, this is crashing:
x = [torch.randn(3, 224, 224), torch.randn(3, 224, 300)]
torch.stack(x)
> RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 224 and 300 in dimension 3 at /opt/conda/conda-bld/pytorch_1565272271120/work/aten/src/TH/generic/THTensor.cpp:689

, while this will work (as all image tensors are resized to the same size):
x = [torch.randn(3, 224, 224), torch.randn(3, 224, 224)]
torch.stack(x) # shape = [2, 3, 224, 224]