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

Angefangen Kommentare im prozess_model zu schreiben

parent 099aee22
"""
Diese Klasse macht das Training des Models möglich
"""
# This class makes the training of the model possible
import argparse
import glob
import logging
......@@ -14,12 +13,12 @@ from email_service import sendMail
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',
datefmt='%m-%d %H:%M',
filename=logfile)
# Argument Parser erlaubt Programmparameter anzugeben
# Argument parser allows to specify program parameters
parser = argparse.ArgumentParser(description='Process Model Application')
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')
......@@ -50,16 +49,14 @@ if arguments.email:
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.
:param emotion: Die Emotion
:return: training, prediction
Get all the files to an emotion from the dataset, mix them, and split them into a training and test set.
: param emotion: The emotion
: return: training, prediction
"""
files = glob.glob(arguments.dataset + '{}/*'.format(emotion))
random.shuffle(files)
"""
Mischt das Dataset in Trainings- und Vergleichsbilder im Verhältnis 80 zu 20
"""
# Mix the dataset in training and comparison images in the ratio 80 to 20
training = files[:int(len(files) * 0.8)]
prediction = files[-int(len(files) * 0.2):]
......@@ -68,9 +65,8 @@ def _get_faces_from_emotion(emotion):
def image_preprocessing(image):
"""
Preprocessing der Dateien
:param item: Bild
:return:
Preprocessing of the files
: param item: picture
"""
img = cv2.imread(image) # open image
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # convert to grayscale
......@@ -89,10 +85,12 @@ def make_sets():
# Append data to training and prediction list, and generate labels 0-7
for item in training:
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))
for item in prediction: # repeat above process for prediction set
# repeat above process for prediction set
for item in prediction:
img = image_preprocessing(item)
prediction_data.append(img)
prediction_labels.append(arguments.emotions.index(emotion))
......@@ -118,12 +116,10 @@ def run_recognizer():
else:
incorrect += 1
cnt += 1
return ((100 * correct) / (correct + incorrect))
return (100 * correct) / (correct + incorrect)
"""
Emotions Liste
"""
# Emotions list
fishface = cv2.face.FisherFaceRecognizer_create()
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