O'Reilly logo

Python Deep Learning Cookbook by Indra den Bakker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required