首页 > 解决方案 > 在 tensorflow 中读取 LZO 压缩的 csv 文件

问题描述

我有一组以 LZO 格式压缩的 csv 文件,我想将它们导入 TensorFlow。但是,如果我尝试像读取未压缩文件一样读取它,即使用

def parse_csv(line):
    columns = tf.decode_csv(line, record_defaults=DEFAULTS, field_delim="\t", use_quote_delim=False)  # take a line at a time
    features = dict(zip(COLUMNS, columns))  # create a dictionary out of the features
    labels = tf.to_int32(features.pop('label'))  # define the label as an integer
    return features, labels

data_files = glob.glob("my/folder/*")
dataset = tf.data.TextLineDataset(data_files)
dataset = dataset.map(parse_csv)

之前已经定义了 DEFAULTS 和 COLUMNS 的地方,我得到了错误

tensorflow.python.framework.errors_impl.InvalidArgumentError: Expect 20 fields but have 1 in record 0

为了规避它,我尝试定义 atf.WholeFileReader和使用该tf.read_file函数,然后将它们的输出传递给包中​​的decompress函数python-lzo,但无济于事。我怀疑那里有很多错误:至少一个在我使用该read_file函数的方式上,因为我不确定我是否能很好地导航 TF 数据结构,还有一个在decompress,因为我并不真正掌握 LZO 的工作原理。

data_files = glob.glob("my/folder/*")
file_queue = tf.train.string_input_producer(data_files)
value = tf.read_file(file_queue.dequeue())
value = tf.map_fn(lzo.decompress, value)
dataset = tf.map_fn(parse_csv, value)

我收到以下错误:

tensorflow.python.framework.errors_impl.InvalidArgumentError: slice index 0 of dimension 0 out of bounds. for 'map/strided_slice' (op: 'StridedSlice') with input shapes: [0], [1], [1], [1] and with computed input tensors: input[1] = <0>, input[2] = <1>, input[3] = <1>.

你能指出我出了什么问题,我该如何解决?

标签: pythontensorflowlzo

解决方案


推荐阅读