This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
import h5py | |
import scipy | |
from PIL import Image | |
from scipy import ndimage | |
%matplotlib inline #to set the backend of matplotlib to the 'inline' backend | |
def load_dataset(): | |
train_dataset = h5py.File('catdataset/train_catvnoncat.h5', "r") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
index = 30 # change index value to visualize other data | |
plt.imshow(train_set_x_orig[index]) | |
print ("y = " + str(train_set_y[:, index]) + ", it's a '" + classes[np.squeeze(train_set_y[:, index])].decode("utf-8") + "' picture.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from keras import layers | |
from keras.layers import Input, Dense, Activation, ZeroPadding2D, BatchNormalization, Flatten, Conv2D | |
from keras.layers import AveragePooling2D, MaxPooling2D, Dropout, GlobalMaxPooling2D, GlobalAveragePooling2D | |
from keras.models import Model | |
from keras.preprocessing import image | |
from keras.utils import layer_utils | |
from keras.utils.data_utils import get_file | |
from keras.applications.imagenet_utils import preprocess_input | |
import pydot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X_train_orig, Y_train_orig, X_test_orig, Y_test_orig, classes = load_dataset() | |
# Normalize image vectors | |
X_train = X_train_orig/255. | |
X_test = X_test_orig/255. | |
# Reshape | |
Y_train = Y_train_orig.T | |
Y_test = Y_test_orig.T |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def HappyModel(input_shape): | |
""" | |
Implementation of the HappyModel. | |
Arguments: | |
input_shape -- shape of the images of the dataset | |
(height, width, channels) as a tuple. | |
Note that this does not include the 'batch' as a dimension. | |
If you have a batch like 'X_train', | |
then you can provide the input_shape using |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##creating model | |
happyModel = HappyModel(X_train.shape[1:]) | |
##compiling the model | |
happyModel.compile('adam', 'binary_crossentropy', metrics=['accuracy']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
preds = happyModel.evaluate(X_test, Y_test, batch_size=32) | |
print() | |
print ("Loss = " + str(preds[0])) | |
print ("Test Accuracy = " + str(preds[1])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
img_path = 'images/pic5.jpeg' ##location to you image | |
img = image.load_img(img_path, target_size=(64, 64)) | |
imshow(img) | |
x = image.img_to_array(img) | |
x = np.expand_dims(x, axis=0) | |
x = preprocess_input(x) | |
print(happyModel.predict(x)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##prints the details of your layers in a table. | |
happyModel.summary() | |
##plots a graph of all the steps taken to build the model. | |
##You can also save it in .png or .svg format | |
plot_model(happyModel, to_file='HappyModel.png') | |
SVG(model_to_dot(happyModel).create(prog='dot', format='svg')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import os | |
import matplotlib.pyplot as plt | |
from matplotlib.pyplot import imshow | |
import scipy.io | |
import scipy.misc | |
import numpy as np | |
import pandas as pd | |
import PIL | |
import tensorflow as tf |
OlderNewer