keras - 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)
解决方案
推荐阅读
- vb.net - 为什么这些陈述会产生相反的结果?
- c# - C# ListBox,显示多列
- opengl - openGL - 使用不同的着色器渲染多个对象
- python - 无法在 Main() 中调用函数
- css - 尝试添加文本时 CSS 功能“内容”不起作用
- python-requests - 如何在请求(或 urllib3.response)中获取完整的服务器响应消息?
- spring - 文件编码中面临的问题 - 使用文件到字符串转换器的 UTF-8/16
- php - 将“全选”添加到过滤器
- java - SpringBoot:绕过 OncePerRequestFilter 过滤器
- python - Python 子进程打开我的 Pycharm 文件夹和 Jupyter 文件夹而不是目标