Converting a keras DirectoryIterator to a torch variable

I am creating a classifier using PyTorch for classifying a dog and cat. My question is that I only have 10000 images for cats and dogs, 8000 for training and 2000 for testing. So to prevent overfitting I want to use keras’s ImageDataGenerator function to generator augmented images. This is what I did for that portion

   train_datagen = ImageDataGenerator(rescale = 1./255, 
                                      shear_range = 0.2, #corresponds to shearing to the images
                                      zoom_range = 0.2, #corresponds to a random zoom on the images
                                      horizontal_flip = True) #flips the images horizontally

   test_datagen = ImageDataGenerator(rescale = 1./255) #preprocessing the images of the test set

   #since our images are formatted in a certain way we use the flow_from_directory() function
   #Creating the training set
   training_set = train_datagen.flow_from_directory('dataset/training_set',
                                                     target_size = (64, 64), 
                                                     batch_size = 32,
                                                     class_mode = 'binary')

   #Creating the test set
   test_set = test_datagen.flow_from_directory('dataset/test_set',
                                                target_size = (64, 64),
                                                batch_size = 32,
                                                class_mode ='binary')

Now the only problem is that I need the training_set and test_set to be converted to Torch Variables, but right now there DirectoryIterators. So is there a way to convert the training_set and test_set to Torch Variables. Or can I do the same thing that I did here but using pytorch.

Thank you

Have a look at the transformations from torchvision.
Also have a look at this thread. This should give you the needed transformations.

@ptrblck Thanks for the response. I just had a quick question that I wanted to ask about using transformations. I’m still kind of confused on how to use the transformations from torchvision to obtain the same results that I would get using keras. My main issue is that I dont really understand how the transformation adds additional images to my dataset. From how I am understanding it as of now is that the transformation from torchvision wont add those transformations to my dataset instead the current images will just get transformed. If this is the case do I need to then apply the transformations each epoch, and if this is not the case can you please clear up my understanding.

Thank you

your understanding is correct.

@smth So after each epoch has been completed than do I need to redo the transformation