title: TensorFlow - import meta graph and use variables from it
body: <p>I'm training classification CNN using TensorFlow v0.12, and then want to create labels for new data using the trained model.</p>
  
  <p>At the end of the training script, I added those lines of code:</p>
  
  <pre><code>saver = tf.train.Saver()
  save_path = saver.save(sess,'/home/path/to/model/model.ckpt')
  </code></pre>
  
  <p>After the training completed, the files appearing in the folder are: 1. <em>checkpoint</em> ; 2. <em>model.ckpt.data-00000-of-00001</em> ; 3. <em>model.ckpt.index</em> ; 4. <em>model.ckpt.meta</em></p>
  
  <p>Then I tried to restore the model using the <em>.meta</em> file. Following <a href="https://www.tensorflow.org/versions/r1.0/how_tos/meta_graph/" rel="noreferrer">this tutorial</a>, I added the following line into my classification code:</p>
  
  <pre><code>saver=tf.train.import_meta_graph(savepath+'model.ckpt.meta') #line1
  </code></pre>
  
  <p>and then:</p>
  
  <pre><code>saver.restore(sess, save_path=savepath+'model.ckpt') #line2
  </code></pre>
  
  <p>Before that change, I needed to build the graph again, and then write (instead of line1):</p>
  
  <pre><code>saver = tf.train.Saver()
  </code></pre>
  
  <p>But, deleting the graph building, and using <code>line1</code> in order to restore it, raised an error. The error was that I used a variable from the graph inside my code, and the python didn't recognize it:</p>
  
  <pre><code>predictions = sess.run(y_conv, feed_dict={x: patches,keep_prob: 1.0})
  </code></pre>
  
  <p>The python didn't recognize the <code>y_conv</code> parameter. There is a way to restore the variables using the meta graph? if not, what os this restore helping, if I can't use variables from the original graph?</p>
  
  <p>I know this question isn't so clear, but it was hard for me to express the problem in words. Sorry about it...</p>
  
  <p>Thanks for answering, appreciate your help! Roi.</p>