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. Create a new Python file and import the necessary libraries:
import numpy as npimport globimport cv2import matplotlib.pyplot as pltfrom sklearn.preprocessing import LabelBinarizerfrom sklearn.model_selection import train_test_splitfrom sklearn.metrics import accuracy_scoreimport kerasfrom keras.models import Sequential, load_modelfrom keras.layers import Dense, Dropout, Activation, Flatten, Conv2D, MaxPooling2D, Lambda, Cropping2Dfrom keras.utils import np_utilsfrom keras import optimizersSEED = 2017
  1. Next, we load the dataset and extract the labels:
# Specify data directory and extract all file namesDATA_DIR = '../Data/'images = glob.glob(DATA_DIR + "flower_photos/*/*.jpg")# Extract labels from file nameslabels = [x.split('/')[3] ...

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