By default, Dataloader tries to stack the tensors to form a batch (calls torch.stack on the current batch), but it fails if the tensors are not of equal size. With the collate_fn it is possible to override this behavior and define your own “stacking procedure”. In the example above, the batch arg contains a list of instances (an image-bbox pair; the batch arg is of type List[Tuple[Image, Bbox]]) and with  tuple(zip(*batch)) we  form a batch, where batch[0] corresponds to the images, and batch[1]  to the bboxes in the batch.