title: Keras + Tensorflow and Multiprocessing in Python
body: <p>I'm using Keras with Tensorflow as backend.</p>
  
  <p>I am trying to save a model in my main process and then load/run (i.e. call <code>model.predict</code>) within another process.</p>
  
  <p>I'm currently just trying the naive approach from the docs to save/load the model: <a href="https://keras.io/getting-started/faq/#how-can-i-save-a-keras-model" rel="noreferrer">https://keras.io/getting-started/faq/#how-can-i-save-a-keras-model</a>.<br>
  So basically:</p>
  
  <ol>
  <li><code>model.save()</code> in main process</li>
  <li><code>model = load_model()</code> in child process</li>
  <li><code>model.predict()</code> in child process</li>
  </ol>
  
  <p>However, it simply hangs on the <code>load_model</code> call.</p>
  
  <p>Searching around I've discovered this potentially related answer suggesting that Keras can only be utilized in one process: <a href="https://stackoverflow.com/questions/38176827/using-multiprocessing-with-theano">using multiprocessing with theano</a> but am unsure if this is true (can't seem to find much on this).</p>
  
  <p>Is there a way to accomplish my goal?  A high level description or short example is greatly appreciated.</p>
  
  <p>Note: I've attempted approaches along the lines of passing a graph to the process but failed since it seems tensorflow graphs aren't pickable (related SO post for that here: <a href="https://stackoverflow.com/questions/34900246/tensorflow-passing-a-session-to-a-python-multiprocess">Tensorflow: Passing a session to a python multiprocess</a>).  If there is indeed a way to pass the tensorflow graph/model to the child process then I am open to that as well.</p>
  
  <p>Thanks!</p>