我正在尝试在 Keras 和 TensorFlow 中实现 actor-critic 的异步版本。我使用 Keras 作为构建网络层的前端(我直接使用张量流更新参数)。我有一个global_model
和一个主要的张量流会话。但在每个线程内我正在创建一个local_model
它从复制参数global_model
。我的代码看起来像这样
def main(args):
config=tf.ConfigProto(log_device_placement=False,allow_soft_placement=True)
sess = tf.Session(config=config)
K.set_session(sess) # K is keras backend
global_model = ConvNetA3C(84,84,4,num_actions=3)
threads = [threading.Thread(target=a3c_thread, args=(i, sess, global_model)) for i in range(NUM_THREADS)]
for t in threads:
t.start()
def a3c_thread(i, sess, global_model):
K.set_session(sess) # registering a session for each thread (don't know if it matters)
local_model = ConvNetA3C(84,84,4,num_actions=3)
sync = local_model.get_from(global_model) # I get the error here
#in the get_from function I do tf.assign(dest.params[i], src.params[i])
我收到来自 Keras 的用户警告
用户警告:默认的 TensorFlow 图不是关联的图
当前已在 Keras 中注册的 TensorFlow 会话,以及
这样 Keras 无法自动初始化变量。你
应该考虑通过 Keras 注册正确的会话K.set_session(sess)
随后出现张量流错误tf.assign
操作表示操作必须在同一个图上。
值错误:张量(“conv1_W:0”,形状=(8,8,4,16),
dtype=float32_ref, device=/device:CPU:0) 必须来自同一个图表
作为张量(“conv1_W:0”,形状=(8,8,4,16),dtype=float32_ref)
我不太确定出了什么问题。
Thanks