How can Tensorflow be used to download the flower dataset using keras sequential API?


The flower dataset can be downloaded using the keras sequential API with the help of google API that stores the dataset. The ‘get_file’ method is used with the API (URL) to fetch the dataset, and store it in memory.

Read More: What is TensorFlow and how Keras work with TensorFlow to create Neural Networks?

A neural network that contains at least one layer is known as a convolutional layer. Convolutional neural networks have been used to produce great results for a specific kind of problems, such as image recognition.  

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.

import matplotlib.pyplot as plt
import numpy as np
import os
import PIL
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.models import Sequential
import pathlib
print("Required pakcages imported")
dataset_url = "https://storage.googleapis.com/download.tensorflow.org/example_images/flower_photos.tgz"
data_dir = tf.keras.utils.get_file('flower_photos', origin=dataset_url, untar=True)
data_dir = pathlib.Path(data_dir)
print("Data has been downloaded")

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

Output

Required pakcages imported
Downloading data from https://storage.googleapis.com/download.tensorflow.org/example_images/flower_photos.tgz
228818944/228813984 [==============================] - 5s 0us/step
Data has been downloaded

Explanation

  • The required packages are imported.
  • The data is downloaded from the API.

Updated on: 20-Feb-2021

240 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements