Can someone explain to me how name_scope works in TensorFlow?
Suppose I have the following code:
Your problem is that you are calling the latest variable product which points to a tensor created on g2 - you overwrote it in your second scope. Just relabel all your variables and you should be good to go. The working code is below.
import tensorflow as tf
g1 = tf.Graph() with g1.as_default() as g:
with g.name_scope( "g1" ) as scope:
matrix11 = tf.constant([[3., 3.]])
matrix21 = tf.constant([[2.],[2.]])
product1 = tf.matmul(matrix11, matrix21)
tf.reset_default_graph()
g2 = tf.Graph() with g2.as_default() as g:
with g.name_scope( "g2" ) as scope:
matrix12 = tf.constant([[4., 4.]])
matrix22 = tf.constant([[5.],[5.]])
product2 = tf.matmul(matrix12, matrix22)
tf.reset_default_graph()
with tf.Session( graph = g1 ) as sess:
result = sess.run( product1 )
print( result )