Keras Training Data Discrepancy
While following the official TensorFlow guide to build a neural network with Keras, you noticed that the model uses only a portion of the available dataset during training, despite having 60,000 entries.
Understanding Batch Size
The number 1875 displayed during model fitting is not an indication of training samples but rather the number of batches. The model.fit method has an optional argument, batch_size, which determines the number of data points that are processed simultaneously during training.
If you do not specify a batch_size, the default value is 32. In this case, with a total dataset of 60,000 images, the number of batches becomes:
60000 / 32 = 1875
Therefore, although you have 60,000 data points, the model actually trains on 1875 batches, each batch containing 32 data points. This is a common practice to reduce the memory footprint and improve training speed.
Adjusting Batch Size
To use the entire dataset during training without batching, you can specify a batch_size of 60000 in the model.fit method. However, this can potentially slow down training and require more memory.
Alternatively, you can adjust the batch_size to find a compromise between training efficiency and memory utilization. For example, you could set it to 1024 or 2048, which would still significantly reduce the number of batches without sacrificing too much performance.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3