我试图在一个GPU上并行安装多个小型Keras型号 . 由于我需要将它们从列表中删除并一次训练它们的原因 . 由于我不熟悉标准的多处理模块,我使用了pathos .
我试图做的是这样的:
from pathos.multiprocessing import ProcessPool as Pool
import tensorflow as tf
import keras.backend as K
def multiprocess_step(self, model):
K.set_session(sess)
with sess.graph.as_default():
model = step(model, sess)
return model
def step(model, sess):
K.set_session(sess)
with sess.graph.as_default():
model.fit(x=data['X_train'], y=data['y_train'],
batch_size=batch_size
validation_data=(data['X_test'], data['y_test']),
verbose=verbose,
shuffle=True,
initial_epoch=self.step_num - 1)
return model
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
config.gpu_options.visible_device_list = "0"
sess = tf.Session(config=config)
K.set_session(sess)
with sess.graph.as_default():
pool = Pool(8).map
model_list = pool(multiprocess_step, model_list)
但无论我尝试什么,我都会收到一个错误声称模型似乎不在同一个图表上......
ValueError: Tensor("training/RMSprop/Variable:0", shape=(25, 352), dtype=float32_ref) must be from the same graph as Tensor("RMSprop/rho/read:0", shape=(), dtype=float32).
异常起源于model.fit()行,所以即使我试图在每个可能的位置设置它,我必须对会话图的分配做错了吗?
有没有人有类似的经历?