首页 > 解决方案 > K.function的第三个参数,更新需要有新旧权重对以外的操作吗?

问题描述

我一直在构建 DDPG 代理,它是强化学习算法。无论如何,我发现了一些我可以参考的来源。那些似乎工作。但是,我对在 keras 中使用 K.function() 感到困惑。在下面,函数“get_soft_target_model_updates”返回(旧权重,新权重),这与 keras 官方文档中写道的“更新:更新操作列表”不同。所以,我认为它需要返回 K.update(old tensor, new tensor)。

def get_soft_target_model_updates(target, source, tau):
    target_weights = target.trainable_weights + sum([l.non_trainable_weights for l in target.layers], [])
    source_weights = source.trainable_weights + sum([l.non_trainable_weights for l in source.layers], [])
    assert len(target_weights) == len(source_weights)

    updates = []
    for tw, sw in zip(target_weights, source_weights):
        updates.append((tw, tau * sw + (1. - tau) * tw))
    return updates


    if self.tau_for_actor < 1:
        updates += get_soft_target_model_updates(self.target_actor, self.actor, self.tau_for_actor)

    updates += self.actor.updates

    self.actor_train_fn = K.function(state_inputs + [K.learning_phase()], [self.actor(state_inputs)], updates=updates)

标签: keras

解决方案


推荐阅读