application_vnd.jupyter.stderr_output_1.png
from keras.callbacks import ModelCheckpoint,ReduceLROnPlateau,EarlyStopping

from keras.layers import Conv2D,MaxPooling2D,GlobalMaxPooling2D

from keras.layers import Dense,LSTM,GlobalAveragePooling1D,GlobalAveragePooling2D

from keras.layers import Input,Activation,Flatten,Dropout,BatchNormalization

from keras.layers.advanced_activations import PReLU,LeakyReLU

from keras.metrics import top_k_categorical_accuracy,categorical_accuracy

from keras.models import Sequential,load_model,Model

import warnings
warnings.filterwarnings('ignore')
import numpy as np, pandas as pd, pylab as pl, h5py
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import OneHotEncoder
from IPython import display
from keras.preprocessing.image import ImageDataGenerator
from keras.callbacks import ModelCheckpoint, ReduceLROnPlateau, EarlyStopping
from keras.metrics import top_k_categorical_accuracy, categorical_accuracy
from keras.models import Sequential, load_model, Model
from keras.layers import Dense, LSTM, GlobalAveragePooling1D, GlobalAveragePooling2D
from keras.layers.advanced_activations import PReLU, LeakyReLU
from keras.layers import Input, Activation, Flatten, Dropout, BatchNormalization
from keras.layers import Conv2D, MaxPooling2D, GlobalMaxPooling2D
fw = 'weights.best.letters.hdf5'

def top_3_categorical_accuracy(y_true, y_pred):
    return top_k_categorical_accuracy(y_true, y_pred, k=3)
def gray_model():
    model = Sequential()
    model.add(Conv2D(32, (5, 5), padding='same', input_shape=x_train1.shape[1:]))
    model.add(LeakyReLU(alpha=0.02))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Dropout(0.25))
    model.add(Conv2D(128, (5, 5)))
    model.add(LeakyReLU(alpha=0.02))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    model.add(Dropout(0.25))
    model.add(GlobalMaxPooling2D())
    model.add(Dense(1024))
    model.add(LeakyReLU(alpha=0.02))
    model.add(Dropout(0.25))
    model.add(Dense(128))
    model.add(LeakyReLU(alpha=0.02))
    model.add(Dropout(0.25))
    model.add(Dense(33))
    model.add(Activation('softmax'))
    model.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=[categorical_accuracy, top_3_categorical_accuracy])
    return model
gray_model = gray_model()

checkpointer = ModelCheckpoint(filepath=fw, verbose=2, save_best_only=True)
lr_reduction = ReduceLROnPlateau(monitor='val_loss', patience=10, verbose=2, factor=0.5)
estopping = EarlyStopping(monitor='val_loss', patience=20, verbose=2)
history = gray_model.fit(x_train1, y_train1, epochs=200, batch_size=64, verbose=2, validation_data=(x_valid1, y_valid1), callbacks=[checkpointer, lr_reduction, estopping])