text_plain_output_1.png
from keras.layers import Dropout, Flatten, Dense, GlobalAveragePooling2D,Conv2D,MaxPooling2D,BatchNormalization

from keras.models import Sequential, Model

X_train.shape

X_cv.shape

X_test.shape

img_width = img_height = 224
if K.image_data_format() == 'channels_first':
    input_shape = (3, img_width, img_height)
    X_train = X_train.reshape(X_train.shape[0], 3, img_width, img_height)
    X_cv = X_cv.reshape(X_cv.shape[0], 3, img_width, img_height)
    X_test = X_test.reshape(X_test.shape[0], 3, img_width, img_height)
else:
    input_shape = (img_width, img_height, 3)
    X_train = X_train.reshape(X_train.shape[0], img_width, img_height, 3)
    X_cv = X_cv.reshape(X_cv.shape[0], img_width, img_height, 3)
    X_test = X_test.reshape(X_test.shape[0], img_width, img_height, 3)

epoch = 25
batch = 32
num_classes = 3

model = Sequential()
model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=input_shape, kernel_initializer='he_normal'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, kernel_size=(3, 3), activation='relu', kernel_initializer='he_normal'))
model.add(MaxPooling2D(pool_size=(3, 3)))
model.add(Conv2D(64, kernel_size=(3, 3), activation='relu', kernel_initializer='he_normal'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(512, activation='relu', kernel_initializer='he_normal'))
model.add(Dropout(0.25))
model.add(Dense(256, activation='relu', kernel_initializer='he_normal'))
model.add(Dropout(0.4))
model.add(Dense(128, activation='relu', kernel_initializer='he_normal'))
model.add(Dropout(0.3))
model.add(BatchNormalization())
model.add(Dense(64, activation='relu', kernel_initializer='he_normal'))
model.add(Dropout(0.5))
model.add(Dense(num_classes, activation='softmax', kernel_initializer='glorot_normal'))
model.summary()

model.compile(loss='categorical_crossentropy', optimizer='Adam', metrics=['accuracy'])
his = model.fit(X_train, y_train, batch_size=batch, epochs=epoch, verbose=1, validation_data=(X_cv, y_cv))

score = model.evaluate(X_test, y_test, verbose=0)
print('The test accuracy for the model is %f ' % (score[1] * 100))