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

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