- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# How can Tensorflow be used to standardize the data using Python?

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. Once the flower dataset has been downloaded using the ‘get_file’ method, it will be loaded into the environment to work with it.

The flower data can be standardized by introducing a normalization layer in the model. This layer is called the ‘Rescaling’ layer, which 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 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("Normalization layer is created ") normalization_layer = layers.experimental.preprocessing.Rescaling(1./255) print("This layer is applied to dataset using map function ") normalized_ds = train_ds.map(lambda x, y: (normalization_layer(x), y)) image_batch, labels_batch = next(iter(normalized_ds)) first_image = image_batch[0] print(np.min(first_image), np.max(first_image))

Code credit: https://www.tensorflow.org/tutorials/images/classification

## Output

Normalization layer is created This layer is applied to dataset using map function 0.0 1.0

## Explanation

- The RGB channel values are in the range [0, 255].
- This is not considered ideal for a neural network.
- As a thumb rule, ensure that the input values small.
- Hence, we can standardize values to fall in between the range [0, 1].
- This is done by using a Rescaling layer.
- It can be done by applying the layer on the dataset by calling the map function.
- Another way to do it is to include the layer within the model definition.
- This would simplify the deployment process.

- Related Questions & Answers
- How can Tensorflow be used to standardize the flower dataset?
- How can Tensorflow be used to visualize the data using Python?
- How can Tensorflow be used to fit the data to the model using Python?
- How can Tensorflow be used to compile the model using Python?
- How can Tensorflow be used to train the model using Python?
- How can Tensorflow be used to decode the predictions using Python?
- How can Tensorflow be used to check the predicrion using Python?
- How can Tensorflow be used to plot the results using Python?
- How can Tensorflow be used to check the predictions using Python?
- How can Tensorflow be used to compose layers using Python?
- How can Tensorflow be used to evaluate both the models on test data using Python?
- How can Tensorflow be used to view a sample of the vectorised data using Python?
- How can Tensorflow and pre-trained model be used to visualize the data using Python?
- How can Tensorflow be used to export the model built using Python?
- How can Tensorflow be used to load the Illiad dataset using Python?