- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 download flower dataset into the environment?
The flower dataset can be downloaded using a google API that basically links to the flower dataset. The ‘get_file’ method can be used to pass the API as a parameter. Once this is done, the data gets downloaded into the environment.
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.
import numpy as np import os import PIL import PIL.Image import tensorflow as tf import tensorflow_datasets as tfds print("The Tensorflow version is :") print(tf.__version__) import pathlib print("The dataset is being downloaded") dataset_url = "https://storage.googleapis.com/download.tensorflow.org/example_images/flower_photos.tgz" data_dir = tf.keras.utils.get_file(origin=dataset_url, fname='flower_photos', untar=True) data_dir = pathlib.Path(data_dir) print("The number of images in the dataset") image_count = len(list(data_dir.glob('*/*.jpg'))) print(image_count) print("Sample data in the dataset") roses = list(data_dir.glob('roses/*')) PIL.Image.open(str(roses[2])) print("Some more sample data from the dataset") roses = list(data_dir.glob('roses/*')) PIL.Image.open(str(roses[4]))
Code credit: https://www.tensorflow.org/tutorials/load_data/images
Output
The Tensorflow version is : 2.4.0 The dataset is being downloaded Downloading data from https://storage.googleapis.com/download.tensorflow.org/example_images/flower_photos.tgz 228818944/228813984 [==============================] - 4s 0us/step The number of images in the dataset 3670 Sample data in the dataset Some more sample data from the dataset
Explanation
- The required packages are downloaded.
- The version of Tensorflow is displayed on the console.
- The data is downloaded using the API.
- A sample of the image is also displayed on the console.
- Related Articles
- How can Tensorflow be used to download the flower dataset using keras sequential API?
- How can Tensorflow be used to standardize the flower dataset?
- How can Tensorflow be used to split the flower dataset into training and validation?
- 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 premade estimator to download the Iris dataset?
- How can Tensorflow be used with flower dataset to continue training the model?
- How can Tensorflow be used to download and explore IMDB dataset in Python?
- How can Tensorflow and Python be used to download and prepare the CIFAR dataset?
- How can Tensorflow be used to download and explore the Illiad dataset using Python?
- How can Tensorflow be used to load the flower dataset and work with it?
- 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 be used to download and explore the Fashion MNIST dataset using Python?
