How to do it..

  1. 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
  1. After importing the libraries, we set some of the hyperparameters:
n_classes = 10batch_size = 128n_epochs = 1000
  1. 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, ...

Get Python Deep Learning Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.