The flower dataset would have given a certain percentage of accuracy when a model is created. If it is required to configure the model for performance, the buffer prefetch is used along with the Rescaling layer. This layer is applied using the Keras model, on the dataset, by making the rescaling layer a part of the Keras model.
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.
AUTOTUNE = tf.data.AUTOTUNE train_ds = train_ds.cache().prefetch(buffer_size=AUTOTUNE) val_ds = val_ds.cache().prefetch(buffer_size=AUTOTUNE) num_classes = 5 print("A sequential model is built") model = tf.keras.Sequential([ layers.experimental.preprocessing.Rescaling(1./255), layers.Conv2D(32, 3, activation='relu'), layers.MaxPooling2D(), layers.Conv2D(32, 3, activation='relu'), layers.MaxPooling2D(), layers.Conv2D(32, 3, activation='relu'), layers.MaxPooling2D(), layers.Flatten(), layers.Dense(128, activation='relu'), layers.Dense(num_classes) ])
Code credit: https://www.tensorflow.org/tutorials/load_data/images
A sequential model is built