如何在Jupyter笔记本中测试数据集迭代器



我想尝试使用不同的功能来解析我的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调用发生了什么?

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

最新更新