【发布时间】:2018-06-01 19:02:09
【问题描述】:
我正在尝试在单个 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() 行,所以即使我尝试在每个可能的位置设置会话图,我也一定做错了什么?
有人有类似的经历吗?
【问题讨论】:
-
尝试在其进程中声明每个模型及其会话。
-
delaring 是指创建一个全新的模型,然后将权重加载到其中?
-
是的!您的问题可能来自在不同进程中创建的新会话/图表,并且没有在外部声明原始节点。
标签: python tensorflow multiprocessing keras