Search code examples
tensorflowbatchsize

Batch Size From Keras Output Is Different From My Training Set


I have a question on the batch size number showing up in keras output. I've gone through similar posts on how to interpret keras outputs and figured out that the number 219 shown in the result is the number of batch_size. However, you can see that my X_train batch_size is 7000, not 219. Where did this 219 come from?

X_train.shape # (7000, 50, 1)
Y_train.shape # (7000, 50, 10)


model = keras.models.Sequential([
    keras.layers.SimpleRNN(20, return_sequences=True, input_shape=[None, 1]),
    keras.layers.SimpleRNN(20, return_sequences=True),
    keras.layers.TimeDistributed(keras.layers.Dense(10))
])

model.compile(loss="mse", optimizer=keras.optimizers.Adam(lr=0.01))
history = model.fit(X_train, Y_train, epochs=10)

Partial result:

model.compile(loss="mse", optimizer=keras.optimizers.Adam(lr=0.01))...
Epoch 1/10
219/219 [==============================] - 2s 8ms/step - loss: 6.0260e-06
Epoch 2/10
219/219 [==============================] - 2s 8ms/step - loss: 1.1669e-08
Epoch 3/10
219/219 [==============================] - 2s 8ms/step - loss: 7.6153e-08

Solution

  • in model.fit the default batch size is 32. So if you have 7000 samples then the steps per epoch is 7000/32=218.75 which gets rounded up to 219. So what this means is to go through your 7000 samples it fetches 32 images for each batch and does that 219 times.