我想尝试使用不同的函数来解析我的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调用发生了什么?
答案 0 :(得分:0)
您运行sess.run(next_x)
而不是sess.run(next_row)
。