Skip to content

Instantly share code, notes, and snippets.

View miki998's full-sized avatar
🐢
don't be fooled by this rabbit, i'm actually a pretty slow turtle

Michael 米高 miki998

🐢
don't be fooled by this rabbit, i'm actually a pretty slow turtle
View GitHub Profile
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()
#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
import cv2
import numpy as np
import time
import os
from face_detection import *
from buzzer import alertor, stopAlertor
global thres
thres = 0
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)
@miki998
miki998 / hyperas.py
Last active March 21, 2020 17:02
Hyperas settings example for a CNN.
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',
@miki998
miki998 / data.py
Created March 21, 2020 16:59
data extract for hyperas
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',
@miki998
miki998 / cnn_model.py
Created March 21, 2020 17:02
cnn_model for hyperas.py
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)}}))
@miki998
miki998 / fitting.py
Created March 21, 2020 17:05
fitting for hyperas.py
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)
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)
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)