I'm trying to run my code using TensorFlow.
init = tf.global_variables_initializer()
loaded_graph = tf.Graph()
saver = tf.train.Saver()
with tf.Session(loaded_graph) as sess:
sess.run(init)
...
But I got this error.
File "C:\Users\K451LN\My Documents\LiClipse Workspace\neuralnet\FFNN.py", line 68, in <module>
with tf.Session(loaded_graph) as sess:
AttributeError: 'Session' object has no attribute '_session'
Is there anything wrong with the tf.Graph()?
Here is my code:
for i in range(num_networks):
print("Neural network: {0}".format(i))
X = tf.placeholder(tf.float32)
Y = tf.placeholder(tf.float32)
W1 = tf.Variable(tf.random_uniform([n_input, n_hidden], -1.0, 1.0), name = 'W1')
W2 = tf.Variable(tf.random_uniform([n_hidden, n_output], -1.0, 1.0), name = 'W2')
b1 = tf.Variable(tf.zeros([n_hidden]), name="Bias1")
b2 = tf.Variable(tf.zeros([n_output]), name="Bias2")
L2 = tf.sigmoid(tf.matmul(X, W1) + b1)
hy = tf.sigmoid(tf.matmul(L2, W2) + b2, name="op_to_restore")
cost = tf.reduce_mean(-Y*tf.log(hy) - (1-Y)*tf.log(1-hy))
optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)
init = tf.global_variables_initializer()
loaded_graph = tf.Graph()
saver = tf.train.Saver()
with tf.Session(loaded_graph) as sess:
sess.run(init)
...
I'm adding thistf.Graph() to solve the error of ValueError: At least two variables have the same name: Bias2.