diff --git a/SpectraKeras/SpectraKeras_CNN.py b/SpectraKeras/SpectraKeras_CNN.py index 77da27b..0a94012 100755 --- a/SpectraKeras/SpectraKeras_CNN.py +++ b/SpectraKeras/SpectraKeras_CNN.py @@ -3,7 +3,7 @@ ''' ********************************************************** * SpectraKeras_CNN Classifier and Regressor -* 20200113a +* 20200121a * Uses: TensorFlow * By: Nicola Ferralis *********************************************************** @@ -189,10 +189,6 @@ def main(): #************************************ def train(learnFile, testFile, flag): dP = Conf() - - def_mae = 'mae' - def_val_mae = 'val_mae' - import tensorflow as tf import tensorflow.keras as keras from pkg_resources import parse_version @@ -215,9 +211,6 @@ def train(learnFile, testFile, flag): # gpus[0], # [tf.config.experimental.VirtualDeviceConfiguration(memory_limit=dP.maxMem)]) - def_acc = 'accuracy' - def_val_acc = 'val_accuracy' - else: opts = tf.compat.v1.GPUOptions(per_process_gpu_memory_fraction=1) conf = tf.compat.v1.ConfigProto(gpu_options=opts) @@ -225,11 +218,6 @@ def train(learnFile, testFile, flag): tf.compat.v1.Session(config=conf) - def_mae = 'mean_absolute_error' - def_val_mae = 'val_mean_absolute_error' - def_acc = 'acc' - def_val_acc = 'val_acc' - learnFileRoot = os.path.splitext(learnFile)[0] En, A, Cl = readLearnFile(learnFile, dP) if testFile != None: @@ -409,6 +397,7 @@ def train(learnFile, testFile, flag): val_loss = np.asarray(log.history['val_loss']) if dP.regressor: + def_mae, def_val_mae = [list(log.history)[i] for i in (1,3)] val_mae = np.asarray(log.history[def_val_mae]) printParam() print('\n ==========================================================') @@ -432,6 +421,7 @@ def train(learnFile, testFile, flag): predictions[i][0], score[0], score[1])) print('\n ==========================================================\n') else: + def_acc, def_val_acc = [list(log.history)[i] for i in (1,3)] accuracy = np.asarray(log.history[def_acc]) val_acc = np.asarray(log.history[def_val_acc]) print(" Number unique classes (training): ", np.unique(Cl).size) diff --git a/SpectraKeras/SpectraKeras_MLP.py b/SpectraKeras/SpectraKeras_MLP.py index c785d48..c02b386 100755 --- a/SpectraKeras/SpectraKeras_MLP.py +++ b/SpectraKeras/SpectraKeras_MLP.py @@ -3,7 +3,7 @@ ''' ********************************************************** * SpectraKeras_MLP Classifier and Regressor -* 20200113a +* 20200121a * Uses: TensorFlow * By: Nicola Ferralis *********************************************************** @@ -165,10 +165,6 @@ def main(): #************************************ def train(learnFile, testFile): dP = Conf() - - def_mae = 'mae' - def_val_mae = 'val_mae' - import tensorflow as tf import tensorflow.keras as keras from pkg_resources import parse_version @@ -191,20 +187,12 @@ def train(learnFile, testFile): # gpus[0], # [tf.config.experimental.VirtualDeviceConfiguration(memory_limit=dP.maxMem)]) - def_acc = 'accuracy' - def_val_acc = 'val_accuracy' - else: opts = tf.compat.v1.GPUOptions(per_process_gpu_memory_fraction=1) conf = tf.compat.v1.ConfigProto(gpu_options=opts) conf.gpu_options.allow_growth = True tf.compat.v1.Session(config=conf) - - def_mae = 'mean_absolute_error' - def_val_mae = 'val_mean_absolute_error' - def_acc = 'acc' - def_val_acc = 'val_acc' learnFileRoot = os.path.splitext(learnFile)[0] @@ -345,6 +333,7 @@ def train(learnFile, testFile): val_loss = np.asarray(log.history['val_loss']) if dP.regressor: + def_mae, def_val_mae = [list(log.history)[i] for i in (1,3)] val_mae = np.asarray(log.history[def_val_mae]) printParam() print('\n ==========================================================') @@ -367,6 +356,7 @@ def train(learnFile, testFile): predictions[i][0], score[0], score[1])) print('\n ==========================================================\n') else: + def_acc, def_val_acc = [list(log.history)[i] for i in (1,3)] accuracy = np.asarray(log.history[def_acc]) val_acc = np.asarray(log.history[def_val_acc]) print(" Number unique classes (training): ", np.unique(Cl).size) diff --git a/SpectraKeras/setup-gpu.py b/SpectraKeras/setup-gpu.py index 819a7f8..0625d98 100644 --- a/SpectraKeras/setup-gpu.py +++ b/SpectraKeras/setup-gpu.py @@ -7,7 +7,7 @@ entry_points={'console_scripts' : ['SpectraKeras_MLP=SpectraKeras_MLP:SpectraKeras_MLP', 'SpectraKeras_CNN=SpectraKeras_CNN:SpectraKeras_CNN']}, py_modules=['SpectraKeras_MLP','SpectraKeras_CNN','libSpectraKeras'], - version='20200113a', + version='20200121a', description='Machine learning for spectral data', long_description= """ Machine learning for spectral data """, author='Nicola Ferralis', diff --git a/SpectraKeras/setup.py b/SpectraKeras/setup.py index fba4ac4..3001ec5 100644 --- a/SpectraKeras/setup.py +++ b/SpectraKeras/setup.py @@ -7,7 +7,7 @@ entry_points={'console_scripts' : ['SpectraKeras_MLP=SpectraKeras_MLP:SpectraKeras_MLP', 'SpectraKeras_CNN=SpectraKeras_CNN:SpectraKeras_CNN']}, py_modules=['SpectraKeras_MLP','SpectraKeras_CNN','libSpectraKeras'], - version='20200113a', + version='20200121a', description='Machine learning for spectral data', long_description= """ Machine learning for spectral data """, author='Nicola Ferralis',