In practice I don’t think 2.5 million images is unreasonable, as many models are trained on ImageNet (1.2 million images) these days with larger datasets floating around. However, by default ImageNet is usually distributed as an archive that is deserialized as many images on a filesystem so there is no need to keep the entire dataset in memory at once. Is there any way you could do something similar with your dataset (e.g., convert the images to file on disk) ahead of time?