-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,42 @@ | ||
from os.path import exists | ||
|
||
import numpy as np | ||
import tensorflow as tf | ||
import os | ||
import tflearn | ||
from tflearn.layers.conv import conv_2d, max_pool_2d | ||
from tflearn.layers.core import input_data, dropout, fully_connected | ||
from tflearn.layers.estimator import regression | ||
|
||
class cnnModel: | ||
def __init__(self): | ||
self.model = None | ||
cnn = input_data(shape=[150, 150, 3]) | ||
|
||
#32 filters and stride is 5, the filter will move 5 pixels at a time | ||
cnn = conv_2d(cnn, 32, filter_size=5, activation='relu') | ||
cnn = max_pool_2d(cnn, 5) | ||
cnn = conv_2d(cnn, 64, 5, activation='relu') | ||
cnn = max_pool_2d(cnn, 5) | ||
cnn = conv_2d(cnn, 128, 5, activation='relu') | ||
cnn = max_pool_2d(cnn, 5) | ||
cnn = conv_2d(cnn, 256, 5, activation='relu') | ||
|
||
#input layer | ||
cnn = fully_connected(cnn, 1024, activation='relu') | ||
self.cnn = dropout(cnn, 0.5) | ||
# input layer | ||
cnn = fully_connected(cnn, 256, activation='relu') | ||
self.cnn = dropout(cnn, 0.5) | ||
|
||
def set_output_layer(self, labels): | ||
# output layer | ||
self.labels = labels | ||
self.cnn = fully_connected(self.cnn, len(labels.keys()), activation='softmax') | ||
self.cnn = regression(self.cnn, optimizer='adam', learning_rate=0.001, loss='categorical_crossentropy') | ||
|
||
# final model initializer | ||
self.model = tflearn.DNN(self.cnn, tensorboard_verbose=1) | ||
|
||
def train(self, x_train, y_train, x_test, y_test): | ||
self.model.fit(x_train, y_train, n_epoch=5, validation_set=(x_test, y_test), show_metric=True) | ||
self.model.save('savedModels/cnn.tfl') | ||
|
||
def predict(self, current_face): | ||
import numpy as np | ||
import tflearn | ||
from tflearn.layers.conv import conv_2d, max_pool_2d | ||
from tflearn.layers.core import input_data, dropout, fully_connected | ||
from tflearn.layers.estimator import regression | ||
|
||
class cnnModel: | ||
def __init__(self): | ||
self.model = None | ||
cnn = input_data(shape=[150, 150, 3]) | ||
|
||
#32 filters and stride is 5, the filter will move 5 pixels at a time | ||
cnn = conv_2d(cnn, 32, filter_size=5, activation='relu') | ||
cnn = max_pool_2d(cnn, 5) | ||
cnn = conv_2d(cnn, 64, 5, activation='relu') | ||
cnn = max_pool_2d(cnn, 5) | ||
cnn = conv_2d(cnn, 128, 5, activation='relu') | ||
cnn = max_pool_2d(cnn, 5) | ||
cnn = conv_2d(cnn, 256, 5, activation='relu') | ||
|
||
#input layer | ||
cnn = fully_connected(cnn, 1024, activation='relu') | ||
self.cnn = dropout(cnn, 0.5) | ||
# input layer | ||
cnn = fully_connected(cnn, 256, activation='relu') | ||
self.cnn = dropout(cnn, 0.5) | ||
|
||
def set_output_layer(self, labels): | ||
# output layer | ||
self.labels = labels | ||
self.cnn = fully_connected(self.cnn, len(labels.keys()), activation='softmax') | ||
self.cnn = regression(self.cnn, optimizer='adam', learning_rate=0.001, loss='categorical_crossentropy') | ||
|
||
# final model initializer | ||
self.model = tflearn.DNN(self.cnn, tensorboard_verbose=1) | ||
|
||
def train(self, x_train, y_train, x_test, y_test): | ||
self.model.fit(x_train, y_train, n_epoch=5, validation_set=(x_test, y_test), show_metric=True) | ||
self.model.save('savedModels/cnn.tfl') | ||
|
||
def predict(self, current_face): | ||
return self.model.predict(np.array(current_face).reshape(-1, 150, 150, 3)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,53 @@ | ||
from cnnModel import model | ||
from getWebCamImages import take_pictures | ||
from lbphModel import lbph | ||
from trainModels import train | ||
from runDetector import detectFace | ||
|
||
lbph_model = lbph.lbphModel() | ||
cnn_model = model.cnnModel() | ||
|
||
|
||
def run(): | ||
cur_command = input("Enter Command (type 'help' to see list of commands): ") | ||
|
||
while cur_command != 'exit': | ||
if cur_command == 'take pictures': | ||
take_pictures.takeImages() | ||
print("Pictures added to database!") | ||
|
||
elif cur_command == 'train lbph': | ||
train.train_lbph(lbph_model) | ||
print("LBPH model trained successfully!") | ||
|
||
elif cur_command == 'train cnn': | ||
train.train_cnn(cnn_model) | ||
print("CNN model trained successfully!") | ||
|
||
elif cur_command == 'run predictor lbph': | ||
detectFace.runDetector(lbph_model.name_dict, lbph_model, 'lbph') | ||
print() | ||
print("Predictor closed successfully") | ||
|
||
elif cur_command == 'run predictor cnn': | ||
detectFace.runDetector(cnn_model.labels, cnn_model, 'cnn') | ||
print() | ||
print("Predictor closed successfully") | ||
|
||
elif cur_command == 'help': | ||
print() | ||
print("Commands:") | ||
print("take pictures: take pictures used for training models") | ||
print('train lbph: train the local binary pattern histogram model') | ||
print('train cnn: train convolutional neural network model (Will take a lot longer, if a model has already been trained previously, you ' | ||
'will be given the option to load that model)') | ||
print('run predictor: run the real-time prediction algorithm') | ||
print() | ||
|
||
else: | ||
print("No such command!") | ||
|
||
cur_command = input("Enter Command (type 'help' to see list of commands): ") | ||
|
||
|
||
run() | ||
from cnnModel import model | ||
from getWebCamImages import take_pictures | ||
from lbphModel import lbph | ||
from trainModels import train | ||
from runDetector import detectFace | ||
|
||
lbph_model = lbph.lbphModel() | ||
cnn_model = model.cnnModel() | ||
|
||
|
||
def run(): | ||
cur_command = input("Enter Command (type 'help' to see list of commands): ") | ||
|
||
while cur_command != 'exit': | ||
if cur_command == 'take pictures': | ||
take_pictures.takeImages() | ||
print("Pictures added to database!") | ||
|
||
elif cur_command == 'train lbph': | ||
train.train_lbph(lbph_model) | ||
print("LBPH model trained successfully!") | ||
|
||
elif cur_command == 'train cnn': | ||
train.train_cnn(cnn_model) | ||
print("CNN model trained successfully!") | ||
|
||
elif cur_command == 'run predictor lbph': | ||
detectFace.runDetector(lbph_model.name_dict, lbph_model, 'lbph') | ||
print() | ||
print("Predictor closed successfully") | ||
|
||
elif cur_command == 'run predictor cnn': | ||
detectFace.runDetector(cnn_model.labels, cnn_model, 'cnn') | ||
print() | ||
print("Predictor closed successfully") | ||
|
||
elif cur_command == 'help': | ||
print() | ||
print("Commands:") | ||
print("take pictures: take pictures used for training models") | ||
print('train lbph: train the local binary pattern histogram model') | ||
print('train cnn: train convolutional neural network model (Will take a lot longer, if a model has already been trained previously, you ' | ||
'will be given the option to load that model)') | ||
print('run predictor: run the real-time prediction algorithm') | ||
print() | ||
|
||
else: | ||
print("No such command!") | ||
|
||
cur_command = input("Enter Command (type 'help' to see list of commands): ") | ||
|
||
|
||
run() |