Commit 61cf0be3 authored by tihmels's avatar tihmels

Rafectorings und Requierements endlich mal wieder angepasst

parent 1d81154b
......@@ -8,21 +8,18 @@ import random
import cv2
import numpy as np
import sys
from email_service import sendMail
logfile = 'logs/process_model.log'
"""
Erstellt und gibt das Log-File aus
"""
# Erstellt und konfiguriert den Logger
logging.basicConfig(level=logging.NOTSET, format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%m-%d %H:%M',
filename=logfile)
"""
Argument Parser erlaubt Parameter für die Verarbeitung anzugeben.
"""
# Argument Parser erlaubt Programmparameter anzugeben
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')
......@@ -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('-d', '--dataset', action='store', dest='dataset', default='resources/img_data/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('-t', '--test', action='store_true', help='prevent writing new model to classifier')
parser.add_argument('-c', '--csv', action='store_true', help='activate csv processing')
parser.add_argument('-x', '--email', action='store_true', help='activate email notifications')
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', dest='csv', help='activate csv output')
parser.add_argument('-x', '--email', action='store_true', dest='email', help='activate email notifications')
arguments = parser.parse_args()
logging.debug(arguments)
dataset_path = arguments.dataset
iterations = arguments.iterations
emotions = arguments.emotions
properties = arguments.properties
csv = arguments.csv
email = arguments.email
test = arguments.test
if not arguments.emotions:
print('No emotions declared')
sys.exit()
"""
Liest Input Parameter
"""
logging.info('Fisherface training started')
if email:
if arguments.email:
sendMail('Fisherface training started')
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
"""
files = glob.glob(dataset_path + '{}/*'.format(emotion))
files = glob.glob(arguments.dataset + '{}/*'.format(emotion))
random.shuffle(files)
"""
......@@ -94,18 +84,18 @@ def make_sets():
training_labels = []
prediction_data = []
prediction_labels = []
for emotion in emotions:
for emotion in arguments.emotions:
training, prediction = _get_faces_from_emotion(emotion)
# 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
training_labels.append(emotions.index(emotion))
training_labels.append(arguments.emotions.index(emotion))
for item in prediction: # repeat above process for prediction set
img = image_preprocessing(item)
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
......@@ -135,16 +125,16 @@ Emotions Liste
fishface = cv2.face.FisherFaceRecognizer_create()
metascore = []
for i in range(1, iterations + 1):
for i in range(1, arguments.iterations + 1):
correct = run_recognizer()
logging.info("{} : {}%".format(i, int(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)))
if csv:
file = open("resources/csv/{}.csv".format('_'.join(properties).lower()), "w")
if arguments.csv:
file = open("resources/csv/{}.csv".format('_'.join(arguments.properties).lower()), "w")
for entry in metascore:
file.write("{}\n".format(int(entry)))
......@@ -152,8 +142,8 @@ if csv:
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')
if email:
if arguments.email:
sendMail('Fisherface training finished')
......@@ -40,6 +40,10 @@ parser.add_argument('-x', '--email', action='store_true', help='activate email n
arguments = parser.parse_args()
logging.debug(arguments)
if not arguments.emotions:
print('No emotions declared')
sys.exit()
source_path = arguments.img_source
dataset_path = arguments.dataset
resizeFactor = arguments.resize
......
image==1.5.16
imagesize==0.7.1
imutils==0.4.3
jupyter==1.0.0
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
numpy==1.14.0
opencv-python==3.4.0.12
Pillow==5.0.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