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。但我不太確定。我會很高興每一個簡短的想法,因爲我現在坐在這上太久了。
感謝