'steps_per_epoch with model.fit() and ImageDataGenerator don't work as expected
This is the code:
batch_size = 2
dir="augmented_images/"
trainX, testX, trainY, testY = train_test_split(images, labels,
test_size=0.3)
training = ImageDataGenerator(rotation_range=25, fill_mode="nearest")
train_generator=training.flow(trainX, trainY, batch_size=batch_size,
save_to_dir=dir)
optimizer = Adam(learning_rate=init_learning_rate, decay=init_learning_rate / epochs)
model = get_model()
model.compile(loss="binary_crossentropy", optimizer=optimizer, metrics=["accuracy"])
training_data = model.fit(train_generator,steps_per_epoch=1,epochs=1)
The len of trainX is 18.
In the directory where i save augmented images of ImageDataGenerator, i see that, even if i set 1 step per epoch, there are 6 images, that means next(train_generator) was called 3 times.
If i write model.fit(train_generator,steps_per_epoch=2,epochs=1).. it generates 3*batch_size + batch_size images, then 8... till i set up steps_per_epoch=8, that will produce 20 images, but also using steps_per_epoch=9, that is equal to len(trainX)//batch_size, outputs 20 images.
From some repeated name of saved images (ex. _6_1922.png, _6_2832.png) i get that, at the end of each epoch, train_generator is "reset" and called again even if we won't have another epoch, so for this reason there is an additional batch in the output directory; the same seems to happen at the end of each step, when the next step is less than len(trainX)//batch_size, however i'm not sure about this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
