Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
code/*.pyc
code/__pycache__
*.py[cod]
*$py.class

# Editors
.vscode/
.idea/

# Windows
Thumbs.db

17 changes: 15 additions & 2 deletions code/Utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
@Author: Dat Tran
@Email: viebboy@gmail.com, dat.tranthanh@tut.fi, thanh.tran@tuni.fi
"""
import math

import numpy as np
from keras.utils import to_categorical
from tensorflow.keras.utils import to_categorical
import os
import pickle
from keras.preprocessing.image import ImageDataGenerator
Expand All @@ -25,9 +26,21 @@ def create_configuration(hyperparameter_list, value_list):
configurations += list(itertools.product(*v_list))

configurations = list(set(configurations))
configurations.sort()
configurations.sort(key=getSortableKey)
return configurations

def getSortableKey(x):
sortKey = []
for element in x:
# To avoid tuples with NoneType elements causing error while sorting
if isinstance(element, tuple):
theTuple = element;
nonesRemoved = [-1 * math.inf if item is None else item for item in theTuple]
sortKey.append(tuple(nonesRemoved));
else:
sortKey.append(element);

return sortKey

def flatten(data, mode):

Expand Down
18 changes: 9 additions & 9 deletions code/exp_configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
'LR',
'Epoch']

conf_baseline = {'dataset': ['cfw32x32',],
'classifier': ['allcnn', ],
conf_baseline = {'dataset': ['cfw32x32'],
'classifier': ['allcnn'],
'regularizer': [(1e-4, None)],
'LR': [LR],
'Epoch': [EPOCH]}
Expand Down Expand Up @@ -81,8 +81,8 @@
'classifier': ['allcnn', 'resnet'],
'target_shape': [(20, 19, 2), (28, 27, 1), (14, 11, 2), (18, 17, 1), (9, 6, 1), (6, 9, 1)],
'sensing_mode': ['tensor'],
'linear_sensing': [True,],
'end_to_end': [True,],
'linear_sensing': [True],
'end_to_end': [True],
'mean_update': [False],
'augmentation': [True],
'regularizer': [(1e-4, None)],
Expand All @@ -98,8 +98,8 @@
'classifier': ['allcnn'],
'target_shape': [(20, 19, 2), (28, 27, 1), (14, 11, 2), (18, 17, 1), (9, 6, 1), (6, 9, 1)],
'sensing_mode': ['tensor'],
'linear_sensing': [True,],
'end_to_end': [True,],
'linear_sensing': [True],
'end_to_end': [True],
'mean_update': [False],
'augmentation': [True],
'regularizer': [(1e-4, None)],
Expand All @@ -117,7 +117,7 @@
'target_shape': [(20, 19, 2), (28, 27, 1), (14, 11, 2), (18, 17, 1), (9, 6, 1), (6, 9, 1)],
'sensing_mode': ['tensor'],
'linear_sensing': [True, False],
'end_to_end': [True,],
'end_to_end': [True],
'mean_update': [False],
'augmentation': [True],
'regularizer': [(1e-4, None)],
Expand All @@ -133,8 +133,8 @@
'classifier': ['allcnn'],
'target_shape': [(28, 27, 1), (18, 17, 1), (9, 6, 1)],
'sensing_mode': ['tensor'],
'linear_sensing': [True,],
'end_to_end': [True,],
'linear_sensing': [True],
'end_to_end': [True],
'mean_update': [False],
'augmentation': [True],
'regularizer': [(1e-4, None)],
Expand Down
23 changes: 12 additions & 11 deletions code/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ def save_result(output, path):
fid.close()

def main(argv):

try:
opts, args = getopt.getopt(argv,"h", ['index=' ])
opts, args = getopt.getopt(argv, "h", ['index='])

except getopt.GetoptError:
sys.exit(2)
for opt, arg in opts:

for opt, arg in opts:
if opt == '--index':
index = int(arg)

baseline_configurations = Utility.create_configuration([Conf.baseline_var_names], [Conf.conf_baseline])
experiment_configurations = Utility.create_configuration([Conf.hyperparameters]*5,
[Conf.conf_vector,
Expand All @@ -47,13 +46,15 @@ def main(argv):
output = Runners.train_baseline(baseline_configurations[index])
filename = '_'.join([str(v) for v in baseline_configurations[index]]) + '.pickle'
filename = os.path.join(Conf.BASELINE_DIR, filename)

else:
output = Runners.train_sensing(experiment_configurations[index-len(baseline_configurations)])
filename = '_'.join([str(v) for v in experiment_configurations[index-len(baseline_configurations)]]) + '.pickle'
output = Runners.train_sensing(experiment_configurations[index - len(baseline_configurations)])
filename = '_'.join(
[str(v) for v in experiment_configurations[index - len(baseline_configurations)]]) + '.pickle'
filename = os.path.join(Conf.OUTPUT_DIR, filename)

save_result(output, filename)



if __name__ == "__main__":
main(sys.argv[1:])