Commit 6f1eabdc authored by Arne Gerdes's avatar Arne Gerdes

Angefangen Kommentare im prozess_model zu schreiben

parent 099aee22
""" # This class makes the training of the model possible
Diese Klasse macht das Training des Models möglich
"""
import argparse import argparse
import glob import glob
import logging import logging
...@@ -14,12 +13,12 @@ from email_service import sendMail ...@@ -14,12 +13,12 @@ from email_service import sendMail
logfile = 'logs/process_model.log' logfile = 'logs/process_model.log'
# Erstellt und konfiguriert den Logger # Creates and configures the logger
logging.basicConfig(level=logging.NOTSET, format='%(asctime)s %(levelname)-8s %(message)s', logging.basicConfig(level=logging.NOTSET, format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%m-%d %H:%M', datefmt='%m-%d %H:%M',
filename=logfile) filename=logfile)
# Argument Parser erlaubt Programmparameter anzugeben # Argument parser allows to specify program parameters
parser = argparse.ArgumentParser(description='Process Model Application') parser = argparse.ArgumentParser(description='Process Model Application')
parser.add_argument('-0', action='append_const', dest='emotions', const='neutral', help='neutral') parser.add_argument('-0', action='append_const', dest='emotions', const='neutral', help='neutral')
parser.add_argument('-1', action='append_const', dest='emotions', const='happy', help='happy') parser.add_argument('-1', action='append_const', dest='emotions', const='happy', help='happy')
...@@ -50,16 +49,14 @@ if arguments.email: ...@@ -50,16 +49,14 @@ if arguments.email:
def _get_faces_from_emotion(emotion): def _get_faces_from_emotion(emotion):
""" """
Holt alle Dateien zu einer Emotion aus dem Dataset, mischt sie und teilt sie in ein Trainings- und Prognoseset. Get all the files to an emotion from the dataset, mix them, and split them into a training and test set.
:param emotion: Die Emotion : param emotion: The emotion
:return: training, prediction : return: training, prediction
""" """
files = glob.glob(arguments.dataset + '{}/*'.format(emotion)) files = glob.glob(arguments.dataset + '{}/*'.format(emotion))
random.shuffle(files) random.shuffle(files)
""" # Mix the dataset in training and comparison images in the ratio 80 to 20
Mischt das Dataset in Trainings- und Vergleichsbilder im Verhältnis 80 zu 20
"""
training = files[:int(len(files) * 0.8)] training = files[:int(len(files) * 0.8)]
prediction = files[-int(len(files) * 0.2):] prediction = files[-int(len(files) * 0.2):]
...@@ -68,9 +65,8 @@ def _get_faces_from_emotion(emotion): ...@@ -68,9 +65,8 @@ def _get_faces_from_emotion(emotion):
def image_preprocessing(image): def image_preprocessing(image):
""" """
Preprocessing der Dateien Preprocessing of the files
:param item: Bild : param item: picture
:return:
""" """
img = cv2.imread(image) # open image img = cv2.imread(image) # open image
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # convert to grayscale gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # convert to grayscale
...@@ -89,10 +85,12 @@ def make_sets(): ...@@ -89,10 +85,12 @@ def make_sets():
# Append data to training and prediction list, and generate labels 0-7 # Append data to training and prediction list, and generate labels 0-7
for item in training: for item in training:
img = image_preprocessing(item) img = image_preprocessing(item)
training_data.append(img) # append image array to training data list # append image array to training data list
training_data.append(img)
training_labels.append(arguments.emotions.index(emotion)) training_labels.append(arguments.emotions.index(emotion))
for item in prediction: # repeat above process for prediction set # repeat above process for prediction set
for item in prediction:
img = image_preprocessing(item) img = image_preprocessing(item)
prediction_data.append(img) prediction_data.append(img)
prediction_labels.append(arguments.emotions.index(emotion)) prediction_labels.append(arguments.emotions.index(emotion))
...@@ -118,12 +116,10 @@ def run_recognizer(): ...@@ -118,12 +116,10 @@ def run_recognizer():
else: else:
incorrect += 1 incorrect += 1
cnt += 1 cnt += 1
return ((100 * correct) / (correct + incorrect)) return (100 * correct) / (correct + incorrect)
""" # Emotions list
Emotions Liste
"""
fishface = cv2.face.FisherFaceRecognizer_create() fishface = cv2.face.FisherFaceRecognizer_create()
metascore = [] metascore = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment