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

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

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