In [1]:
import numpy as np
import scipy
import matplotlib.pyplot as plt
from utils import *
from scipy import ndimage
In [2]:
train_set_x_orig, train_set_y_orig, test_set_x_orig, test_set_y_orig = load_data()
X = (train_set_x_orig.reshape(train_set_x_orig.shape[0], -1) / 255.).T
Y = (train_set_y_orig.reshape(train_set_y_orig.shape[0], 1)).T
X_test = (test_set_x_orig.reshape(test_set_x_orig.shape[0], -1) / 255.).T
Y_test = (test_set_y_orig.reshape(test_set_y_orig.shape[0], 1)).T
L model without regularization or dropout
In [3]:
parameters = L_model(X, Y, [X.shape[0], 5, 3, 1], learning_rate=0.0075, num_iterations=3000, print_cost=True);
# parameters = L_model_with_regularization(X, Y, [X.shape[0], 20, 20, 20, 20, 20, 1], learning_rate=0.0075, num_iterations=3000, lamb=0.1, print_cost=True);
# parameters = L_model_with_dropout(X, Y, [X.shape[0], 5, 3, 1], learning_rate=0.0075, num_iterations=3000, keep_prob=0.9, print_cost=True)
In [4]:
acc_train = predict(X, Y, parameters)
acc_test = predict(X_test, Y_test, parameters)
print('Accuracy on train set', acc_train)
print('Accuracy on test set', acc_test)
In [5]:
num_px = 64
my_label = np.array([[1]])
image = np.array(ndimage.imread('my_image.jpg', flatten=False))
plt.imshow(image)
plt.show()
my_image = scipy.misc.imresize(image, size=(num_px,num_px)).reshape(num_px * num_px * 3, 1)
my_predicted_image = predict(my_image, my_label, parameters)
print('y = ' + str(np.squeeze(my_predicted_image)))
L model with regularization
In [6]:
parameters = L_model_with_regularization(X, Y, [X.shape[0], 5, 3, 1], learning_rate=0.0075, num_iterations=3000, lamb=0.1, print_cost=True);
In [7]:
acc_train = predict(X, Y, parameters)
acc_test = predict(X_test, Y_test, parameters)
print('Accuracy on train set', acc_train)
print('Accuracy on test set', acc_test)
In [8]:
num_px = 64
my_label = np.array([[1]])
image = np.array(ndimage.imread('my_image.jpg', flatten=False))
plt.imshow(image)
plt.show()
my_image = scipy.misc.imresize(image, size=(num_px,num_px)).reshape(num_px * num_px * 3, 1)
my_predicted_image = predict(my_image, my_label, parameters)
print('y = ' + str(np.squeeze(my_predicted_image)))
L model with dropout
In [9]:
parameters = L_model_with_dropout(X, Y, [X.shape[0], 5, 3, 1], learning_rate=0.0075, num_iterations=3000, keep_prob=0.86, print_cost=True)
In [10]:
acc_train = predict(X, Y, parameters)
acc_test = predict(X_test, Y_test, parameters)
print('Accuracy on train set', acc_train)
print('Accuracy on test set', acc_test)
In [11]:
num_px = 64
my_label = np.array([[1]])
image = np.array(ndimage.imread('my_image.jpg', flatten=False))
plt.imshow(image)
plt.show()
my_image = scipy.misc.imresize(image, size=(num_px,num_px)).reshape(num_px * num_px * 3, 1)
my_predicted_image = predict(my_image, my_label, parameters)
print('y = ' + str(np.squeeze(my_predicted_image)))
In [ ]: