title: Tensorflow object_detection: unable to find input and output tensors
body: <p>I've successfully trained and saved a faster RCNN model for tensorflow using their object detection API. I'm now trying to run some inferences on the code, taking bits of code from <a href="https://github.com/tensorflow/models/blob/master/object_detection/object_detection_tutorial.ipynb" rel="nofollow noreferrer">this tutorial</a>.</p>
  
  <p>However, after I successfully restore the metagraph and the checkpoint, the system can't find the input and output nodes, I get the following error:</p>
  
  <blockquote>
    <p>KeyError: "The name 'image_tensor:0' refers to a Tensor which does not
    exist. The operation, 'image_tensor', does not exist in the graph."</p>
  </blockquote>
  
  <p>The checkpoint and metagraph were created by the train.py script, on my own data, following the instructions given <a href="https://github.com/tensorflow/models/blob/master/object_detection/g3doc/running_locally.md" rel="nofollow noreferrer">here</a>.</p>
  
  <p>This is my code:</p>
  
  <pre><code>OUTPUT_DIR = "my_path/models/SSD_v1/train"
  CKPT_DIR = OUTPUT_DIR
  LATEST_CKPT_FILENAME = "checkpoint"
  LAST_CKPT_FILE = os.path.join(CKPT_DIR, LATEST_CKPT_FILENAME)
  MODEL_FILENAME_PATH = os.path.join(OUTPUT_DIR, "model.ckpt.meta")
  def load_image_into_numpy_array(image):
    (im_width, im_height) = image.size
    return np.array(image.getdata()).reshape(
        (im_height, im_width, 3)).astype(np.uint8)
  
  
  def test_model(images_list, path_to_ckpt=None,
                 meta_graph=None):
      if path_to_ckpt is None:
          path_to_ckpt = tf.train.latest_checkpoint(CKPT_DIR, LATEST_CKPT_FILENAME)
      if meta_graph is None:
          meta_graph = MODEL_FILENAME_PATH
      print("test_model launched")
  
      tf.reset_default_graph()
      detection_graph = tf.Graph()
      with detection_graph.as_default():
          with tf.Session(graph=detection_graph) as sess:
              # Restore graph
              saver = tf.train.import_meta_graph(meta_graph, clear_devices=True)
              print('metagraph restored')
              saver.restore(sess, path_to_ckpt)
              print('graph restored')
  
              image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')  # This is where the error happens
              # Each box represents a part of the image where a particular object was detected.
              detected_boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
              # Each score represent how level of confidence for each of the objects.
              # Score is shown on the result image, together with the class label.
              detected_scores = detection_graph.get_tensor_by_name('detection_scores:0')
              detected_classes = detection_graph.get_tensor_by_name('detection_classes:0')
              num_detections = graph.get_tensor_by_name('num_detections:0')
  
              print("Output tensors: ")
              print(detected_boxes)
              print(detected_scores)
              print(detected_classes)
              print('')
  
              for i, image in enumerate(images_list):
                  detected_boxes, detected_scores, detected_classes, num_detect = sess.run([detected_boxes, detected_scores, detected_classes, num_detections],
                           feed_dict={image_tensor: image})
                  print(i, num_detect, detected_boxes, detected_scores, detected_classes)
  
  
  def main():
      directory_path = "../data/samples/"
      image_files = [f for f in os.listdir(directory_path) if os.path.isfile(os.path.join(directory_path, f))]
      # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
      image_list = [ np.expand_dims(load_image_into_numpy_array(Image.open(os.path.join(directory_path, f))), axis=0) for f in image_files]
      test_model(images_list=image_list)
  
  if __name__=="__main__":
      main()
  </code></pre>
  
  <p>Full error stacktrace:</p>
  
  <pre><code>Traceback (most recent call last):   File "/home/guillaumedelaboulaye/PR8210PANO/faster-rcnn/pano_faster_rcnn/src/run_faster_rcnn_inference.py", line 99, in &lt;module&gt;
      main()   File "/home/guillaumedelaboulaye/PR8210PANO/faster-rcnn/pano_faster_rcnn/src/run_faster_rcnn_inference.py", line 95, in main
      test_model(images_list=image_list)   File "/home/guillaumedelaboulaye/PR8210PANO/faster-rcnn/pano_faster_rcnn/src/run_faster_rcnn_inference.py", line 48, in test_model
      image_tensor = graph.get_tensor_by_name('image_tensor:0')   File "/home/guillaumedelaboulaye/PR8210PANO/faster-rcnn/venv/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2733, in get_tensor_by_name
      return self.as_graph_element(name, allow_tensor=True, allow_operation=False)   File "/home/guillaumedelaboulaye/PR8210PANO/faster-rcnn/venv/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2584, in as_graph_element
      return self._as_graph_element_locked(obj, allow_tensor, allow_operation)   File "/home/guillaumedelaboulaye/PR8210PANO/faster-rcnn/venv/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2626, in _as_graph_element_locked
      "graph." % (repr(name), repr(op_name))) KeyError: "The name 'image_tensor:0' refers to a Tensor which does not exist. The operation, 'image_tensor', does not exist in the graph."
  </code></pre>