It returns the next batch of images with their labels. So if your batch size was defined as 5, it returns 5 images and their one hot encoded labels vector.
def get_batches(self, path, gen=image.ImageDataGenerator(), shuffle=True, batch_size=8, class_mode='categorical'):
Takes the path to a directory, and generates batches of augmented/normalized data. Yields batches indefinitely, in an infinite loop.
See Keras documentation: https://keras.io/preprocessing/image/
return gen.flow_from_directory(path, target_size=(224,224),
class_mode=class_mode, shuffle=shuffle, batch_size=batch_size)
This is where it is all setup. “gen” is an
ImageDataGenerator object. When
gen.flow_from_directory(...) it is assigned to the variable
batches upon which you then iterate by calling
next(). Each time you call
next() you get
batch_size number of images and
batch_size number of one hot encoded vectors which represents the category of the image (dog or cat). You can loop indefinitely upon the
ImageDataGenerator and it will always keep returning 4 images.
All this is used to endlessly loop over the training set during training.
Now there are many ways to get data out of an
flow_from_directory is one of them. You can check the other ways in the
Hope this helps!