Commit 5af0c9a4 authored by tihmels's avatar tihmels

AffectNet Pipeline

parent 7216fb4f
...@@ -7,7 +7,7 @@ from shutil import copyfile ...@@ -7,7 +7,7 @@ from shutil import copyfile
import pandas as pd import pandas as pd
logfile = '../logs/affectnet.log' logfile = 'affectnet.log'
# Erstellt und konfiguriert die Logdatei # Erstellt und konfiguriert die Logdatei
logging.basicConfig(level=logging.NOTSET, format='%(asctime)s %(levelname)-8s %(message)s', logging.basicConfig(level=logging.NOTSET, format='%(asctime)s %(levelname)-8s %(message)s',
...@@ -45,14 +45,6 @@ csv = os.path.join(curdir, arguments.csv) ...@@ -45,14 +45,6 @@ csv = os.path.join(curdir, arguments.csv)
source = os.path.join(curdir, arguments.source) source = os.path.join(curdir, arguments.source)
destination = os.path.join(curdir, arguments.destination) destination = os.path.join(curdir, arguments.destination)
if os.path.exists(destination):
delete = input(destination + ' existiert. Durch diesen Prozess werden die Daten gelöscht. Fortfahren (y/n): ')
if delete == 'y':
shutil.rmtree(destination)
else:
logging.info('process aborted')
sys.exit()
def generate_records(csvfile): def generate_records(csvfile):
data = pd.read_csv(csvfile, delimiter=',', dtype='a') data = pd.read_csv(csvfile, delimiter=',', dtype='a')
...@@ -65,10 +57,20 @@ def generate_records(csvfile): ...@@ -65,10 +57,20 @@ def generate_records(csvfile):
dest = os.path.join(destination, e) dest = os.path.join(destination, e)
if not os.path.exists(dest): if not os.path.exists(dest):
os.makedirs(dest) os.makedirs(dest)
else:
counter[e] = len(os.listdir(dest))
data = zip(labels, imagepaths, valence, arousal) data = zip(labels, imagepaths, valence, arousal)
for d in data: for d in data:
if all(count >= arguments.limit for count in counter.values()):
break
emotion = emodict.get(d[0])
if emotion not in arguments.emotions or d[2] < arguments.valence or d[3] < arguments.arousal or counter[emotion] >= arguments.limit:
continue
img = d[1] img = d[1]
pathfrom = os.path.join(source, img) pathfrom = os.path.join(source, img)
...@@ -76,20 +78,14 @@ def generate_records(csvfile): ...@@ -76,20 +78,14 @@ def generate_records(csvfile):
logging.info(img + ' not found') logging.info(img + ' not found')
continue continue
if all(count == arguments.limit for count in counter.values()):
break
emotion = emodict.get(d[0])
if emotion not in arguments.emotions or d[2] < float(arguments.valence) or d[3] < float(arguments.arousal) or counter[emotion] == arguments.limit:
continue
parent = os.path.join(destination, emotion) parent = os.path.join(destination, emotion)
pathto = os.path.join(parent, img.split('/')[1]) pathto = os.path.join(parent, img.split('/')[1])
copyfile(pathfrom, pathto)
logging.info('wrote file ' + pathto) if not os.path.isfile(pathto):
counter[emotion] += 1 copyfile(pathfrom, pathto)
logging.info('wrote file ' + pathto)
counter[emotion] += 1
if __name__ == '__main__': if __name__ == '__main__':
......
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