text_plain_output_1.png
from tensorflow.keras import backend

from tensorflow.keras import backend, models, layers, regularizers , optimizers

from tensorflow.keras.callbacks import EarlyStopping

from tensorflow.keras.layers import BatchNormalization , Concatenate

from tensorflow.keras.preprocessing.image import ImageDataGenerator

train_directory = '../input/100-bird-species/train'
val_directory = '../input/100-bird-species/valid'
test_directory = '../input/100-bird-species/test'

train_datagen = ImageDataGenerator(rescale=1 / 255)
val_datagen = ImageDataGenerator(rescale=1 / 255)
test_datagen = ImageDataGenerator(rescale=1 / 255)

train_generator = train_datagen.flow_from_directory(train_directory, target_size=(224, 224), batch_size=32, color_mode='rgb', class_mode='sparse')
validation_generator = train_datagen.flow_from_directory(val_directory, target_size=(224, 224), batch_size=32, color_mode='rgb', class_mode='sparse')
test_generator = test_datagen.flow_from_directory(test_directory, target_size=(224, 224), batch_size=32, color_mode='rgb', class_mode='sparse')

train_generator.class_indices

num_classes = len(train_generator.class_indices)

backend.clear_session()
model_base = models.Sequential()
model_base.add(layers.Conv2D(512, (3, 3), activation='relu', input_shape=(224, 224, 3)))
model_base.add(layers.MaxPool2D((2, 2)))
model_base.add(BatchNormalization())
model_base.add(layers.Conv2D(512, (3, 3), activation='relu'))
model_base.add(layers.MaxPool2D((2, 2)))
model_base.add(BatchNormalization())
model_base.add(layers.Conv2D(256, (3, 3), activation='relu'))
model_base.add(layers.MaxPool2D((2, 2)))
model_base.add(BatchNormalization())
model_base.add(layers.Flatten())
model_base.add(layers.Dense(128, activation='relu'))
model_base.add(layers.Dropout(0.5))
model_base.add(layers.Dense(num_classes, activation='softmax'))
model_base.compile(optimizer=optimizers.Adam(lr=0.001), loss='sparse_categorical_crossentropy', metrics=['accuracy'])
history = model_base.fit_generator(train_generator, epochs=50, validation_data=validation_generator, validation_steps=20, verbose=1, callbacks=[EarlyStopping(monitor='val_accuracy', patience=5, restore_best_weights=True)])
test_loss, test_acc = model_base.evaluate_generator(test_generator, steps=20)
print('test_acc:', test_acc)