【发布时间】: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