user1367204
user1367204

Reputation: 4797

Keras: Why isn't observed batch size matching up with the specified batch size?

I specify a batch size of 500 by doing this in my code:

model.fit(x_train, y_train, validation_data=(x_test, y_test), nb_epoch=100, batch_size=500, verbose=1)

When I run the code, the first batch size is 500, and the batch sizes after that are like 5000 and larger, why does this happen?

The reason I think the batch size are larger is because it seems like the model goes from row 500 to row 6000, which is 5500 rows.

Epoch 100/100
  500/31016 [..............................] - ETA: 0s - loss: 0.1659 - acc: 0.7900
 6000/31016 [====>.........................] - ETA: 0s - loss: 0.1679 - acc: 0.7865
11500/31016 [==========>...................] - ETA: 0s - loss: 0.1688 - acc: 0.7850
17000/31016 [===============>..............] - ETA: 0s - loss: 0.1692 - acc: 0.7842
23000/31016 [=====================>........] - ETA: 0s - loss: 0.1694 - acc: 0.7839
29000/31016 [===========================>..] - ETA: 0s - loss: 0.1693 - acc: 0.7841
31016/31016 [==============================] - 0s - loss: 0.1693 - acc: 0.7841 - val_loss: nan - val_acc: 0.6799

Upvotes: 1

Views: 1372

Answers (1)

Marcin Możejko
Marcin Możejko

Reputation: 40506

This is really interesting issue. The part of code which is responsible for displaying a progress bar is a util called progbar and it's defined here. It accepts as a parameter a minimum visual progress update interval which is by default set to 0.01 seconds. This default value is also used during printing a progress bar during fit computations and this is probably the reason behind this weird behaviour.

Upvotes: 1

Related Questions