
- 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 pre-process the flower training dataset?
The flower dataset can be pre-processed using the keras preprocessing API. It has a method named ‘image_dataset_from_directory’ that takes the validation set, the directory where data is stored, and other parameters to process the dataset.
Read More: What is TensorFlow and how Keras work with TensorFlow to create Neural Networks?
We will use the Keras Sequential API, 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. An image classifier is created using a keras.Sequential model, and data is loaded using preprocessing.image_dataset_from_directory.
Data is efficiently loaded off disk. Overfitting is identified and techniques are applied to mitigate it. These techniques include data augmentation, and dropout. There are images of 3700 flowers. This dataset contaisn 5 sub directories, and there is one sub directory per class. They are: daisy, dandelion, roses, sunflowers, and tulips.
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("Pre-processing the dataset using keras.preprocessing") val_ds = tf.keras.preprocessing.image_dataset_from_directory( data_dir, validation_split=0.2, subset="validation", seed=123, image_size=(img_height, img_width), batch_size=batch_size) class_names = train_ds.class_names print("The class names are:") print(class_names)
Code credit: https://www.tensorflow.org/tutorials/images/classification
Output
Pre-processing the dataset using keras.preprocessing Found 3670 files belonging to 5 classes. Using 734 files for validation. The class names are: ['daisy', 'dandelion', 'roses', 'sunflowers', 'tulips']
Explanation
- The dataset is processed using keras.preprocessing method.
- The next step is to display the class names on the console.
- Related Articles
- How can Tensorflow be used with flower dataset to continue training the model?
- How can Tensorflow be used to split the flower dataset into training and validation?
- How can Tensorflow be used with pre-trained model to build the training and validation dataset?
- How can Tensorflow be used to standardize the flower dataset?
- 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 prepare the IMDB dataset for training in Python?
- 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 with the flower dataset to compile and fit the model?
- How can Tensorflow and pre-trained model be used to configure the dataset for performance?
- How can Tensorflow and pre-trained model be used to continue training the model using Python?
- How can Tensorflow be used to split the Illiad dataset into training and test data in Python?
