MLP sequential fitting

I am fitting a Keras model, using SGD Input dataset X_train has 55000 entries.

Can anyone explain the yellow highlighted values? For me, when each epoch is done, this should correspond to 55000/55000.

model = keras.models.Sequential()
model.add(keras.layers.Flatten(input_shape=[28,28]))
model.add(keras.layers.Dense(300, activation=relu))
model.add(keras.layers.Dense(100, activation=relu))
model.add(keras.layers.Dense(10, activation=softmax))

model.compile(loss=sparse_categorical_crossentropy, optimizer=sgd,metrics=[accuracy])

history = model.fit(X_train , y_train, epochs=30 , validation_data=(X_valid, y_valid))

Topic ann keras deep-learning

Category Data Science


These numbers refer to minibatches, not individual samples. The data is not fed to the model one by one, but in small groups called "minibatches" or simply "batches". The size of the minibatch (the number of elements to be included in each minibatch) can be specified as a parameter to the fit method. As you did not provide any value, it took the default value of 32. This is specified in the documentation:

batch_size: Integer or None. Number of samples per gradient update. If unspecified, batch_size will default to 32. Do not specify the batch_size if your data is in the form of datasets, generators, or keras.utils.Sequence instances (since they generate batches).

Your data size divided by the batch size gives us the number of batches, which is the number you see: ceil(55000 / 32) = 1719. As they are not divisible, the last batch would have a few elements less; specifically, the last batch has 24 elements (= 55000 - 32 * 1718) instead of 32.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.