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
from keras.layers import Dense, Input, Dropout, GlobalAveragePooling2D, Flatten, Conv2D, BatchNormalization, Activation, MaxPooling2D | |
from keras.models import Model, Sequential | |
from keras.optimizers import Adam | |
# number of possible label values | |
nb_classes = 7 | |
# Initialising the CNN | |
model = Sequential() |
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
#imported libs | |
import numpy as np | |
import pandas as pd | |
from xgboost import XGBClassifier | |
import matplotlib.pyplot as plt | |
from scipy import stats | |
import seaborn as sns | |
from sklearn.model_selection import train_test_split | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.pipeline import Pipeline |
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 cv2 | |
import numpy as np | |
import time | |
import os | |
from face_detection import * | |
from buzzer import alertor, stopAlertor | |
global thres | |
thres = 0 |
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
from face_detection import * | |
label = input('What is your name?') | |
label = label.strip().lower() | |
print('We will be taking 5 pictures! Smile when you are ready!') | |
cap = cv2.VideoCapture(0) # video capture source camera (Here webcam of laptop) | |
count = 0 | |
print('Press on y to select the current photo') | |
while(True): | |
ret,frame = cap.read() # return a single frame in variable `frame` | |
rannumb = random.randint(1,100000000) |
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 data(): | |
""" | |
Data providing function: | |
This function is separated from create_model() so that hyperopt | |
won't reload data for each evaluation run. | |
""" | |
#Encodings | |
encode = {0:'Attire', | |
1:'Decorationandsignage', |
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 data(): | |
""" | |
Data providing function: | |
This function is separated from create_model() so that hyperopt | |
won't reload data for each evaluation run. | |
""" | |
#Encodings | |
encode = {0:'Attire', | |
1:'Decorationandsignage', | |
2:'Food', |
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 create_model(X_train,y_train,X_test,y_test): | |
# Initialising the CNN | |
model = Sequential() | |
# 1 - Convolution | |
model.add(Conv2D(64,(3,3), padding='same', input_shape=(48, 48,1))) | |
model.add(BatchNormalization()) | |
model.add(Activation('relu')) | |
model.add(Dropout({{uniform(0,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
best_run, best_model = optim.minimize(model=create_model, | |
data=data, | |
algo=tpe.suggest, | |
max_evals=5, | |
trials=Trials(), | |
notebook_name='gala_recog') | |
# Evaluate the model on the test data using `evaluate` | |
print('\n# Evaluate on test data') | |
results = best_model.evaluate(X_test, y_test, batch_size=128) |
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 array_to_color(array, cmap="Oranges"): | |
s_m = plt.cm.ScalarMappable(cmap=cmap) | |
return s_m.to_rgba(array)[:,:-1] | |
def rgb_data_transform(data): | |
data_t = [] | |
for i in range(data.shape[0]): | |
data_t.append(array_to_color(data[i]).reshape(16, 16, 16, 3)) | |
return np.asarray(data_t, dtype=np.float32) |
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
with h5py.File("./full_dataset_vectors.h5", "r") as hf: | |
# Split the data into training/test features/targets | |
X_train = hf["X_train"][:] | |
targets_train = hf["y_train"][:] | |
X_test = hf["X_test"][:] | |
targets_test = hf["y_test"][:] | |
# Determine sample shape | |
sample_shape = (16, 16, 16, 3) |
OlderNewer