1import numpy as np
2import matplotlib.pyplot as plt
3import h5py
4import scipy
5from PIL import Image
6from scipy import ndimage
7
8%matplotlib inline
9
1train_set_x = train_set_x_flatten/255.
2test_set_x = test_set_x_flatten/255.
3
1# Loading the data (cat/non-cat)
2train_set_x_orig, train_set_y, test_set_x_orig, test_set_y, classes = load_dataset()
3
1- m_train (number of training examples)
2- m_test (number of test examples)
3- num_px (= height = width of a training image)
4
1def load_dataset():
2 train_dataset = h5py.File('datasets/train_catvnoncat.h5', "r")
3 train_set_x_orig = np.array(train_dataset["train_set_x"][:]) # your train set features
4 train_set_y_orig = np.array(train_dataset["train_set_y"][:]) # your train set labels
5
6 test_dataset = h5py.File('datasets/test_catvnoncat.h5', "r")
7 test_set_x_orig = np.array(test_dataset["test_set_x"][:]) # your test set features
8 test_set_y_orig = np.array(test_dataset["test_set_y"][:]) # your test set labels
9
10 classes = np.array(test_dataset["list_classes"][:]) # the list of classes
11
12 train_set_y_orig = train_set_y_orig.reshape((1, train_set_y_orig.shape[0]))
13 test_set_y_orig = test_set_y_orig.reshape((1, test_set_y_orig.shape[0]))
14
15 return train_set_x_orig, train_set_y_orig, test_set_x_orig, test_set_y_orig, classes
16
1- Initialize the parameters of the model
2- Learn the parameters for the model by minimizing the cost
3- Use the learned parameters to make predictions (on the test set)
4- Analyse the results and conclude
1train_set_x_flatten shape: (12288, 209)
2train_set_y shape: (1, 209)
3test_set_x_flatten shape: (12288, 50)
4test_set_y shape: (1, 50)
5sanity check after reshaping: [17 31 56 22 33]
6