title: Attempting to reset tensorflow graph when using keras, failing
body: <p>I'm spinning up a Python 3 API w/gunicorn that uses keras to calculate vectors for an image, pretty straightforward.</p>
  
  <p>How can I reset the data stored in memory for each request? Slowly over time the requests increase in the time it takes to respond. I've run a profiler and it's specifically this line in tensorflow (also memory usage goes up slowly over time per process):</p>
  
  <pre><code>#tensorflow/python/framework/ops.py:2317:_as_graph_def
  graph.node.extend([op.node_def])
  </code></pre>
  
  <p>It takes longer as more data is in the node. Here is the code I execute:</p>
  
  <pre><code># We have 11439MiB of GPU memory, lets only use 2GB of it:
  config = tf.ConfigProto()
  config.gpu_options.per_process_gpu_memory_fraction = 0.22
  sess = tf.Session(config=config)
  set_session(sess)
  sess.graph.as_default()
  
  # Get the vector for the image
  img_size = (224,224)
  vgg = VGG16(include_top=False, weights='imagenet')
  img = kimage.load_img(tmpfile.name, target_size=img_size)
  x = kimage.img_to_array(img)
  x = np.expand_dims(x, axis=0)
  x = preprocess_input(x)
  pred = vgg.predict(x)
  vectors = pred.ravel().tolist()
  </code></pre>
  
  <p>I thought <code>as_default()</code> would help, but it doesn't. I also tried closing the session after I get the list of vectors, and that fails.</p>