I was reading the Deep Learning in Python book and wanted to understand more on the what happens when you define the steps_per_epoch
and batch size
. The example they use consists of 4000 images of dogs and cats, with 2000 for training, 1000 for validation, and 1000 for testing. They provide two examples of their model. One with image augmentation one without. I am confused on why they changed the batch size between the two cases.
I have understood the process is that 1 epoch is 1 pass over the entire training dataset. The batch size determines how many of the images are shown per one step. When we change the batch size, we change the number of images to be learned from. For their first example with 2000 images in training, a batch size of 20, 100 steps per epoch is logical and what they use. It will take 100 steps to see 2000 images, completing an epoch. On their next example, they implement more augmentations than re-scaling the image (6 total of rotation changes, zooms, shears, etc), the batch size increases to 32, but they left steps per epoch at 100. I assumed with the increase in batch size, steps_per_epoch declines and in this case to be 63 (round up from 62.5). Why do they leave steps_per_epoch
the same in this case? In the end, does the model not see some training data or see too much data given the rounding issue?
from keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(rescale=1./255)
test_datagane = ImageDataGenerator(rescale=1./255)
train_generator=train_datagen.flow_from_directory(
train_dir,
target_size = (150,150)
batch_size=20 # for model 2 batch_size=32
class_mode='binary')
validation_generator = test_datagen.flow_from_directory(
validation_dir,
target_size = (150,150)
batch_size=20 # for model 2 batch_size=32
class_mode='binary')
history = model.fit_generator(
train_generator,
steps_per_epoch = 100, # same for both models
epochs=30,
validation_data=validation_generator,
validation_steps=50) # same for both models