【问题标题】:Tensorflow, feeding Estimator.fit(batch)Tensorflow,喂 Estimator.fit(batch)
【发布时间】:2017-07-10 03:44:42
【问题描述】:

您能否提供一个使用高级 API 估算器与占位符和喂料批次的示例,例如用于基本用途:

for step in xrange(max_steps):
    batch_of_inputs,batch_of_targets= get_batch_from_disk(step)# e.g.batches are stored as list where step is and index of the list
    feed_dict = {x:batch_of_inputs,y:batch_of_targets}
    _, loss_value = sess.run([train_op, loss],
                         feed_dict=feed_dict)

如何使用 Estimator API 做同样的事情? Estimator 将 batch_size、steps、input_fuc 或 feed_fun 作为 fit 函数的参数(参见 doc https://www.tensorflow.org/versions/master/api_docs/python/contrib.learn/estimators),但我不清楚如何实现一个函数,该函数将从例如批量加载数据磁盘?

【问题讨论】:

    标签: python tensorflow neural-network


    【解决方案1】:

    我不认为估算器是否真的要与占位符一起使用。他们使用input_fn 的概念,正确描述here

    如果你真的需要使用占位符,你可以使用FeedFnHook

    def input_fn():  # empty input_fn, returns features and labels
        return {}, {}
    
    feed_dict = {x:batch_of_inputs,y:batch_of_targets}
    def feed_fn():  # feed_fn with hardcoded feed_dict
        return feed_dict
    
    hooks = [tf.train.FeedFnHook(feed_fn=feed_fn)]
    estimator.train(input_fn=input_fn, hooks=hooks, steps=1)
    

    【讨论】:

      猜你喜欢
      • 2023-03-23
      • 2017-04-18
      • 2017-03-21
      • 1970-01-01
      • 2016-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多