Search code examples
deep-learningkerasepochmodel-fittingupdatebatchsize

What is the relationship between the batch size and the epochs in Keras?


I'm training a model with 8000 samples

classifier = KerasClassifier(build_fn=build_classifier, batch_size=10, nb_epoch=100)

where the batch size is 10 (then each batch will contain 800 samples). So, in every epoch, one of these 800 samples will be used to fit the model. This is what I have understood, correct me if I'm wrong.

The output is

Epoch 1/10

10/7200 [..............................] - ETA: 2:57 - loss: 0.6932 - acc: 0.1000
440/7200 [>.............................] - ETA: 4s - loss: 0.6866 - acc: 0.7932  
1100/7200 [===>..........................] - ETA: 2s - loss: 0.6744 - acc: 0.7900
1660/7200 [=====>........................] - ETA: 1s - loss: 0.6555 - acc: 0.7910
2220/7200 [========>.....................] - ETA: 1s - loss: 0.6329 - acc: 0.7869
2930/7200 [===========>..................] - ETA: 0s - loss: 0.5990 - acc: 0.7887
3520/7200 [=============>................] - ETA: 0s - loss: 0.5744 - acc: 0.7906
4230/7200 [================>.............] - ETA: 0s - loss: 0.5564 - acc: 0.7872
4880/7200 [===================>..........] - ETA: 0s - loss: 0.5432 - acc: 0.7881
5650/7200 [======================>.......] - ETA: 0s - loss: 0.5278 - acc: 0.7913
6280/7200 [=========================>....] - ETA: 0s - loss: 0.5165 - acc: 0.7933
6910/7200 [===========================>..] - ETA: 0s - loss: 0.5059 - acc: 0.7951
7200/7200 [==============================] - 1s 123us/step - loss: 0.5051 - acc: 0.7939

Why there are 13 subdivisions in the 1st epoch? In every epoch, there should be only one batch that must be executed, right?


Solution

  • The batch size is the number of samples in each batch. Each batch process is referred to as 1 step.

    One epoch is completed when all the data in the training set is used for training.

    Hence, for the given example, each epoch will have 800 steps and each batch will have 10 samples.