Skip to content

Instantly share code, notes, and snippets.

@ImadDabbura
Last active September 20, 2018 15:12
Show Gist options
  • Save ImadDabbura/70dc948898eaad1ad1f428cda71800e3 to your computer and use it in GitHub Desktop.
Save ImadDabbura/70dc948898eaad1ad1f428cda71800e3 to your computer and use it in GitHub Desktop.
# Loading packages
import sys
import h5py
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
sys.path.append("../scripts/")
from coding_neural_network_from_scratch import (initialize_parameters,
L_model_forward,
compute_cost,
relu_gradient,
sigmoid_gradient,
tanh_gradient,
update_parameters,
accuracy)
from gradient_checking import dictionary_to_vector
from load_dataset import load_dataset_catvsdog
%matplotlib inline
sns.set_context("notebook")
plt.style.use("fivethirtyeight")
plt.rcParams['figure.figsize'] = (12, 6)
# Import training data
train_dataset = h5py.File("../data/train_catvnoncat.h5")
X_train = np.array(train_dataset["train_set_x"])
Y_train = np.array(train_dataset["train_set_y"])
# Plot a sample image
plt.imshow(X_train[50])
plt.axis("off");
# Import test data
test_dataset = h5py.File("../data/test_catvnoncat.h5")
X_test = np.array(test_dataset["test_set_x"])
Y_test = np.array(test_dataset["test_set_y"])
# Transform data
X_train = X_train.reshape(209, -1).T
X_train = X_train / 255
Y_train = Y_train.reshape(-1, 209)
X_test = X_test.reshape(50, -1).T
X_test = X_test / 255
Y_test = Y_test.reshape(-1, 50)
# print the new shape of both training and test datasets
print("Training data dimensions:")
print("X's dimension: {}, Y's dimension: {}".format(X_train.shape, Y_train.shape))
print("Test data dimensions:")
print("X's dimension: {}, Y's dimension: {}".format(X_test.shape, Y_test.shape))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment