It seems that you are looking for the implementation of collate_fn which handles the heterogeneity of the data sources from your own Dataset. You should pass your own collate_fn as the input of Dataloader. See more at https://pytorch.org/docs/stable/data.html 1