In pytorch, you do not need to write all dataloader by yourself. You can write a class inherited from the dataset, then the dataloader in pytorch will help you prefetch by multiprocess. You can check this 45