Keras: Running Keras model for prediction in multiple threads

Created on 2 Apr 2017  路  2Comments  路  Source: keras-team/keras

I posted my problem on Stackoverflow: Running Keras model for prediction in multiple threads but got no answer. So I come here for help.

I tried copying over the weights, but didn't solve the problem:

        for roundNo in xrange(self.param['max_round']):
            for agent in self.AgentPool:                               # self.AgentPool: type - list of AgentThread
                agent.syncModel(self.getEnv(), self.actor, self.critic, eps)
                agent.start()
            for agent in self.AgentPool:
                agent.join()
class AgentThread:
    def syncModel(self, env_, actor_, critic_, eps_):
        """synchronize A-C models before collecting data"""
        # TODO copy env, actor, critic
        self.env = env_     # shallow copy
        self.actor.model.set_weights(actor_.model.get_weights())        # deep copy, by weights
        self.critic.model.set_weights(critic_.model.get_weights())      # deep copy, by weights
        self.eps = eps_     # shallow copy
        self.data = {}

I guess there is something wrong about the tensorflow session, but can't figure out a solution.

Most helpful comment

This fixed the problem to me, after loading the model and BEFORE any prediction invoke:
d_model._make_predict_function()
Hope it works for you

All 2 comments

For further information, see this issue on jaara/AI-blog and this issue on Keras

This fixed the problem to me, after loading the model and BEFORE any prediction invoke:
d_model._make_predict_function()
Hope it works for you

Was this page helpful?
0 / 5 - 0 ratings