What is the use of train_on_batch() in keras?

后端 未结 4 1687
故里飘歌
故里飘歌 2020-12-14 06:05

How train_on_batch() is different from fit()? What are the cases when we should use train_on_batch()?

4条回答
  •  独厮守ぢ
    2020-12-14 06:40

    Train_on_batch will also see a performance increase over fit and fit generator if youre using large datasets and don't have easily serializable data (like high rank numpy arrays), to write to tfrecords.

    In this case you can save the arrays as numpy files and load up smaller subsets of them (traina.npy, trainb.npy etc) in memory, when the whole set won't fit in memory. You can then use tf.data.Dataset.from_tensor_slices and then using train_on_batch with your subdataset, then loading up another dataset and calling train on batch again, etc, now you've trained on your entire set and can control exactly how much and what of your dataset trains your model. You can then define your own epochs, batch sizes, etc with simple loops and functions to grab from your dataset.

提交回复
热议问题