text_plain_output_1.png image_output_2.png image_output_1.png
from glob import glob

from keras.applications import InceptionV3

from keras.layers import Dense, Flatten, BatchNormalization, Dropout

from keras.models import Sequential

from keras.preprocessing.image import ImageDataGenerator, load_img, img_to_array

import matplotlib.pyplot as plt

train_path = '../input/100-bird-species/285 birds/train'
test_path = '../input/100-bird-species/285 birds/test'
validation_path = '../input/100-bird-species/285 birds/valid'

img = load_img(train_path + '/ANHINGA/001.jpg')
plt.axis('off')
img = load_img(train_path + '/BALD EAGLE/018.jpg')
plt.axis('off')

fig, axs = plt.subplots(2, 2, figsize=(8, 8))
axs[0,0].imshow(load_img(train_path + "/BARN OWL/018.jpg"))
axs[0,0].axis("off")

axs[0,1].imshow(load_img(train_path + "/ALBATROSS/001.jpg"))
axs[0,1].axis("off")

axs[1,0].imshow(load_img(train_path + "/CANARY/107.jpg"))                        
axs[1,0].axis("off")

axs[1,1].imshow(load_img(train_path + "/CROW/100.jpg"))
axs[1,1].axis("off")

plt.show()

className = glob(train_path + '/*')
NumberofClass = len(className)

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

batch_size = 256
train_datagen = ImageDataGenerator(rescale=1 / 255, shear_range=0.3, horizontal_flip=True, zoom_range=0.3)
val_datagen = ImageDataGenerator(rescale=1 / 255)
train_generator = train_datagen.flow_from_directory(train_path, target_size=(224, 224), batch_size=batch_size, color_mode='rgb', class_mode='categorical')
val_generator = val_datagen.flow_from_directory(validation_path, target_size=(224, 224), batch_size=batch_size, color_mode='rgb', class_mode='categorical')

IncV3 = InceptionV3(include_top=False, weights='imagenet', input_shape=(224, 224, 3))

model = Sequential()
model.add(IncV3)
for layer in model.layers:
    layer.trainable = False
model.add(Flatten())
model.add(Dense(units=2048, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(units=NumberofClass, activation='softmax'))

model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

history = model.fit(train_generator, validation_data=val_generator, epochs=10, batch_size=batch_size)

plt.figure(figsize=(8, 8))
plt.plot(history.history['loss'], color='b', label='Training loss')
plt.plot(history.history['val_loss'], color='r', label='Validation loss')
plt.legend()
plt.show()
plt.figure()
plt.figure(figsize=(8, 8))
plt.plot(history.history['accuracy'], color='b', label='Training accuracy')
plt.plot(history.history['val_accuracy'], color='r', label='Validation accuracy')
plt.legend()
plt.show()