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. We start with importing all necessary libraries and setting the seed, as follows:
import pandas as pdimport numpy as npimport matplotlib.pyplot as pltfrom sklearn.model_selection import train_test_splitimport tensorflow as tfSEED = 2017
  1. Next, we load the dataset and output some numbers:
DIR = 'Data/faces/'training_file = pd.read_csv(DIR + 'training.csv')cols = training_file.columns[:-1]training_file['Image'] = training_file['Image'].apply(lambda Image: np.fromstring(Image, sep=' '))training_file = training_file.dropna()
  1. Before proceeding, we need to reshape and normalize the data:
img_cols = 96img_rows = 96img_channels = 1n_labels = 30 # 15 times x, y pairsX = np.vstack(training_file['Image'])X = X.reshape(-1, img_cols, ...

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