application_vnd.jupyter.stderr_output_2.png text_plain_output_4.png text_plain_output_3.png text_plain_output_1.png
from keras.callbacks import ReduceLROnPlateau

from keras.layers import Dense, Activation, Dropout, Flatten, Conv2D, MaxPooling2D, AveragePooling2D

from keras.layers.normalization import BatchNormalization

from keras.models import Sequential

import keras

model = Sequential()
model.add(Conv2D(filters=32, kernel_size=(3, 3), activation='relu', strides=(1, 1), padding='valid'))
model.add(MaxPooling2D(pool_size=(3, 3), strides=(1, 1), padding='valid'))
model.add(BatchNormalization())
model.add(Conv2D(filters=64, kernel_size=(3, 3), activation='relu', strides=(1, 1), padding='valid'))
model.add(MaxPooling2D(pool_size=(3, 3), strides=(1, 1), padding='valid'))
model.add(BatchNormalization())
model.add(Conv2D(filters=128, kernel_size=(3, 3), activation='relu', strides=(1, 1), padding='valid'))
model.add(MaxPooling2D(pool_size=(3, 3), strides=(1, 1), padding='valid'))
model.add(BatchNormalization())
model.add(Flatten())
model.add(Dense(units=512, activation='relu'))
model.add(Dense(units=120, activation='relu'))
model.add(Dense(units=10, activation='softmax'))

sgd = keras.optimizers.SGD(lr=0.001, decay=1e-06, momentum=0.9, nesterov=True)
model.compile(loss='sparse_categorical_crossentropy', optimizer=sgd, metrics=['sparse_categorical_accuracy'])
lrr = ReduceLROnPlateau(monitor='val_acc', patience=3, verbose=1, factor=0.5, min_lr=1e-05)

result = model.fit(X_train, y_train, batch_size=70, epochs=20, verbose=2, validation_split=0.25, callbacks=[lrr], shuffle=True)
'\nresult = model.fit(X, \n                   y, \n                   batch_size=70, \n                   epochs=3, \n                   verbose=2, \n                   validation_split=0.25, \n                   callbacks=[lrr],\n                   shuffle=True)\n'

model.summary()

y_pred = model.predict(X_test, verbose=2)
y_pred[:, 0]

test_loss, test_acc = model.evaluate(X_test, y_test)
print('Test accuracy:', test_acc)