5
我想用model.fit()在一个python应用程序中并行训练一些不同的模型。使用的模型没有必要的共同点,它们在不同的时间在一个应用程序中启动。张量多线程/ keras
首先,我在一个单独的线程中,然后在主线程中启动一个model.fit(),没有问题。如果我现在要开始第二model.fit(),我得到了以下错误消息:
start_learn(self:)
tf_session = K.get_session() # this creates a new session since one doesn't exist already.
tf_graph = tf.get_default_graph()
keras_learn_thread.Learn(learning_data, model, self.env_cont, tf_session, tf_graph)
learning_results.start()
:
Exception in thread Thread-1:
tensorflow.python.framework.errors_impl.InvalidArgumentError: Node 'hidden_1/BiasAdd': Unknown input node 'hidden_1/MatMul'
他们都充分利用的方法通过相同的代码行启动钍叫做类/方法是这样的:
def run(self):
tf_session = self.tf_session # take that from __init__()
tf_graph = self.tf_graph # take that from __init__()
with tf_session.as_default():
with tf_graph.as_default():
self.learn(self.learning_data, self.model, self.env_cont)
# now my learn method where model.fit() is located is being started
我想我无论如何都必须指定一个新tf_session并为每个单个线程新tf_graph。但我不太确定。我会很高兴每一个简短的想法,因为我现在坐在这上太久了。
感谢