How to do it...

  1. First, we import all the libraries in Python, as follows:
from keras.datasets import cifar10from keras.preprocessing.image import ImageDataGeneratorfrom keras.models import Sequentialfrom keras.layers import Dense, Dropout, Activation, Flattenfrom keras.layers import Conv2D, MaxPooling2Dfrom keras.optimizers import Adamfrom keras.callbacks import EarlyStopping, TensorBoard, ModelCheckpointfrom keras.utils import to_categorical
  1. Let's load the cifar10 dataset for this example and pre-process the training and validation data:
(X_train, y_train), (X_val, y_val) = cifar10.load_data()X_train = X_train.astype('float32')X_train /=255.X_val = X_val.astype('float32')X_val /=255.n_classes = 10y_train = to_categorical(y_train, n_classes) ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.