<p>Yes, Keras is thread safe, if you pay a little attention to it. </p>

<p>In fact, in reinforcement learning there is an algorithm called <a href="https://arxiv.org/pdf/1602.01783.pdf" rel="noreferrer">Asynchronous Advantage Actor Critics (A3C)</a> where each agent relies on the same neural network to tell them what they should do in a given state. In other words, each thread calls <code>model.predict</code> concurrently as in your problem. An example implementation with Keras of it is <a href="https://github.com/jaara/AI-blog/blob/master/CartPole-A3C.py" rel="noreferrer">here</a>.</p>

<p>You should, however, pay extra attention to this line if you looked into the code:
<code>model._make_predict_function() # have to initialize before threading</code></p>

<p>This is never mentioned in the Keras docs, but its necessary to make it work concurrently. In short, <code>_make_predict_function</code> is a function that compiles the <code>predict</code> function. In multi thread setting, you have to manually call this function to compile <code>predict</code> in advance, otherwise the <code>predict</code> function will not be compiled until you run it the first time, which will be problematic when many threading calling it at once. You can see a detailed explanation <a href="https://github.com/fchollet/keras/issues/6124" rel="noreferrer">here</a>.</p>

<p>I have not met any other issues with multi threading in Keras till now.</p>
Is Keras thread safe?
<p>I'm using Python and Keras (currently using Theano backend, but I have no qualms with switching). I have a neural network that I load and process multiple sources of information with in parallel. Currently, I've been running each one in a separate process and it loads its own copy of the network from the file. This seems like a waste of RAM, so I was thinking it would be more efficient to have a single multi-threaded process with one instance of the network that is used by all threads. However, I'm wondering if Keras is thread safe with either backend. If I run <code>.predict(x)</code> on two different inputs at the same time in different threads, will I run into race conditions or other issues?</p>

<p>Thanks</p>