【问题标题】:Tensorflow Estimator Predict for Deep Wide Model深度宽模型的 Tensorflow 估计器预测
【发布时间】:2017-12-05 07:02:56
【问题描述】:

有人可以给出一个关于如何在tf.estimator 上调用prediction 的明确示例吗?

有两件事我不清楚

  1. 当输入文件没有标签栏时,如何调整input_fn
  2. 如何导出预测结果

我正在研究 deep_wide 模型。

【问题讨论】:

  • 这个article 应该是一本好书。

标签: python tensorflow


【解决方案1】:

我会回答自己,希望这可以帮助有类似问题的人

对于问题 1,是的,我们需要构建一个新的输入函数,并且很可能它的列数与您的输入 csv 不同,因为我们正在删除标签列

def parse_csv(value):
    print('Parsing', data_file)
    columns = tf.decode_csv(value, record_defaults=_PREDICT_COLUMNS_DEFAULTS)
    features = dict(zip(_PREDICT_COLUMNS, columns))

    return features

def predict_input_fn(data_file):
    assert tf.gfile.Exists(data_file), ('%s not found. Please make sure the path is correct.' % data_file)

    dataset = tf.data.TextLineDataset(data_file)
    dataset = dataset.map(parse_csv, num_parallel_calls=5)
    dataset = dataset.batch(1) # this is very important to keep the rank right
    iterator = dataset.make_one_shot_iterator()
    features = iterator.get_next()
    return features

那么对于问题2,你使用新的input_fn来预测结果

def predict(model):
    start_from_id = 892
    test_csv = []

    results = model.predict(
        input_fn=lambda: predict_input_fn(data_file='test.csv')
    )

    # for result in results:
    #     print 'result: {}'.format(result)

【讨论】:

    猜你喜欢
    • 2018-09-15
    • 2020-11-04
    • 2019-04-04
    • 2017-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-17
    • 2020-10-21
    相关资源
    最近更新 更多