本文介绍了在keras中train_on_batch()有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

train_on_batch()fit() 有何不同?什么情况下我们应该使用train_on_batch()?

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

推荐答案

对于这个问题,这是一个 主要作者的简单回答:

For this question, it's a simple answer from the primary author:

使用 fit_generator,您可以使用生成器来生成验证数据好.一般来说,我会推荐使用 fit_generator,但使用train_on_batch 也能正常工作.这些方法只是为了方便在不同的用例中,没有正确"的方法.

train_on_batch 允许您根据您提供的样本集合明确更新权重,而无需考虑任何固定的批次大小.在您想要的情况下,您可以使用它:在显式的样本集合上进行训练.您可以使用这种方法在传统训练集的多个批次上维护自己的迭代,但允许 fitfit_generator 为您迭代批次可能更简单.

train_on_batch allows you to expressly update weights based on a collection of samples you provide, without regard to any fixed batch size. You would use this in cases when that is what you want: to train on an explicit collection of samples. You could use that approach to maintain your own iteration over multiple batches of a traditional training set but allowing fit or fit_generator to iterate batches for you is likely simpler.

最好使用 train_on_batch 的一种情况是更新单个新样本批次上的预训练模型.假设您已经训练并部署了一个模型,并且稍后您收到了一组以前从未使用过的新训练样本.您可以使用 train_on_batch 仅在这些样本上直接更新现有模型.其他方法也可以做到这一点,但在这种情况下使用 train_on_batch 是相当明确的.

One case when it might be nice to use train_on_batch is for updating a pre-trained model on a single new batch of samples. Suppose you've already trained and deployed a model, and sometime later you've received a new set of training samples previously never used. You could use train_on_batch to directly update the existing model only on those samples. Other methods can do this too, but it is rather explicit to use train_on_batch for this case.

除了像这样的特殊情况(或者你有一些教学理由在不同的训练批次中保持你自己的光标,或者对于特殊批次的某种类型的半在线训练更新),可能更好始终使用 fit(用于适合内存的数据)或 fit_generator(用于将批量数据作为生成器).

Apart from special cases like this (either where you have some pedagogical reason to maintain your own cursor across different training batches, or else for some type of semi-online training update on a special batch), it is probably better to just always use fit (for data that fits in memory) or fit_generator (for streaming batches of data as a generator).

这篇关于在keras中train_on_batch()有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 02:47