-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplified recognition of definition of callback metrics for TF 1x vs…
… 2.x This is now more robust.
- Loading branch information
Showing
4 changed files
with
8 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
''' | ||
********************************************************** | ||
* SpectraKeras_CNN Classifier and Regressor | ||
* 20200113a | ||
* 20200121a | ||
* Uses: TensorFlow | ||
* By: Nicola Ferralis <[email protected]> | ||
*********************************************************** | ||
|
@@ -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,21 +211,13 @@ 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) | ||
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] | ||
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
''' | ||
********************************************************** | ||
* SpectraKeras_MLP Classifier and Regressor | ||
* 20200113a | ||
* 20200121a | ||
* Uses: TensorFlow | ||
* By: Nicola Ferralis <[email protected]> | ||
*********************************************************** | ||
|
@@ -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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters