
- 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 load the flower dataset and work with it?
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.
Read More: What is TensorFlow and how Keras work with TensorFlow to create Neural Networks?
Once the flower dataset has been downloaded using the ‘get_file’ method, it will be loaded into the environment to work with it. The loader parameters are explicitly mentioned and the loaded data is split into training and validation set.
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("Loading parameters for the loader") batch_size = 32 img_height = 180 img_width = 180 print("Preprocessing the image dataset using Keras") print("Splitting dataset into training and validation set ") train_ds = tf.keras.preprocessing.image_dataset_from_directory( data_dir, validation_split=0.2, subset="training", seed=123, image_size=(img_height, img_width), batch_size=batch_size) print("Splitting dataset into training and validation set ") 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) print("Printing the class names present in sub-directories") class_names = train_ds.class_names print(class_names)
Code credit: https://www.tensorflow.org/tutorials/load_data/images
Output
Loading parameters for the loader Preprocessing the image dataset using Keras Splitting dataset into training and validation set Found 3670 files belonging to 5 classes. Using 2936 files for training. Splitting dataset into training and validation set Found 3670 files belonging to 5 classes. Using 734 files for validation. Printing the class names present in sub-directories ['daisy', 'dandelion', 'roses', 'sunflowers', 'tulips']
Explanation
- The parameters are defined.
- The dataset is split into training set and validation set.
- The class names into which every image is classified is displayed on the console.
- Related Articles
- How can Tensorflow be used to load the flower dataset and model off the disk using Python?
- How can Tensorflow be used to standardize the flower dataset?
- How can Tensorflow be used with flower dataset to continue training the model?
- How can Tensorflow be used with the flower dataset to compile and fit the model?
- 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 to load the Illiad dataset using Python?
- How can Tensorflow be used to split the flower dataset into training and validation?
- How can Tensorflow be used to save and load weights for MNIST dataset?
- How can Tensorflow be used to load the csv data from abalone dataset?
- 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 load the dataset which contains stackoverflow questions using Python?
