Farrukh Ahmed Khan
Farrukh Ahmed Khan

Reputation: 301

Keras fit_generator(datagen.flow(X_train)) function takes less pictures than X_train have?

I am using keras fit_generator(datagen.flow()) function for training of my inception model, I am so confused about the number of images it is taking on every epoch. Can anyone please help me telling this How it is working. My code is below.

I am using this keras documentation.

from keras.preprocessing.image import ImageDataGenerator
datagen = ImageDataGenerator(rotation_range = 15, horizontal_flip = True)

# Fitting the model with
history = inc_model.fit_generator(datagen.flow(X_train, train_labels, batch_size=10), epochs=20, validation_data = (X_test, test_labels), callbacks=None)

Now my total images in X_train is 4676. However, everytime I run this history line, I get

Epoch 1/20
936/936 [========================] - 167s 179ms/step - loss: 1.4236 - acc: 0.3853 - val_loss: 1.0858 - val_acc: 0.5641

Why is it not taking whole of my X_train images? Also, if I change batch_size from 10 to lets say 15 it start taking more less images such as

Epoch 1/20 
436/436

Thank you.

Upvotes: 0

Views: 776

Answers (1)

JimmyOnThePage
JimmyOnThePage

Reputation: 965

The 936 and 436 actually refer to batches of samples per epoch. You set your batch size to 10 and 15, so in each case the model is trained on 936 X 10 and 436 X 15 samples per epoch. The samples is even more than your original training set, since you use the ImageDataGenerator which creates additional training instances by applying transformations to existing ones.

Upvotes: 2

Related Questions