Home > Blockchain >  How batch_size parameter works on Keras .fit() when using custom generators
How batch_size parameter works on Keras .fit() when using custom generators

Time:03-03

Given that my dataset is too big to load in memory all at once I opted to use a custom generator with a batch size of 32, this means my data will be loaded in batch sizes of 32. Now if I understand correctly when I feed this generator as a paramenter to the .fit() of Keras that means that in one epoch all of the training data will be seen by the model in batches of 32. So my question is, if I specify a batch_size to the .fit() method so I can control when the weights are updated, how would this work, or should I not specify it and the weights will be updated for every batch of the generator?

CodePudding user response:

In your case, I would leave it as it is. As the docs explain, when you define the batch size in model.fit(...), you are defining the:

[...] Number of samples per gradient update. [...]

However if you read on, it also says:

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

So, the batch size from your generator should be respected when passing it to model.fit

  • Related