``````

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)

``````
``````

Cost after 0 iterations is: 0.7008199923306838
Cost after 100 iterations is: 0.5520165727996922
Cost after 200 iterations is: 0.46868869792452744
Cost after 300 iterations is: 0.43236996838603364
Cost after 400 iterations is: 0.3529648424015535
Cost after 500 iterations is: 0.26475005400961316
Cost after 600 iterations is: 0.25032107317186936
Cost after 700 iterations is: 0.1729598788909891
Cost after 800 iterations is: 0.15525051230399686
Cost after 900 iterations is: 0.08426763833891732
Cost after 1000 iterations is: 0.0692322559590341
Cost after 1100 iterations is: 0.055629563238585776
Cost after 1200 iterations is: 0.04381172857527264
Cost after 1300 iterations is: 0.03663021911718393
Cost after 1400 iterations is: 0.031423248198722484
Cost after 1500 iterations is: 0.026949398562569903
Cost after 1600 iterations is: 0.023441983286671117
Cost after 1700 iterations is: 0.020593211494177362
Cost after 1800 iterations is: 0.017994131445432337
Cost after 1900 iterations is: 0.015988284819583937
Cost after 2000 iterations is: 0.01428478315313005
Cost after 2100 iterations is: 0.012861374083221284
Cost after 2200 iterations is: 0.011634673608766409
Cost after 2300 iterations is: 0.010541481718548823
Cost after 2400 iterations is: 0.009621723856606701
Cost after 2500 iterations is: 0.008833935910776422
Cost after 2600 iterations is: 0.008149520649456742
Cost after 2700 iterations is: 0.007497775880728765
Cost after 2800 iterations is: 0.0069677731177311105
Cost after 2900 iterations is: 0.006506966253988189

``````
``````

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)

``````
``````

Accuracy on train set 1.0
Accuracy on test set 0.66

``````
``````

In [5]:

num_px = 64
my_label = np.array([[1]])
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)))

``````
``````

y = 1.0

``````

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);

``````
``````

Cost after 0 iterations is: 0.7927309338705072
Cost after 100 iterations is: 0.6469092798970708
Cost after 200 iterations is: 0.6340702415514673
Cost after 300 iterations is: 0.6138721158279924
Cost after 400 iterations is: 0.5853863748284921
Cost after 500 iterations is: 0.5507790813311488
Cost after 600 iterations is: 0.5125658941877002
Cost after 700 iterations is: 0.47453563694404416
Cost after 800 iterations is: 0.4414443139818433
Cost after 900 iterations is: 0.41064809057445145
Cost after 1000 iterations is: 0.3816379929744432
Cost after 1100 iterations is: 0.3461594527087302
Cost after 1200 iterations is: 0.3195993082885402
Cost after 1300 iterations is: 0.288366871795227
Cost after 1400 iterations is: 0.269946940633998
Cost after 1500 iterations is: 0.24861426064357656
Cost after 1600 iterations is: 0.24915535343917328
Cost after 1700 iterations is: 0.21498352637696097
Cost after 1800 iterations is: 0.22082576801480508
Cost after 1900 iterations is: 0.19454517662973161
Cost after 2000 iterations is: 0.18877465825123615
Cost after 2100 iterations is: 0.18844557570001041
Cost after 2200 iterations is: 0.1786612072461685
Cost after 2300 iterations is: 0.15849693137870838
Cost after 2400 iterations is: 0.15233278801021705
Cost after 2500 iterations is: 0.1472606968581712
Cost after 2600 iterations is: 0.14225253886592498
Cost after 2700 iterations is: 0.13779729989011075
Cost after 2800 iterations is: 0.13387285775149757
Cost after 2900 iterations is: 0.13021286864892367

``````
``````

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)

``````
``````

Accuracy on train set 0.980861244019
Accuracy on test set 0.56

``````
``````

In [8]:

num_px = 64
my_label = np.array([[1]])
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)))

``````
``````

y = 0.0

``````

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)

``````
``````

cost after 0 iterations is: 0.756234757921652
cost after 100 iterations is: 0.5788521556105536
cost after 200 iterations is: 0.5536678924889248
cost after 300 iterations is: 0.5346071291921773
cost after 400 iterations is: 0.4775997711435038
cost after 500 iterations is: 0.5038667877152906
cost after 600 iterations is: 0.41089644405537534
cost after 700 iterations is: 0.4432130990306341
cost after 800 iterations is: 0.4040100909318405
cost after 900 iterations is: 0.3979631085338401
cost after 1000 iterations is: 0.3491096205310618
cost after 1100 iterations is: 0.32996926079535965
cost after 1200 iterations is: 0.3595727113731817
cost after 1300 iterations is: 0.3730084045290037
cost after 1400 iterations is: 0.3128348932611668
cost after 1500 iterations is: 0.29795013205241294
cost after 1600 iterations is: 0.2595369025559032
cost after 1700 iterations is: 0.3326643178158872
cost after 1800 iterations is: 0.3167829146449158
cost after 1900 iterations is: 0.3964509986697357
cost after 2000 iterations is: 0.2811322306770265
cost after 2100 iterations is: 0.2743557653528868
cost after 2200 iterations is: 0.3045344539355948
cost after 2300 iterations is: 0.2972908618567567
cost after 2400 iterations is: 0.318283426532256
cost after 2500 iterations is: 0.3224526676385774
cost after 2600 iterations is: 0.25043127413762317
cost after 2700 iterations is: 0.28303499030204693
cost after 2800 iterations is: 0.26613445964729154
cost after 2900 iterations is: 0.29365097297532594

``````
``````

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)

``````
``````

Accuracy on train set 0.933014354067
Accuracy on test set 0.66

``````
``````

In [11]:

num_px = 64
my_label = np.array([[1]])
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)))

``````
``````

y = 1.0

``````
``````

In [ ]:

``````