Why is the validation accuracy low even though I'm using a pretrained model?

Viewed 32

I am trying to classify 10 species of birds on google colab using a pretrained model from tensorflow hub which has been trained on 964 species of birds. But when I train it, the accuracy isn't as high as I thought it would be. The loss is also considerably high. I'm not sure if I've done something wrong when I imported the model. For some reason when I view model.summary(), the # of parameters for the KerasLayer shows as 0. Why is that? I have attached all my code below.

   import numpy as np
   import tensorflow as tf
   from tensorflow import keras
   from keras.preprocessing.image import ImageDataGenerator
   import matplotlib.pyplot as plt

  from google.colab import drive
  drive.mount('/content/gdrive', force_remount=True)
  dataset_path = '/content/gdrive/MyDrive/images/'


  image_size = (224,224)
  batch_size = 10

  train_datagen = ImageDataGenerator(rescale=1./255, 
                               rotation_range=15,
                               zoom_range = (0.95,0.95),
                               width_shift_range=0.1,
                               height_shift_range=0.1,
                               validation_split=0.2,
                               dtype = tf.float32,
                              )

  validation_datagen = ImageDataGenerator(rescale=1./255, validation_split=0.2, dtype = 
  tf.float32,)

  train_batches = train_datagen.flow_from_directory(
  dataset_path,
  target_size = image_size,
  batch_size = batch_size,
  color_mode='rgb',
  class_mode = 'categorical',
  shuffle = True,
  seed = 123,
  subset = 'training', )

  validation_batches = validation_datagen.flow_from_directory(
  dataset_path,
  target_size = image_size,
  batch_size = batch_size,
  color_mode='rgb',
  class_mode = 'categorical',
  shuffle = True,
  seed = 123,
  subset = 'validation', )

  test_batches = validation_datagen.flow_from_directory(
  dataset_path,
  target_size = image_size,
  batch_size = batch_size,
  color_mode='rgb',
  class_mode = 'categorical',
  shuffle = True,
  seed = 123,
  subset = 'validation', )

  from keras import layers
  import tensorflow_hub as hub


 url = 'https://tfhub.dev/google/aiy/vision/classifier/birds_V1/1'
 base_model = hub.KerasLayer(url, input_shape=(224, 224, 3), trainable=False)

 num_of_birds = 10

 model = tf.keras.Sequential([
 base_model,
 tf.keras.layers.Dense(num_of_birds, activation='softmax'),
  ])

 model.summary()

model summary

When I train the model on a high number of epochs, the accuracy actually drops lower. Therefore I have only trained it for one epoch. But even then I'm not satisfied with the accuracy. I want it to be higher. Can somebody please tell me what I've done wrong? training and testing

0 Answers
Related