- We start by importing all libraries as follows:
from functools import reducefrom operator import addimport randomfrom keras.datasets import mnistfrom keras.models import Sequentialfrom keras.layers import Dense, Dropoutfrom keras.utils.np_utils import to_categoricalfrom keras.callbacks import EarlyStopping, ModelCheckpoint
- After importing the libraries, we set some of the hyperparameters:
n_classes = 10batch_size = 128n_epochs = 1000
- Next, we load and preprocess the training data:
(X_train, y_train), (X_val, y_val) = mnist.load_data()X_train = X_train.reshape(60000, 28, 28, 1)X_val = X_val.reshape(10000, 28, 28, 1)X_train = X_train.astype('float32')X_val = X_val.astype('float32')X_val /= 255X_val /= 255y_train = to_categorical(y_train, ...