Calling “fit” multiple times in Keras

后端 未结 2 1456
伪装坚强ぢ
伪装坚强ぢ 2021-02-01 01:54

I\'ve working on a CNN over several hundred GBs of images. I\'ve created a training function that bites off 4Gb chunks of these images and calls fit over each of th

相关标签:
2条回答
  • 2021-02-01 02:38

    This question was raised at the Keras github repository in Issue #4446: Quick Question: can a model be fit for multiple times? It was closed by François Chollet with the following statement:

    Yes, successive calls to fit will incrementally train the model.

    So, yes, you can call fit multiple times.

    0 讨论(0)
  • 2021-02-01 02:41

    For datasets that do not fit into memory, there is an answer in the Keras Documentation FAQ section

    You can do batch training using model.train_on_batch(X, y) and model.test_on_batch(X, y). See the models documentation.

    Alternatively, you can write a generator that yields batches of training data and use the method model.fit_generator(data_generator, samples_per_epoch, nb_epoch).

    You can see batch training in action in our CIFAR10 example.

    So if you want to iterate your dataset the way you are doing, you should probably use model.train_on_batch and take care of the batch sizes and iteration yourself.

    One more thing to note is that you should make sure the order in which the samples you train your model with is shuffled after each epoch. The way you have written the example code seems to not shuffle the dataset. You can read a bit more about shuffling here and here

    0 讨论(0)
提交回复
热议问题