title: Tensorflow: How to initialize variables on another graph?
body: <p>I have a default graph and a newly created graph (G1).</p>
  
  <p>In G1, I have a variable named "a".</p>
  
  <p>I can use <code>tf.import_graph_def</code> to include G1 onto the main graph, and expose its "a" variable.</p>
  
  <p><strong>How do I initialize this variable and successfully print the value of "a" ?</strong> </p>
  
  <p>Here is the actual code:</p>
  
  <pre><code>import tensorflow as tf
  
  INT = tf.int32
  
  
  def graph():
      g = tf.Graph()
      with g.as_default() as g:
          a = tf.get_variable('a', [], INT, tf.constant_initializer(10))
      return g
  
  
  tf.reset_default_graph()
  
  g = graph()
  [g_a] = tf.import_graph_def(g.as_graph_def(), return_elements=['a:0'])
  
  with tf.Session() as sess:
      sess.run(tf.global_variables_initializer())
      print(sess.run(g_a))
  </code></pre>
  
  <p>The above won't work, it will error with <code>FailedPreconditionError: Attempting to use uninitialized value import/a</code>.</p>