title: Keras Tensorflow - Exception while predicting from multiple threads
body: <p>I am using keras 2.0.8 with tensorflow 1.3.0 backend.</p>
  
  <p>I am loading a model in the class init and then use it to predict multithreaded.</p>
  
  
  
  <pre class="lang-python prettyprint-override"><code>import tensorflow as tf
  from keras import backend as K
  from keras.models import load_model
  
  
  class CNN:
      def __init__(self, model_path):
          self.cnn_model = load_model(model_path)
          self.session = K.get_session()
          self.graph = tf.get_default_graph()
  
      def query_cnn(self, data):
          X = self.preproccesing(data)
          with self.session.as_default():
              with self.graph.as_default():
                  return self.cnn_model.predict(X)
  </code></pre>
  
  <p>I initialize the CNN once and the query_cnn method happens from multiple threads.</p>
  
  <p>The exception i get in my log is:</p>
  
  <pre class="lang-python prettyprint-override"><code>  File "/home/*/Similarity/CNN.py", line 43, in query_cnn
      return self.cnn_model.predict(X)
    File "/usr/local/lib/python3.5/dist-packages/keras/models.py", line 913, in predict
      return self.model.predict(x, batch_size=batch_size, verbose=verbose)
    File "/usr/local/lib/python3.5/dist-packages/keras/engine/training.py", line 1713, in predict
      verbose=verbose, steps=steps)
    File "/usr/local/lib/python3.5/dist-packages/keras/engine/training.py", line 1269, in _predict_loop
      batch_outs = f(ins_batch)
    File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 2273, in __call__
      **self.session_kwargs)
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 895, in run
      run_metadata_ptr)
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1124, in _run
      feed_dict_tensor, options, run_metadata)
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1321, in _do_run
      options, run_metadata)
    File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1340, in _do_call
      raise type(e)(node_def, op, message)
  tensorflow.python.framework.errors_impl.NotFoundError: PruneForTargets: Some target nodes not found: group_deps 
  </code></pre>
  
  <p>The code works fine most of the times, its probably some problem with the multithreading.</p>
  
  <p>How can i fix it?</p>