【发布时间】:2017-05-15 13:52:11
【问题描述】:
[简短总结:如何通过外部文件阅读器在 Python 上使用 TF 高级 Estimator?还是使用 feed_dict?]
为此苦苦挣扎了几天,在网上找不到任何解决方案...
我正在使用 TF 高级模块(tf1.0 上的 tf.contrib.learn.Estimator 或 tf1.1 上的 tf.estimator.Estimator), 通过 input_fn 输入的特征和目标 (x/y),以及基于 model_fn 构建的图。
已经使用 slice_input_producer 等在“小型”数据集上训练了一个神经网络,其中整个输入是图形的一部分。(如果它在这里为 ppl 服务,我可以将一个示例推送到 github)。
我尝试在“较重”数据集(10s-100s GB)上训练更大的 nn。 我有一个外部 Python 阅读器,它读取一些讨厌的二进制文件,我真的不想进入。 这个阅读器有自己的 queue.Queue 和 m1 个样本。当我使用它来提取 m1 {features} 和 {targets} 时,网络只是将所有这些样本保存为 const。在图表的第一层......完全不受欢迎。
我尝试要么 -
- 将外部文件阅读器的输出作为输入提供给我的图表。
- 定义一个适当的 tf 队列对象,该对象将不断更新队列(每次一个样本出队时,我都希望另一个样本完全入队)。
提醒我使用“高级”,例如
self.Estimator = tf.contrib.learn.Estimator(
model_fn=self.model_fn,
model_dir=self.config['model_dir'],
config=tf.contrib.learn.RunConfig( ... ) )
def input_fn(self, mode):
batch_data = self.data[mode].next() # pops out a batch of samples, as numpy 4D matrices
... # some processing of batch data
features_dict = dict(data=batch_data.pop('data'))
targets_dict = batch_data
return features_dict, targets_dict
self.Estimator.fit(input_fn=lambda: self.input_fn(modekeys.TRAIN))
【问题讨论】:
-
我在下午收到以下提示,但无法解决,也许我错过了一些必需的 Python 技能;建议? 你必须自己做——使用 py_func 来封装你的 python 阅读器,并查看tensorflow.org/programmers_guide/reading_data 了解更多详细信息。 input_fn 简单必须返回两个字典:一个带有特征张量,一个带有标签。 contrib 中有很多工具可以让这更容易,特别是在 tf.contrib.training 和 tf.contrib.learn.FeatureColumn 中。
标签: python-2.7 tensorflow