How to do it...

  1. Import all necessary libraries as follows:
import globimport numpy as npimport cv2from matplotlib import pyplot as pltfrom sklearn.model_selection import train_test_splitfrom keras.utils import np_utilsfrom keras.models import Sequentialfrom keras.layers.core import Dense, Dropout, Activation, Flatten, Lambdafrom keras.optimizers import Adamfrom keras.callbacks import EarlyStoppingfrom keras.layers import Conv2D, MaxPooling2DSEED = 2017
  1. Let's start with loading the filenames and outputting the training set sizes:
# Specify data directory and extract all file names for both classesDATA_DIR = 'Data/PetImages/'cats = glob.glob(DATA_DIR + "Cat/*.jpg")dogs = glob.glob(DATA_DIR + "Dog/*.jpg")print('#Cats: {}, #Dogs: {}'.format(len(cats), ...

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.