Tensorflow Initialize Variable Error
As you all know there are various ways to initialize your variables in tensorflow. I tried some stuff in combination with a graph definition. See the code below. def Graph1a():
Solution 1:
The problem is that the global_variables_initializer
needs to be associated with the same graph as the session. In Graph1c
this happens because the global_variables_initializer
is inside the scope of the with statement of the session. To get Graph1a
to work it needs to be rewritten like this
def Graph1a():
g1 = tf.Graph()
with g1.as_default() as g:
matrix1 = tf.constant([[3., 3.]])
matrix2 = tf.constant([[2.],[2.]])
product = tf.matmul( matrix1, matrix2, name = "product")
init_op = tf.global_variables_initializer()
sess = tf.Session( graph = g )
sess.run(init_op)
return product
Post a Comment for "Tensorflow Initialize Variable Error"