【问题标题】:How to test dataset iterators within jupyter notebook如何在 jupyter notebook 中测试数据集迭代器
【发布时间】:2018-02-14 00:58:24
【问题描述】:

我想尝试使用不同的函数来解析我的 csv,并且我正在尝试使用 tf.dataset 迭代器,但我无法让它工作。我使用下面的代码的目标是打印第一个解析的行。

import tensorflow as tf
filenames = 'my_dataset.csv'
dataset = tf.data.TextLineDataset(filenames).skip(1).map(lambda row: parse_csv(row, hparams))
    iterator = dataset.make_one_shot_iterator()
    next_row = iterator.get_next()

with tf.Session() as sess:
    #sess.run(iterator.initializer)
    while True:
        try:
            print(sess.run(next_x))
        except tf.errors.OutOfRangeError:
            break

现在如果我运行它,你会看到我得到FailedPreconditionError (see above for traceback): GetNext() failed because the iterator has not been initialized. Ensure that you have run the initializer operation for this iterator before getting the next element.,然后我继续取消注释iterator.initializer,我得到另一个错误ValueError: Iterator does not have an initializer.

需要进行哪些更改才能真正逐步查看我的 parse_csv 调用发生了什么?

【问题讨论】:

    标签: python tensorflow tensorflow-datasets


    【解决方案1】:

    您运行 sess.run(next_x) 而不是 sess.run(next_row)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-14
      • 1970-01-01
      • 2017-05-09
      • 2017-04-11
      • 1970-01-01
      • 1970-01-01
      • 2021-05-14
      • 2017-06-06
      相关资源
      最近更新 更多