You can try Dataloader, which doesn’t require to actually load all images in memory at any point.
You can read more about it here: https://pytorch.org/docs/stable/data.html 342
tutorial: https://github.com/pytorch/tutorials/blob/master/beginner_source/data_loading_tutorial.py 300