
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How can Tensorflow be used to configure the dataset for performance?
The flower dataset can be configured for performance with the help of buffer prefetch, shuffle method, and cache method. Buffered prefetching can be used to ensure that the data can be taken from disk without having I/O become blocking. Dataset.cache() keeps the images in memory after they have been loaded off disk during the first epoch. Dataset.prefetch() will overlap the data preprocessing and model execution while training.
Read More: What is TensorFlow and how Keras work with TensorFlow to create Neural Networks?
The Keras Sequential API is used, which is helpful in building a sequential model that is used to work with a plain stack of layers, where every layer has exactly one input tensor and one output tensor.
We are using the Google Colaboratory to run the below code. Google Colab or Colaboratory helps run Python code over the browser and requires zero configuration and free access to GPUs (Graphical Processing Units). Colaboratory has been built on top of Jupyter Notebook.
print("Configuring the dataset for better performance") AUTOTUNE = tf.data.AUTOTUNE train_ds = train_ds.cache().shuffle(1000).prefetch(buffer_size=AUTOTUNE) val_ds = val_ds.cache().prefetch(buffer_size=AUTOTUNE)
Code credit: https://www.tensorflow.org/tutorials/images/classification
Output
Configuring the dataset for better performance
Explanation
- The concept of buffered prefetching can be used so that the data can be taken from disk without having I/O become blocking.
- There are two important methods that can be used when loading data.
- cache() keeps the images in memory after they have been loaded off disk during the first epoch.
- This will ensure that the dataset doesn't become a bottleneck when the model is being trained.
- If the dataset is too large to fit into memory, this method can be used to create a performant on-disk cache.
- prefetch() will overlap the data preprocessing and model execution while training.
- Related Articles
- How can Tensorflow be used to configure the flower dataset for performance?
- How can Tensorflow and pre-trained model be used to configure the dataset for performance?
- How can Tensorflow configure the flower dataset for performance?
- How can TensorFlow be used to configure the IMDB dataset to give good performance and create a model?
- How can Tensorflow be used to configure the stackoverflow question dataset using Python?
- How can Tensorflow be used to standardize the flower dataset?
- How can Tensorflow be used to define a model for MNIST dataset?
- How can Tensorflow be used to prepare the IMDB dataset for training in Python?
- How can Tensorflow be used with Estimators to train the model for titanic dataset?
- How can Tensorflow be used to build a normalization layer for the abalone dataset?
- How can Tensorflow be used to save and load weights for MNIST dataset?
- How can Tensorflow be used to load the Illiad dataset using Python?
- How can Tensorflow be used to train the Illiad dataset using Python?
- How can Tensorflow be used with Estimators to split the iris dataset?
- How can Tensorflow be used to train and evaluate the titanic dataset?
