神经网络的批量大小是多少?

What batch size for neural network?

我有一个包含 36 个数据点的训练集。我想在上面训练一个神经网络。我可以选择作为批量大小,例如 1 或 12 或 36(每个数字都可以除以 36)。

当然,当我增加批量大小时,训练运行时间会大大减少。

如果我选择例如12 作为批量大小而不是 1?

批量大小没有黄金法则。期间。

不过。您的数据集 非常小 ,批量大小 可能根本无关紧要 ,您所有的问题都将来自数据不足,而不是任何超参数。

我同意 lejlot。鉴于数据量非常小,批量大小不是当前模型构建中的问题。一旦您转移到无法放入内存的更大数据,然后尝试不同的批量大小(例如,2 的一些幂,即 32、128、512 等)。

批量大小的选择取决于:

  1. 你的硬件容量和型号架构。给定足够的内存和将数据从内存传输到 CPU/GPU 的总线容量,较大的批量大小会导致更快的学习。然而,争论的焦点是质量是否仍然存在。
  2. 算法及其实现。例如,Keras python 包(基于神经网络算法的 Theano 和 TensorFlow 实现)states:

A batch generally approximates the distribution of the input data better than a single input. The larger the batch, the better the approximation; however, it is also true that the batch will take longer to process and will still result in only one update. For inference (evaluate/predict), it is recommended to pick a batch size that is as large as you can afford without going out of memory (since larger batches will usually result in faster evaluating/prediction).

尝试过不同的批量大小后,您会有更好的直觉。如果您的硬件和时间允许,请让机器为您选择正确的批次(作为网格搜索的一部分循环遍历不同的批次大小。

这里有一些很好的答案:one, two