Python Tensorflow读取选项卡分隔的文件

Python Tensorflow读取选项卡分隔的文件,python,tensorflow,Python,Tensorflow,我正在尝试将一个选项卡分隔的文件读入tensorflow # Metadata describing the text columns COLUMNS = ['queue_name','block_name', 'car_name', 'position_id', 'x_ord', 'y_ord'] FIELD_DEFAULTS = [[''], [''], [''], [0], [0], [0]] def _parse_line(line):

我正在尝试将一个选项卡分隔的文件读入tensorflow

# Metadata describing the text columns
COLUMNS = ['queue_name','block_name', 'car_name',
           'position_id', 'x_ord',
           'y_ord']
FIELD_DEFAULTS = [[''], [''], [''], [0], [0], [0]]
def _parse_line(line):
    # Decode the line into its fields
    fields = tf.decode_csv(line, FIELD_DEFAULTS, field_delim="\t")

    # Pack the result into a dictionary
    features = dict(zip(COLUMNS,fields))

    # Separate the label from the features
    y = features.pop('y_ord')
    x = features.pop('x_ord')

    return features, x, y


ds = tf.data.TextLineDataset(filenames).skip(1)
ds = ds.map(_parse_line)
with tf.Session() as sess:
print(sess.run(ds)) # I am getting an error when running the session
然而,这给了我一个错误

TypeError:Fetch参数的类型无效,必须是字符串或张量。(无法将MapDataset转换为张量或操作。)


这是否意味着我无法在地图数据集中组合字符串和整数,或者我做错了什么?

错误的原因是因为您试图运行的不是张量或操作,而是数据集对象。可以从Dataset对象创建一个张量,这样每次运行它时,都可以从Dataset中获得下一个样本

请尝试以下操作:

value = ds.make_one_shot_iterator().get_next()
print(sess.run(value)) # First value in your dataset
print(sess.run(value)) # Second value in your dataset
从这里开始构建,您可以从这个张量构建模型的其余部分


请参阅

中的文档,您在哪一行获得错误?我在图表上运行会话时遇到错误,我不知道如何检查我的数据是否被正确读取,并且文档中没有详细说明示例页面需要有人澄清语义并添加此语句也许-我很高兴你已经弄明白了:)