Since you have 25000 images, I can provide you an easy way.
When you read the images like you can use Image from PIL or you can use cv2.imread.
So basically store the images as numpy array in a csv file with the corresponding labels.
By this way the time will be reduced as the dataset won’t read the images again and again for every epoch, instead it will directly take the already precomputed numpy arrays.
Till then I’ll try to debug your code!
Cheers!