title: How to create a nested tensorflow structure?
body: <p>I have trouble with creating nested pattern using Tensorflow backend. What I want to achieve is to use two model inside of one session. I trained a model and want to use it inside of the SSD COCO object detection model. By the way I assign the model outside of the graph and session(in order to load model once). Whenever I try to run my codes, return an error like: </p>
  
  <blockquote>
    <p>ValueError: Tensor Tensor("activation_76/Softmax:0", shape=(?, 4),
    dtype=float32) is not an element of this graph.</p>
  </blockquote>
  
  <p>I search other Stack Overflow pages however I could not solve my issue.
  Can someone help me to understand the problem and solution ? </p>
  
  <p>Later on I search on the net and found this site :</p>
  
  <p><a href="https://github.com/keras-team/keras/issues/6462" rel="nofollow noreferrer">https://github.com/keras-team/keras/issues/6462</a></p>
  
  <p>and then I tried the line of "model._make_predict_function()" but it did not work for me and this time it returned that one: </p>
  
  <blockquote>
    <p>ValueError: Tensor("Placeholder:0", dtype=float32) must be from the
    same graph as Tensor("total:0", shape=(), dtype=resource).</p>
  </blockquote>
  
  <pre><code>model = tf.keras.models.load_model("CNN-3")
  
  with detection_graph.as_default():
    with tf.Session(graph=detection_graph) as sess:
      while True:
  
  
        ret, image_np = cap.read()
  
        if W is None or H is None:
            (H, W)= image_np.shape[:2]
  
  
        image_np_expanded = np.expand_dims(image_np, axis=0)
        image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
  
        boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
        scores = detection_graph.get_tensor_by_name('detection_scores:0')
  
        classes = detection_graph.get_tensor_by_name('detection_classes:0')
        num_detections = \
                detection_graph.get_tensor_by_name('num_detections:0')
  
  
  
        (boxes, scores, classes, num_detections) = sess.run(
            [boxes, scores, classes, num_detections],
            feed_dict={image_tensor: image_np_expanded})
  
        boxes = np.squeeze(boxes)
        scores = np.squeeze(scores)
        classes = np.squeeze(classes)
  
        indices = np.argwhere(classes == 1)
        boxes = np.squeeze(boxes[indices])
  
        scores = np.squeeze(scores[indices])
        classes = np.squeeze(classes[indices])
  
        rects = []
        boxes = scale(boxes, 0, 1)
  
        my_prediction = model.predict("Some images")
  
        """ ^ these codes return an error """
  </code></pre>