diff --git a/.gitignore b/.gitignore index 209deaf..10597eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,12 @@ code/*.pyc code/__pycache__ +*.py[cod] +*$py.class + +# Editors +.vscode/ +.idea/ + +# Windows +Thumbs.db diff --git a/code/Utility.py b/code/Utility.py index 01df9ed..47b9a23 100644 --- a/code/Utility.py +++ b/code/Utility.py @@ -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 @@ -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): diff --git a/code/exp_configurations.py b/code/exp_configurations.py index 08f0497..aa57180 100644 --- a/code/exp_configurations.py +++ b/code/exp_configurations.py @@ -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]} @@ -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)], @@ -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)], @@ -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)], @@ -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)], diff --git a/code/train.py b/code/train.py index 7410741..084a901 100644 --- a/code/train.py +++ b/code/train.py @@ -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, @@ -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:])