"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why does my Keras model only train on a portion of my dataset?

Why does my Keras model only train on a portion of my dataset?

Published on 2024-11-18
Browse:515

 Why does my Keras model only train on a portion of my dataset?

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.

Latest tutorial More>

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