title: Import a simple Tensorflow frozen_model.pb file and make prediction in C++
body: <p>I am trying to import a graph I exported from Tensorflow Python into Tensorflow C++. I've already successfully re-imported the graph into Python. The only thing I want now is to write the same code in C++ but I am not sure about the C++ api functions and there usage as the documentation on the Tensorflow website is not good enough.</p>
  
  <p>Here's the C++ code I found so far.</p>
  
  <p><strong>C++:</strong></p>
  
  <pre><code>namespace tf = tensorflow;
  
  tf::Session* session;
  
  tf::Status status = tf::NewSession(tf::SessionOptions(), &amp;session);
  checkStatus(status);
  
  tf::GraphDef graph_def;
  status = ReadBinaryProto(tf::Env::Default(), "./models/frozen_model.pb", &amp;graph_def);
  checkStatus(status);
  
  status = session-&gt;Create(graph_def);
  checkStatus(status);
  
  tf::Tensor x(tf::DT_FLOAT, tf::TensorShape());
  tf::Tensor y(tf::DT_FLOAT, tf::TensorShape());
  
  x.scalar&lt;float&gt;()() = 23.0;
  y.scalar&lt;float&gt;()() = 19.0;
  
  std::vector&lt;std::pair&lt;tf::string, tf::Tensor&gt;&gt; input_tensors = {{"x", x}, {"y", y}};
  std::vector&lt;string&gt; vNames; // vector of names for required graph nodes
  vNames.push_back("prefix/input_neurons:0");
  vNames.push_back("prefix/prediction_restore:0");
  std::vector&lt;tf::Tensor&gt; output_tensors;
  
  status = session-&gt;Run({}, vNames,  {}, &amp;output_tensors);
  checkStatus(status);
  
  tf::Tensor output = output_tensors[0];
  std::cout &lt;&lt; "Success: " &lt;&lt; output.scalar&lt;float&gt;() &lt;&lt; "!" &lt;&lt; std::endl;
  session-&gt;Close();
  return 0;
  </code></pre>
  
  <p>The problem I am having with the current c++ code above is that it says it cannot find any operation by the name of <code>prefix/input_neurons:0</code>. Although there is an operation in the graph because when i import this graph in the Python code (shown below), it works perfectly fine.</p>
  
  <p>Here's the Python code to import the graph successfully.</p>
  
  <p><strong>Python: ( Works perfectly fine )</strong></p>
  
  <pre><code>def load_graph(frozen_graph_filename):
      # We load the protobuf file from the disk and parse it to retrieve the 
      # unserialized graph_def
      with tf.gfile.GFile(frozen_graph_filename, "rb") as f:
          graph_def = tf.GraphDef()
          graph_def.ParseFromString(f.read())
  
      # Then, we can use again a convenient built-in function to import a graph_def into the 
      # current default Graph
      with tf.Graph().as_default() as graph:
          tf.import_graph_def(
              graph_def, 
              input_map=None, 
              return_elements=None, 
              name="prefix", 
              op_dict=None, 
              producer_op_list=None
          )
      return graph
  
  # We use our "load_graph" function
  graph = load_graph("./models/frozen_model.pb")
  
  # We can verify that we can access the list of operations in the graph
  for op in graph.get_operations():
      print(op.name)     # &lt;--- printing the operations snapshot below
      # prefix/Placeholder/inputs_placeholder
      # ...
      # prefix/Accuracy/predictions
  
  # We access the input and output nodes
  x = graph.get_tensor_by_name('prefix/input_neurons:0')
  y = graph.get_tensor_by_name('prefix/prediction_restore:0')
  
  # We launch a Session
  with tf.Session(graph=graph) as sess:
  
      test_features = [[0.377745556,0.009904444,0.063231111,0.009904444,0.003734444,0.002914444,0.008633333,0.000471111,0.009642222,0.05406,0.050163333,7e-05,0.006528889,0.000314444,0.00649,0.043956667,0.016816667,0.001644444,0.016906667,0.00204,0.027342222,0.13864]]
          # compute the predicted output for test_x
      pred_y = sess.run( y, feed_dict={x: test_features} )
      print(pred_y)
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>I can print the operations from the python script. Here's the screenshot.</p>
  
  <p><a href="https://i.stack.imgur.com/5RN7d.png" rel="noreferrer"><img src="https://i.stack.imgur.com/5RN7d.png" alt="enter image description here"></a></p>
  
  <p>Here's the error I get.</p>
  
  <p><a href="https://i.stack.imgur.com/E1o9q.png" rel="noreferrer"><img src="https://i.stack.imgur.com/E1o9q.png" alt="enter image description here"></a></p>