Created
January 10, 2017 18:06
-
-
Save svecon/0ca7e018cf2607e1669a81cf19f3df0c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import tensorflow as tf | |
class EvoNetwork: | |
def __init__(self, input_size, weights, use_biases=False): | |
with tf.Graph().as_default(): | |
self.inputs = tf.placeholder(tf.float32, [None, input_size]) | |
hidden_layer = self.inputs | |
for i, weight in enumerate(weights): | |
with tf.variable_scope('hidden_layer_{}'.format(i)): | |
W = tf.Variable( | |
initial_value=weight.astype(np.float32), | |
trainable=False, | |
name='W', | |
) | |
b = tf.Variable( | |
initial_value=np.zeros((weight.shape[1])).astype(np.float32), | |
trainable=False, | |
name='b', | |
) | |
hidden_layer = tf.add(tf.matmul(hidden_layer, W), b) | |
if i+1 < len(weights): | |
hidden_layer = tf.nn.tanh(hidden_layer) | |
self.output_layer = hidden_layer | |
self.session = tf.Session() | |
self.session.run(tf.global_variables_initializer()) | |
def infer(self, inputs): | |
[infer] = self.session.run([self.output_layer], {self.inputs: inputs}) | |
return infer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment