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