update to tf2

tf2
server 2020-02-21 19:34:03 -07:00
parent ab4249ae2c
commit 0fc2fbda0c
1 changed files with 8 additions and 8 deletions

View File

@ -56,8 +56,8 @@ operators = {ast.Add: tf.add, # e.g., a + b
'square': tf.square, # e.g., square(a)
'sqrt': tf.sqrt, # e.g., sqrt(a)
'pow': tf.pow, # e.g., pow(a, b)
'log': tf.log, # e.g., log(a)
'log1p': tf.log1p, # e.g., log1p(a)
'log': tf.math.log, # e.g., log(a)
'log1p': tf.math.log1p, # e.g., log1p(a)
'cos': tf.cos, # e.g., cos(a)
'sin': tf.sin, # e.g., sin(a)
'tan': tf.tan, # e.g., tan(a)
@ -1228,11 +1228,11 @@ class Base_GP(object):
'''
# Initialize TensorFlow session
tf.reset_default_graph() # Reset TF internal state and cache (after previous processing)
config = tf.ConfigProto(log_device_placement=self.tf_device_log, allow_soft_placement=True)
tf.compat.v1.reset_default_graph() # Reset TF internal state and cache (after previous processing)
config = tf.compat.v1.ConfigProto(log_device_placement=self.tf_device_log, allow_soft_placement=True)
config.gpu_options.allow_growth = True
with tf.Session(config=config) as sess:
with tf.compat.v1.Session(config=config) as sess:
with sess.graph.device(self.tf_device):
# 1 - Load data into TF vectors
@ -1314,7 +1314,7 @@ class Base_GP(object):
else: raise Exception('Kernel type is wrong or missing. You entered {}'.format(self.kernel))
fitness = tf.reduce_sum(pairwise_fitness)
fitness = tf.reduce_sum(input_tensor=pairwise_fitness)
# Process TF graph and collect the results
result, pred_labels, solution, fitness, pairwise_fitness = sess.run([result, pred_labels, solution, fitness, pairwise_fitness])
@ -1433,9 +1433,9 @@ class Base_GP(object):
for class_label in range(self.class_labels - 2, 0, -1):
cond = (class_label - 1 - skew < result) & (result <= class_label - skew)
label_rules[class_label] = tf.cond(cond, lambda: (tf.constant(class_label), tf.constant(' <= {}'.format(class_label - skew))), lambda: label_rules[class_label + 1])
label_rules[class_label] = tf.cond(pred=cond, true_fn=lambda: (tf.constant(class_label), tf.constant(' <= {}'.format(class_label - skew))), false_fn=lambda: label_rules[class_label + 1])
pred_label = tf.cond(result <= 0 - skew, lambda: (tf.constant(0), tf.constant(' <= {}'.format(0 - skew))), lambda: label_rules[1])
pred_label = tf.cond(pred=result <= 0 - skew, true_fn=lambda: (tf.constant(0), tf.constant(' <= {}'.format(0 - skew))), false_fn=lambda: label_rules[1])
return pred_label