TransWikia.com

MLP sequential fitting

Data Science Asked by sidhom slim on July 15, 2021

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

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))

enter image description here

One Answer

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.

Correct answer by noe on July 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP