Skip to content

Commit

Permalink
[Angelica] Extract feature and data modules/methods into separate dir…
Browse files Browse the repository at this point in the history
…ectories
  • Loading branch information
angelicaperez37 authored and aperez-rai committed Dec 20, 2017
1 parent e2403d0 commit 197bba9
Show file tree
Hide file tree
Showing 211 changed files with 135 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ pip-selfcheck.json
share/
dist/
Riot_python.egg-info
*.pyc
*.pyc
build/
Empty file added __init__.py
Empty file.
Empty file added data/__init__.py
Empty file.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
53 changes: 53 additions & 0 deletions data/dataProcessor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import os
from feature import Feature
import numpy as np


class DataProcessor:
"""
Class containing all necessary data preprocessing methods.
"""

def get_image_feature_array(self, root_directory, vector=True):
"""
Extracts features vectors of all images found in root_directory.
:param root_directory: location of image data
:param vector: if true returns features as vectors, otherwise as 2D arrays
:return: numpy array of extracted feature vectors
"""
feature_index = 0 if vector else 1
feature = Feature()
features = list()
for sub_directory in os.listdir(root_directory):
if not sub_directory.startswith('.'):
sub_directory_path = root_directory + '/' + sub_directory
for image_file in os.listdir(sub_directory_path):
if not image_file.startswith('.'):
image_file_path = sub_directory_path + '/' + image_file
features.append([[feature.extract_hog_feature_vector(image_file_path)[feature_index]]])

return np.array(features)

def get_time_series_image_feature_array(self, root_directory, vector=True):
"""
Extracts features vectors of images found in root_directory and groups them
by time_series batch. Subdirectories of root_directory must contain a single
time series batch.
:param root_directory: location of image data
:param vector: if true returns features as vectors, otherwise as 2D arrays
:return: numpy array of arrays which contain time series batch features
"""
feature_index = 0 if vector else 1
feature = Feature()
features = list()
for sub_directory in os.listdir(root_directory):
if not sub_directory.startswith('.'):
sub_directory_path = root_directory + '/' + sub_directory
for image_file in os.listdir(sub_directory_path):
feature_batch = list()
if not image_file.startswith('.'):
image_file_path = sub_directory_path + '/' + image_file
feature_batch.append(feature.extract_hog_feature_vector(image_file_path)[feature_index])
features.append(feature_batch)

return np.array(features)
10 changes: 10 additions & 0 deletions data/fer2013/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
If you use this dataset in your research work, please cite

"Challenges in Representation Learning: A report on three machine learning
contests." I Goodfellow, D Erhan, PL Carrier, A Courville, M Mirza, B
Hamner, W Cukierski, Y Tang, DH Lee, Y Zhou, C Ramaiah, F Feng, R Li,
X Wang, D Athanasakis, J Shawe-Taylor, M Milakov, J Park, R Ionescu,
M Popescu, C Grozea, J Bergstra, J Xie, L Romaszko, B Xu, Z Chuang, and
Y. Bengio. arXiv 2013.

See fer2013.bib for a bibtex entry.
19 changes: 19 additions & 0 deletions data/fer2013/fer2013.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

@MISC{Goodfeli-et-al-2013,
author = {Goodfellow, Ian and Erhan, Dumitru and Carrier, Pierre-Luc and Courville, Aaron and Mirza, Mehdi and Hamner, Ben and Cukierski, Will and Tang, Yichuan and Thaler, David and Lee, Dong-Hyun and Zhou, Yingbo and Ramaiah, Chetan and Feng, Fangxiang and Li, Ruifan and Wang, Xiaojie and Athanasakis, Dimitris and Shawe-Taylor, John and Milakov, Maxim and Park, John and Ionescu, Radu and Popescu, Marius and Grozea, Cristian and Bergstra, James and Xie, Jingjing and Romaszko, Lukasz and Xu, Bing and Chuang, Zhang and Bengio, Yoshua},
keywords = {competition, dataset, representation learning},
title = {Challenges in Representation Learning: A report on three machine learning contests},
year = {2013},
institution = {Unicer},
url = {http://arxiv.org/abs/1307.0414},
abstract = {The ICML 2013 Workshop on Challenges in Representation
Learning focused on three challenges: the black box learning challenge,
the facial expression recognition challenge, and the multimodal learn-
ing challenge. We describe the datasets created for these challenges and
summarize the results of the competitions. We provide suggestions for or-
ganizers of future challenges and some comments on what kind of knowl-
edge can be gained from machine learning competitions.
http://deeplearning.net/icml2013-workshop-competition}
}

10 changes: 10 additions & 0 deletions data/temp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import sys
sys.path.append('../feature')
from dataProcessor import DataProcessor


d = DataProcessor()
root_directory = "../data/cohn_kanade_images"
feature_images = d.get_time_series_image_feature_array(root_directory)

print(feature_images.shape)
Empty file added experiments/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions experiments/conv_lstm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys
sys.path.append('../feature')
from keras.layers import ConvLSTM2D, Dense, Flatten
from keras.models import Sequential
from keras.callbacks import ReduceLROnPlateau, EarlyStopping
Expand Down
37 changes: 35 additions & 2 deletions experiments/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def get_image_feature_vector_array():
feature = Feature()
root_directory = "../images"
root_directory = "../data/cohn_kanade_images"
features = list()
for subfile in os.listdir(root_directory):
if "DS_Store" in subfile: continue
Expand All @@ -21,7 +21,7 @@ def get_image_feature_vector_array():

def get_image_feature_image_array():
feature = Feature()
root_directory = "../images"
root_directory = "../data/cohn_kanade_images"
features = list()
for subfile in os.listdir(root_directory):
if "DS_Store" in subfile: continue
Expand All @@ -32,6 +32,39 @@ def get_image_feature_image_array():

return np.array(features)

def get_raw_training_labels():
# Uses 20 photo series from the Cohn-Kanade dataset
# hand labeled by AP
# arousal(least, most), valence(negative, positive), power, anticipation
raw_training_labels = {1: [10, [.6, .4, .7, .6], [.9, .1, .8, .9]],
2: [9, [.2, .5, .6, .1], [.3, .4, .5, .2]],
3: [10, [.8, .9, .2, .9], [.99, .99, .1, .99]],
4: [10, [.2, .4, .4, .5], [.8, .2, .7, .6]],
5: [8, [.2, .4, .2, .1], [.5, .5, .5, .5]],
6: [10, [.8, .2, .2, .5], [.9, .1, .1, .5]],
7: [10, [.7, .4, .5, .6], [.8, .2, .8, .7]],
8: [9, [.5, .5, .4, .5], [.6, .4, .5, .3]],
9: [10, [.6, .4, .4, .7], [.9, .1, .1, .9]],
10: [10, [.1, .5, .2, .1], [.7, .2, .2, .5]],
11: [10, [.2, .4, .5, .2], [.3, .5, .4, .2]],
12: [10, [.6, .2, .2, .4], [.8, .1, .1, .4]],
13: [10, [.6, .4, .7, .5], [.8, .2, .8, .5]],
14: [9, [.1, .5, .5, .5], [.1, .4, .5, .4]],
15: [10, [.1, .4, .5, .5], [.8, .3, .4, .9]],
16: [10, [.6, .4, .7, .6], [.7, .2, .2, .5]],
17: [10, [.5, .4, .6, .5], [.7, .2, .7, .6]],
18: [10, [.7, .4, .2, .7], [.9, .1, .1, .9]],
19: [10, [.7, .3, .3, .5], [.8, .1, .1, .6]],
20: [10, [.6, .3, .2, .5], [.9, .1, .1, .6]]}
labels = dict()
for time_series_key in raw_training_labels:
time_series = raw_training_labels[time_series_key]
num_images = time_series[0]
increment = [(time_series[2][emotion_dimension_idx] - time_series[1][emotion_dimension_idx]) / num_images for emotion_dimension_idx in range(EMOTION_DIMENSION_COUNT)]
labels[time_series_key] = [[increment[label_idx]*image_idx + (time_series[1][label_idx]) for label_idx in range(EMOTION_DIMENSION_COUNT)] for image_idx in range(num_images)]

return labels


def get_training_label_array():
raw_training_labels = get_raw_training_labels()
Expand Down
Empty file added feature/__init__.py
Empty file.
File renamed without changes.
4 changes: 2 additions & 2 deletions svr_plus_tdnn/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def get_image_feature_vector_array():
feature = Feature()
root_directory = "../images"
root_directory = "../data/cohn_kanade_images"
features = list()
for subfile in os.listdir(root_directory):
if "DS_Store" in subfile: continue
Expand Down Expand Up @@ -93,7 +93,7 @@ def get_time_delay_image_training_data(time_delay=2):

def get_image_feature_vector_batches():
feature = Feature()
root_directory = "../images"
root_directory = "../data/cohn_kanade_images"
features = dict()
idx = 1
for subfile in os.listdir(root_directory):
Expand Down
12 changes: 0 additions & 12 deletions svr_plus_tdnn/feature.py

This file was deleted.

2 changes: 2 additions & 0 deletions svr_plus_tdnn/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys
sys.path.append('../feature')
from tdnn import TDNN
from data import get_image_feature_vector_array, get_training_label_array, get_time_delay_training_data
from regressionModel import RegressionModel
Expand Down
3 changes: 0 additions & 3 deletions svr_plus_tdnn/temp.py

This file was deleted.

0 comments on commit 197bba9

Please sign in to comment.