This approach should work:

create a new script using your current ImageFolder approach and write a single loop over the complete training and validation dataset to store each elements in your drive (in the corresponding train/val folder)
Write a custom Dataset to load the tensors directly instead of the images via ImageFolder

use the custom Dataset in your train.py