- 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
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
How can Tensorflow be used to standardize the flower dataset?
Data standardization refers to the act of scaling the dataset to a level so that all the features can be represented using equivalent units. The rescaling layer is built using the ‘Rescaling’ method which is present in Keras module. The layer is applied to the entire dataset using the ‘map’ method.
Read More: What is TensorFlow and how Keras work with TensorFlow to create Neural Networks?
We will be using the flowers dataset, which contains images of several thousands of flowers. It contains 5 sub-directories, and there is one sub-directory for every class.
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.
from tensorflow.keras import layers print("Standardizing the data using a rescaling layer") normalization_layer = tf.keras.layers.experimental.preprocessing.Rescaling(1./255) print("This layer can be applied by calling the map function on the dataset") normalized_ds = train_ds.map(lambda x, y: (normalization_layer(x), y)) image_batch, labels_batch = next(iter(normalized_ds)) first_image = image_batch print(np.min(first_image), np.max(first_image))
Code credit: https://www.tensorflow.org/tutorials/load_data/images
Standardizing the data using a rescaling layer This layer can be applied by calling the map function on the dataset 0.0 0.96902645
- The RGB channel values are in the range of 0 and 255.
- This isn't good for a neural network.
- The idea is to make the input data as small as possible.
- The values in the image are standardized, to be in thenage of 0 and 1.
- This is done with the help of a rescaling layer.
- Alternative is to include this rescaling layer in the definition of model, which would simplify the deployment.
- Related Articles
- How can Tensorflow be used to download flower dataset into the environment?
- How can Tensorflow be used to visualize the flower dataset using Python?
- How can Tensorflow be used to configure the flower dataset for performance?
- How can Tensorflow be used to pre-process the flower training dataset?
- How can Tensorflow be used with flower dataset to continue training the model?
- How can Tensorflow be used to load the flower dataset and work with it?
- How can Tensorflow be used to download the flower dataset using keras sequential API?
- How can Tensorflow be used to explore the flower dataset using keras sequential API?
- How can Tensorflow be used to split the flower dataset into training and validation?
- How can Tensorflow be used with the flower dataset to compile and fit the model?
- How can Tensorflow be used to standardize the data using Python?
- How can Tensorflow be used to load the flower dataset and model off the disk using Python?
- How can Tensorflow be used to create a pair using a file path for the flower dataset?
- How can Tensorflow configure the flower dataset for performance?
- How can Tensorflow be used to configure the dataset for performance?