TensorFlow - Fashion MNIST Steps Per Epoch

Viewed 438

I'm working with the Kera's Fashion MNIST dataset. When I fit my model, I noticed to complete one epoch it would have to go through 1500 steps.

history = model.fit(x_train, y_train, epochs=30, validation_split=0.2)

Epoch 3/30
1500/1500 [==============================] - 3s 2ms/step - loss: 0.4494 - sparse_categorical_accuracy: 0.8438 - val_loss: 0.4691 - val_sparse_categorical_accuracy: 0.8308
Epoch 4/30
964/1500 [==================>...........] - ETA: 0s - loss: 0.4294 - sparse_categorical_accuracy: 0.8504

I was looking at the docs for the fit function, but couldn't understand why the default steps were set to 1500. I understand when the steps_per_epoch is None the behavior is dependent on the data type of the dataset, but how can I check if the data type is a tensor or tf.data?

1 Answers

The number of steps per epoch is equal to ceil(samples / batch_size). The default batch size in model.fit is 32 (documentation). If the MNIST training data has 60000 samples, then each epoch would take 60000 / 32 = 1875 steps.

model.fit also supports splitting your data into training and validation sets. You have done this with validation_split=0.2, so only 80% of the samples are part of the training set (20% are for validation). The new calculation would be 0.8 * 60000 / 32 = 1500. This is why you see 1500 steps per epoch.

Related