Skip to content

Instantly share code, notes, and snippets.

View vardanagarwal's full-sized avatar
🌚

Vardan Agarwal vardanagarwal

🌚
View GitHub Profile
@vardanagarwal
vardanagarwal / pretrained.ipynb
Last active May 15, 2020 23:45
Untitled2.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vardanagarwal
vardanagarwal / pre-trained_ensemble.ipynb
Created May 13, 2020 16:49
pre-trained_ensemble.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vardanagarwal
vardanagarwal / colorspaces_cnn2.ipynb
Created May 9, 2020 23:36
colorspaces_cnn2.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vardanagarwal
vardanagarwal / colorspaces_cnn1.ipynb
Last active May 9, 2020 23:37
colorspaces_cnn1.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
def create_model():
IMG_SHAPE = (160, 160, 3)
base_model = tf.keras.applications.MobileNetV2(input_shape=IMG_SHAPE, include_top=False, weights="imagenet")
#base_model.summary()
base_model.trainable = False
global_average_layer = tf.keras.layers.GlobalAveragePooling2D()(base_model.output)
prediction_layer = tf.keras.layers.Dense(1, activation='sigmoid')(global_average_layer)
model = tf.keras.models.Model(inputs=base_model.input, outputs=prediction_layer)
#model.summary()
def create_model():
model = Sequential()
model.add(Conv2D(32, (3, 3), activation='relu', input_shape=(IMG_WIDTH, IMG_HEIGHT, 3)))
model.add(Conv2D(32, (3, 3), activation='relu'))
model.add(BatchNormalization())
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.5))
model.add(Conv2D(64, (3, 3), activation='relu'))
def data_gen(img_names, batch_size, colorspace):
c = 0
n = img_names #List of training images
random.shuffle(n)
while (True):
img = np.zeros((batch_size, 150, 150, 3)).astype('float')
labels = []
#initially from 0 to 16, c = 0.
_URL = 'https://storage.googleapis.com/mledu-datasets/cats_and_dogs_filtered.zip'
path_to_zip = tf.keras.utils.get_file('cats_and_dogs.zip', origin=_URL, extract=True)
PATH = os.path.join(os.path.dirname(path_to_zip), 'cats_and_dogs_filtered')
train_dir = os.path.join(PATH, 'train')
validation_dir = os.path.join(PATH, 'validation')
train_cats_dir = os.path.join(train_dir, 'cats') # directory with our training cat pictures
train_dogs_dir = os.path.join(train_dir, 'dogs') # directory with our training dog pictures
validation_cats_dir = os.path.join(validation_dir, 'cats') # directory with our validation cat pictures
validation_dogs_dir = os.path.join(validation_dir, 'dogs') # directory with our validation dog pictures
import cv2
import os
from PIL import Image
import numpy as np
import tensorflow as tf
# assume all variables are defined. That is not the bug.
def create_img(path):
#Function to load,normalize and return image
im = cv2.imread(path)
import cv2
import dlib
import numpy as np
def shape_to_np(shape, dtype="int"):
# initialize the list of (x, y)-coordinates
coords = np.zeros((68, 2), dtype=dtype)
# loop over the 68 facial landmarks and convert them
# to a 2-tuple of (x, y)-coordinates
for i in range(0, 68):