text_plain_output_1.png image_output_1.png
from keras.callbacks import EarlyStopping, ReduceLROnPlateau,ModelCheckpoint

from tensorflow.keras.layers import Dense,Conv2D, MaxPooling2D, Flatten,BatchNormalization,Dropout

from tensorflow.keras.models import Sequential

from tensorflow.keras.optimizers import Adam

from tensorflow.keras.utils import to_categorical

from tensorflow.keras.utils import to_categorical
label_train = to_categorical(label_train)

label_validation = to_categorical(label_validation)

model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=(28, 28, 1), padding='same', activation='relu'))
model.add(BatchNormalization(momentum=0.9, epsilon=1e-05, gamma_initializer='uniform'))
model.add(MaxPooling2D())
model.add(Dropout(0.25))
model.add(Conv2D(64, (3, 3), padding='same', activation='relu'))
model.add(BatchNormalization(momentum=0.9, epsilon=1e-05, gamma_initializer='uniform'))
model.add(MaxPooling2D())
model.add(Dropout(0.25))
model.add(Conv2D(64, (3, 3), padding='same', activation='relu'))
model.add(BatchNormalization(momentum=0.9, epsilon=1e-05, gamma_initializer='uniform'))
model.add(MaxPooling2D())
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dense(256, activation='relu'))
model.add(Dense(10, activation='sigmoid'))
model.summary()

from keras.callbacks import EarlyStopping, ReduceLROnPlateau, ModelCheckpoint
earlystop = EarlyStopping(patience=10)
learning_rate_reduction = ReduceLROnPlateau(monitor='val_acc', patience=2, verbose=1, factor=0.5, min_lr=1e-05)
callbacks = [earlystop, learning_rate_reduction, ModelCheckpoint(filepath='best_model.h5', monitor='val_loss', save_best_only=True)]

from tensorflow.keras.optimizers import Adam
model.compile(loss='categorical_crossentropy', optimizer=Adam(lr=0.001), metrics=['accuracy'])

model.fit(images_train, label_train, validation_data=(images_validation, label_validation), batch_size=64, epochs=50, callbacks=callbacks)