-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfitness.py
More file actions
executable file
·69 lines (56 loc) · 1.8 KB
/
fitness.py
File metadata and controls
executable file
·69 lines (56 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import tensorflow as tf
import os
import argparse
import sys
import numpy as np
parser = argparse.ArgumentParser()
parser.add_argument(
'--solution',
type=str
)
parser.add_argument(
'--type',
type=str
)
parser.add_argument(
'--genes',
type=int
)
FLAGS, unparsed = parser.parse_known_args()
model_path = "./TensorFlow/DNN_Models-" + str(FLAGS.genes) + "-noiseless/" + FLAGS.type + str(FLAGS.genes) + ".csv"
meta_file = '{}/model.meta'.format(model_path)
ckpt_file = '{}/checkpoint'.format(model_path)
x_ = FLAGS.solution.split('[')[1]
x_ = x_.split(']')[0]
input_xx = x_.split('/')
print(input_xx)
input_x = list()
for i in range(0, len(input_xx)):
if i == 0:
input_x = input_xx[i].split(',')
else:
input_x = np.vstack([input_x, input_xx[i].split(',')])
input_x = np.array(input_x).reshape((len(input_xx),FLAGS.genes))
input_y = np.zeros((len(input_xx), 1))
with tf.device('/device:{}:1'.format('CPU')):
config = tf.ConfigProto(allow_soft_placement=True)
sess = tf.Session(config=config)
sess.run(tf.global_variables_initializer())
sess.run(tf.local_variables_initializer())
model = tf.train.import_meta_graph(meta_file, clear_devices=True)
model.restore(sess, tf.train.latest_checkpoint(model_path))
graph = tf.get_default_graph()
x = graph.get_tensor_by_name('input_x:0')
y = graph.get_tensor_by_name('input_y:0')
keep_prob = graph.get_tensor_by_name('keep_prob:0')
y_predict = graph.get_tensor_by_name('y_predict/BiasAdd:0')
prediction = sess.run(
y_predict,
feed_dict={x: input_x, y: input_y, keep_prob: 1.0}
)
tf.reset_default_graph()
sess.close()
with open('result','w') as f:
for i in range(0, len(input_xx)):
f.write(str(prediction[i][0]))
f.write(' ')