2017-02-20 93 views
5

你能提供使用高层次的API估计有占位符和喂养像批次的基本使用的例子:Tensorflow,饲养Estimator.fit(批)

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) 

如何做估计相同API? Estimator将batch_size,steps,input_fuc或feed_fun作为拟合函数的参数(请参阅文档https://www.tensorflow.org/versions/master/api_docs/python/contrib.learn/estimators),但我不清楚如何实现一个函数,该函数将从一个批处理中加载数据。磁盘?

回答

0

我不认为估计值是否真的用于占位符。他们使用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)