简体   繁体   English

当训练数据是图像时,Keras model.fit() 中的“批次”是什么

[英]what is a “batch” in Keras model.fit() when training data are images

say I have a set of image data for training, 20 input images and 20 output images, with image size 512*512.假设我有一组用于训练的图像数据,20 个输入图像和 20 个 output 图像,图像大小为 512*512。 Firstly I prepare training data as "train_image_input"(size 20*512*512) and "train_image_output"(size 20*512*512), then I run below code in Keras,首先,我将训练数据准备为“train_image_input”(大小 20*512*512)和“train_image_output”(大小 20*512*512),然后在 Keras 中运行以下代码,

model.fit(train_image_input, train_image_output,epochs=3,batch_size=5)

I would like to confirm the definition of a "batch" when data are images, on the above example, does "batch_size=5" means当数据是图像时,我想确认“批处理”的定义,在上面的示例中,“batch_size = 5”是否意味着

  1. 5 images(data size 5*512*512) are taken into training at a time?一次训练 5 张图像(数据大小 5*512*512)?
  2. 5 column among a single image(data size 5*512) are taken into training at a time?一次将单个图像(数据大小5 * 512)中的5列进行训练?

I had read the article: https://machinelearningmastery.com/difference-between-a-batch-and-an-epoch/ and the below description confuses me about the definition of sample/batch when data are images我读过这篇文章: https://machinelearningmastery.com/difference-between-a-batch-and-an-epoch/下面的描述让我对数据是图像时样本/批次的定义感到困惑

What Is a Sample?什么是样品? A sample is a single row of data.样本是单行数据。 It contains inputs that are fed into the algorithm and an output that is used to compare to the prediction and calculate an error.它包含输入算法的输入和用于与预测进行比较并计算误差的 output。 A training dataset is comprised of many rows of data, eg many samples.训练数据集由多行数据组成,例如许多样本。 A sample may also be called an instance, an observation, an input vector, or a feature vector.样本也可以称为实例、观察、输入向量或特征向量。 Now that we know what a sample is, let's define a batch.现在我们知道了什么是样本,让我们定义一个批次。 What Is a Batch?什么是批次? The batch size is a hyperparameter that defines the number of samples to work through before updating the internal model parameters.批量大小是一个超参数,用于定义在更新内部 model 参数之前要处理的样本数量。

Further more, if I set "batch_size=30" which is larger of number of images, there is no error during code execution, so I may consider the second one(data size 5*512) is correct?此外,如果我设置图像数量较大的“batch_size=30”,代码执行过程中没有错误,所以我可能认为第二个(数据大小5 * 512)是正确的?

Thanks.谢谢。

The batch size defines the number of samples that will be propagated through the network.批量大小定义将通过网络传播的样本数量。

For instance, let's say you have 1050 training samples and you want to set up a batch_size equal to 100. The algorithm takes the first 100 samples (from 1st to 100th) from the training dataset and trains the network.例如,假设您有 1050 个训练样本,并且您希望将 batch_size 设置为 100。该算法从训练数据集中获取前 100 个样本(从第 1 个到第 100 个)并训练网络。 Next, it takes the second 100 samples (from 101st to 200th) and trains the network again.接下来,它获取第二个 100 个样本(从第 101 个样本到第 200 个样本)并再次训练网络。 We can keep doing this procedure until we have propagated all samples through the network.我们可以继续执行此过程,直到我们通过网络传播了所有样本。 The problem might happen with the last set of samples.最后一组样本可能会出现问题。 In our example, we've used 1050 which is not divisible by 100 without the remainder.在我们的示例中,我们使用了 1050,它不能被 100 整除而没有余数。 The simplest solution is just to get the final 50 samples and train the network.最简单的解决方案就是获取最后的 50 个样本并训练网络。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Keras:model.fit 中的详细(值 1)显示较少的训练数据 - Keras: verbose (value 1) in model.fit shows less training data Tensorflow Keras:在 model.fit() 上进行训练 - Tensorflow Keras: Training Holting on model.fit() Keras LSTM批次大小和模型.fit() - Keras LSTM Batch Size and model.fit() 使用model.fit时如何将'training'参数传递给tf,keras.Model - how to pass in 'training' argument to tf,keras.Model when using model.fit 在 Keras model.fit 中将训练数据指定为元组 (x, y) 的正确方法,具有多个输入和输出 - Correct way to specify training data as tuple (x, y) in Keras model.fit with multiple inputs and outputs model.fit中的批次大小和Keras中的输入形状 - Batch size in model.fit and input shape in Keras Keras model.fit UnboundLocalError - Keras model.fit UnboundLocalError 带有 Model.Fit() 的 Keras InvalidArgumentError - Keras InvalidArgumentError With Model.Fit() “validation_data 将覆盖validation_split”是什么意思。 在 keras model.fit 文档中 - What is the meaning of "validation_data will override validation_split." in keras model.fit documentation Keras:使用 model.train_on_batch() 和 model.fit() 获得不同的精度。 可能是什么原因以及如何解决? - Keras: Getting different accuracy using model.train_on_batch() and model.fit(). What could be the reason and how to fix that?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM