Skip to content

Instantly share code, notes, and snippets.

View Crazz-Zaac's full-sized avatar
🎯
Focusing

Rabin BK (Bishwokarma) Crazz-Zaac

🎯
Focusing
View GitHub Profile
@Crazz-Zaac
Crazz-Zaac / import_dataset.py
Last active December 7, 2020 04:10
Importing image dataset as train and test set
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")
@Crazz-Zaac
Crazz-Zaac / visualize_data.py
Created December 7, 2020 04:19
Visualizing the data in the dataset
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.")
@Crazz-Zaac
Crazz-Zaac / import.py
Last active January 1, 2021 16:16
Importing essential libraries
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
@Crazz-Zaac
Crazz-Zaac / view_data.py
Created January 1, 2021 16:18
Viewing more about data
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
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
@Crazz-Zaac
Crazz-Zaac / create_compile.py
Created January 2, 2021 08:56
Creating the model and compiling it
##creating model
happyModel = HappyModel(X_train.shape[1:])
##compiling the model
happyModel.compile('adam', 'binary_crossentropy', metrics=['accuracy'])
@Crazz-Zaac
Crazz-Zaac / evaluate.py
Created January 2, 2021 09:16
Evaluating the model's loss and accuracy
preds = happyModel.evaluate(X_test, Y_test, batch_size=32)
print()
print ("Loss = " + str(preds[0]))
print ("Test Accuracy = " + str(preds[1]))
@Crazz-Zaac
Crazz-Zaac / test_my_image.py
Created January 2, 2021 09:32
Pass your image to the model and check
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))
@Crazz-Zaac
Crazz-Zaac / model_summary.py
Created January 2, 2021 09:37
Summarizing the created model
##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'))
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