python - 在 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>.
你能指出我出了什么问题,我该如何解决?
解决方案
推荐阅读
- git - 命令提示符中的奇怪错误,尝试使用 PIP 安装包
- ruby - 使用“bundle gem help”创建 ruby gem 后没有测试目录
- sql - 将标识列添加到雪花中的现有表?
- mysql - MySQL SELECT Query 假设 1623x=1623 为 True
- mysql - 使用 PHP 加入 MYSQL
- java - 使用 Zuul 网关过滤入站请求
- javascript - 如何选择获取请求中收到的所有数据并检查每个项目
- ruby-on-rails - Ruby 唯一的用户名生成器
- docker-compose - 如何在 gitlab 上测试在 docker-compose 中运行的容器
- python - 在 Matplotlib 中绘图不覆盖 y 轴