【问题标题】:tensorflow - implementing experience replay memory with the estimator apitensorflow - 使用 estimator api 实现体验回放记忆
【发布时间】:2018-11-20 23:47:30
【问题描述】:

我尝试使用tf.estimator.Estimator API 实现experience replay memory。但是,我不确定获得至少适用于所有模式的结果的最佳方法是什么(TRAINEVALUATEPREDICT)。我尝试了以下方法:

  • 使用tf.Variable 实现内存,这会导致批处理和输入管道出现问题(我无法在测试或预测阶段输入自定义体验)

目前正在尝试:

  • tf.Graph 之外实现内存。每次运行后使用tf.train.SessionRunHook 设置值。在训练和测试期间使用tf.data.Dataset.from_generator() 加载体验。自行管理状态。

我在几个方面都失败了,并开始相信 tf.estimator.Estimator API 没有为我提供轻松写下所需的接口。

一些代码(第一种方法,batch_size 失败,因为它是固定用于 exp 的切片,我不能使用模型进行预测或评估):

 def model_fn(self, features, labels, mode, params):
    batch_size = features["matrix"].get_shape()[0].value

    # get prev_exp
    if mode == tf.estimator.ModeKeys.TRAIN:
        erm = tf.get_variable("erm", shape=[30000, 10], initializer=tf.constant_initializer(self.erm.initial_train_erm()), trainable=False)
        prev_exp = tf.slice(erm, [features["index"][0], 0], [batch_size, 10])

    # model
    pred = model(features["matrix"], prev_exp, params) 

但是:最好将 erm 放在功能字典中。但随后我必须管理图表之外的 erm,并写回我对 SessionRunHook 的最新体验。有没有更好的方法或者我错过了什么?

【问题讨论】:

    标签: python tensorflow deep-learning reinforcement-learning tensorflow-estimator


    【解决方案1】:

    我通过在图表外实现 ERM 解决了我的问题,使用 tf.data.Dataset.from_generator() 将其反馈到输入管道中,并使用 SessionRunHooks 回写。是的,相当乏味,但它正在工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多