From d4255ab4ce772270d80d157c5245aa1a9ae3a0f9 Mon Sep 17 00:00:00 2001 From: Rineez Ahmed N Date: Mon, 26 Jul 2021 10:37:29 +0530 Subject: [PATCH 1/5] Update gitignore with more rules for python projects that use VS-Code or PyCharm --- .gitignore | 9 +++++++++ 1 file changed, 9 insertions(+) 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 From dc1b529bbadd4743b0336814112f66aa15dd0f24 Mon Sep 17 00:00:00 2001 From: Rineez Ahmed N Date: Mon, 26 Jul 2021 10:39:14 +0530 Subject: [PATCH 2/5] Just removed some unnecessary commas --- code/exp_configurations.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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)], From eb8754b8605555c208e6e8218798024b32d7ba35 Mon Sep 17 00:00:00 2001 From: Rineez Ahmed N Date: Mon, 26 Jul 2021 10:42:53 +0530 Subject: [PATCH 3/5] just some code formatting --- code/train.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) 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:]) From ae1ea4649f31328209beb59a91565fe2bb99e2cb Mon Sep 17 00:00:00 2001 From: Rineez Ahmed N Date: Mon, 26 Jul 2021 10:49:00 +0530 Subject: [PATCH 4/5] Fix keras.utils package that is now integrated to Tensorflow package --- code/Utility.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/Utility.py b/code/Utility.py index 01df9ed..bcdcab4 100644 --- a/code/Utility.py +++ b/code/Utility.py @@ -6,7 +6,7 @@ """ 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 From c352a72b07a14ad4351a8b329cb3caabbabf8491 Mon Sep 17 00:00:00 2001 From: Rineez Ahmed N Date: Mon, 26 Jul 2021 20:42:57 +0530 Subject: [PATCH 5/5] Fix NoneType error while sorting configurations list Replace all NoneType items from tuples inside configuration items to generate sortable keys --- code/Utility.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/code/Utility.py b/code/Utility.py index bcdcab4..47b9a23 100644 --- a/code/Utility.py +++ b/code/Utility.py @@ -4,6 +4,7 @@ @Author: Dat Tran @Email: viebboy@gmail.com, dat.tranthanh@tut.fi, thanh.tran@tuni.fi """ +import math import numpy as np from tensorflow.keras.utils import to_categorical @@ -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):