简体   繁体   中英

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. 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,

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

  1. 5 images(data size 5*512*512) are taken into training at a time?
  2. 5 column among a single image(data size 5*512) are taken into training at a time?

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

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. 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.

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?

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. Next, it takes the second 100 samples (from 101st to 200th) and trains the network again. 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. The simplest solution is just to get the final 50 samples and train the network.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM