Compare commits

...

4 Commits
master ... tf2

Author SHA1 Message Date
server 0fc2fbda0c update to tf2 2020-02-21 19:34:03 -07:00
server ab4249ae2c deps 2020-02-21 19:02:27 -07:00
server aad6d6aace ignore vi swapfiles 2020-02-21 19:02:13 -07:00
server fbb3e36899 Tensorflow 2.1 install 2020-02-21 18:58:21 -07:00
3 changed files with 38 additions and 9 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.venv/
modules/__pycache__/
runs/
*.swp

View File

@ -19,7 +19,7 @@ Learn more at <a href="http://kstaats.github.io/karoo_gp/">kstaats.github.io/kar
# Debian Install
To install on Debian (Buster, Stable, 10):
To install on Debian (Buster/Stable/10):
```
# Install Dependencies:
@ -42,3 +42,31 @@ pip3 install numpy==1.16.4 sympy==1.4 tensorflow==1.13.1 scikit-learn==0.21.2
python3 karoo_gp.py
```
# Tensorflow 2 Install
Using karoo_gp with Tensorflow 2 on Debian (Buster/Stable/10).
```
# Install Dependencies:
sudo apt install python3 python3-pip python3-venv
# Clone repo (choose this one or upstream):
# git clone https://github.com/kstaats/karoo_gp
git clone https://spacecruft.org/spacecruft/karoo_gp
# Setup
cd karoo_gp
python3 -m venv .venv
source .venv/bin/activate
pip3 install --upgrade pip
pip3 install --upgrade setuptools
# Install python dependencies
pip3 install wheel
pip3 install sklearn sympy
# This will install Tensorflow 2.1:
pip3 install tensorflow
# Run application
python3 karoo_gp.py
```

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