Commit 61cf0be3 authored by tihmels's avatar tihmels
Browse files

Rafectorings und Requierements endlich mal wieder angepasst

parent 1d81154b
...@@ -8,21 +8,18 @@ import random ...@@ -8,21 +8,18 @@ import random
import cv2 import cv2
import numpy as np import numpy as np
import sys
from email_service import sendMail from email_service import sendMail
logfile = 'logs/process_model.log' logfile = 'logs/process_model.log'
""" # Erstellt und konfiguriert den Logger
Erstellt und gibt das Log-File aus
"""
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 erlaubt Parameter für die Verarbeitung anzugeben.
"""
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')
...@@ -33,38 +30,31 @@ parser.add_argument('-5', action='append_const', dest='emotions', const='disgust ...@@ -33,38 +30,31 @@ parser.add_argument('-5', action='append_const', dest='emotions', const='disgust
parser.add_argument('-6', action='append_const', dest='emotions', const='anger', help='anger') parser.add_argument('-6', action='append_const', dest='emotions', const='anger', help='anger')
parser.add_argument('-d', '--dataset', action='store', dest='dataset', default='resources/img_data/dataset/', parser.add_argument('-d', '--dataset', action='store', dest='dataset', default='resources/img_data/dataset/',
help='path to dataset') help='path to dataset')
parser.add_argument('-i' '--iterations', action='store', dest='iterations', type=int, default=30, help='number of iterations') parser.add_argument('-i' '--iterations', action='store', dest='iterations', type=int, default=30,
help='number of iterations')
parser.add_argument('-p', '--properties', nargs='+', dest='properties', help='pre-processing steps for logging') parser.add_argument('-p', '--properties', nargs='+', dest='properties', help='pre-processing steps for logging')
parser.add_argument('-t', '--test', action='store_true', help='prevent writing new model to classifier') parser.add_argument('-t', '--test', action='store_true', dest='test', help='prevent writing new model to classifier')
parser.add_argument('-c', '--csv', action='store_true', help='activate csv processing') parser.add_argument('-c', '--csv', action='store_true', dest='csv', help='activate csv output')
parser.add_argument('-x', '--email', action='store_true', help='activate email notifications') parser.add_argument('-x', '--email', action='store_true', dest='email', help='activate email notifications')
arguments = parser.parse_args() arguments = parser.parse_args()
logging.debug(arguments) logging.debug(arguments)
dataset_path = arguments.dataset if not arguments.emotions:
iterations = arguments.iterations print('No emotions declared')
emotions = arguments.emotions sys.exit()
properties = arguments.properties
csv = arguments.csv
email = arguments.email
test = arguments.test
"""
Liest Input Parameter
"""
logging.info('Fisherface training started') logging.info('Fisherface training started')
if email: if arguments.email:
sendMail('Fisherface training started') sendMail('Fisherface training started')
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. Holt alle Dateien zu einer Emotion aus dem Dataset, mischt sie und teilt sie in ein Trainings- und Prognoseset.
:param emotion: Die Emotion :param emotion: Die Emotion
:return: training, prediction :return: training, prediction
""" """
files = glob.glob(dataset_path + '{}/*'.format(emotion)) files = glob.glob(arguments.dataset + '{}/*'.format(emotion))
random.shuffle(files) random.shuffle(files)
""" """
...@@ -94,18 +84,18 @@ def make_sets(): ...@@ -94,18 +84,18 @@ def make_sets():
training_labels = [] training_labels = []
prediction_data = [] prediction_data = []
prediction_labels = [] prediction_labels = []
for emotion in emotions: for emotion in arguments.emotions:
training, prediction = _get_faces_from_emotion(emotion) training, prediction = _get_faces_from_emotion(emotion)
# 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 training_data.append(img) # append image array to training data list
training_labels.append(emotions.index(emotion)) training_labels.append(arguments.emotions.index(emotion))
for item in prediction: # repeat above process for prediction set for item in prediction: # repeat above process for prediction set
img = image_preprocessing(item) img = image_preprocessing(item)
prediction_data.append(img) prediction_data.append(img)
prediction_labels.append(emotions.index(emotion)) prediction_labels.append(arguments.emotions.index(emotion))
return training_data, training_labels, prediction_data, prediction_labels return training_data, training_labels, prediction_data, prediction_labels
...@@ -135,16 +125,16 @@ Emotions Liste ...@@ -135,16 +125,16 @@ Emotions Liste
fishface = cv2.face.FisherFaceRecognizer_create() fishface = cv2.face.FisherFaceRecognizer_create()
metascore = [] metascore = []
for i in range(1, iterations + 1): for i in range(1, arguments.iterations + 1):
correct = run_recognizer() correct = run_recognizer()
logging.info("{} : {}%".format(i, int(correct))) logging.info("{} : {}%".format(i, int(correct)))
metascore.append(correct) metascore.append(correct)
if i % (int(iterations / 4)) == 0 and email: if i % (int(arguments.iterations / 4)) == 0 and arguments.email:
sendMail(str(i) + ' iterations done', body='up-to-date average: {}%'.format(np.mean(metascore))) sendMail(str(i) + ' iterations done', body='up-to-date average: {}%'.format(np.mean(metascore)))
if csv: if arguments.csv:
file = open("resources/csv/{}.csv".format('_'.join(properties).lower()), "w") file = open("resources/csv/{}.csv".format('_'.join(arguments.properties).lower()), "w")
for entry in metascore: for entry in metascore:
file.write("{}\n".format(int(entry))) file.write("{}\n".format(int(entry)))
...@@ -152,8 +142,8 @@ if csv: ...@@ -152,8 +142,8 @@ if csv:
logging.info("Fisherface training finished - {}% average\n".format(np.mean(metascore))) logging.info("Fisherface training finished - {}% average\n".format(np.mean(metascore)))
if not test: if not arguments.test:
fishface.write('resources/models/detection_model.xml') fishface.write('resources/models/detection_model.xml')
if email: if arguments.email:
sendMail('Fisherface training finished') sendMail('Fisherface training finished')
...@@ -40,6 +40,10 @@ parser.add_argument('-x', '--email', action='store_true', help='activate email n ...@@ -40,6 +40,10 @@ parser.add_argument('-x', '--email', action='store_true', help='activate email n
arguments = parser.parse_args() arguments = parser.parse_args()
logging.debug(arguments) logging.debug(arguments)
if not arguments.emotions:
print('No emotions declared')
sys.exit()
source_path = arguments.img_source source_path = arguments.img_source
dataset_path = arguments.dataset dataset_path = arguments.dataset
resizeFactor = arguments.resize resizeFactor = arguments.resize
......
image==1.5.16 numpy==1.14.0
imagesize==0.7.1 opencv-python==3.4.0.12
imutils==0.4.3 Pillow==5.0.0
jupyter==1.0.0 \ No newline at end of file
jupyter-client==5.1.0
jupyter-console==5.2.0
jupyter-core==4.3.0
matplotlib==2.1.0
numpy==1.13.3
olefile==0.44
opencv-contrib-python==3.3.0.10
opencv-python==3.3.0.10
Pillow==4.3.0
pytz==2017.2
PyYAML==3.12
pyzmq==16.0.21
requests==2.18.4
scipy==1.0.0
six==1.11.0
Sphinx==1.6.5
sphinxcontrib-websupport==1.0.1
urllib3==1.22
utils==0.9.0
\ No newline at end of file
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