广义Tensorflow CSV加载

时间:2017-02-28 21:16:28

标签: python csv tensorflow

我正在尝试将大型CSV文件加载到TensorFlow管道中,其中每行代表一个展平的256 * 256图像。我试图概括TensorFlow CSV文件读取示例,但是我无法将decode_csv函数概括为使我的所有列都适应:

$adphone = (Get-ADUser -Filter "Name -eq '$fullname'" -Properties MobilePhone).MobilePhone

但是我收到了错误

def file_len(fname):
    with open(fname) as f:
        for i, l in enumerate(f):
            pass
    return i + 1

# setup text reader
file_length = file_len(filename)
filename_queue = tf.train.string_input_producer([filename])
reader = tf.TextLineReader(skip_header_lines=1)
_, csv_row = reader.read(filename_queue)

# setup CSV decoding
record_defaults = [[0] for i in range(256*256)]
col = tf.decode_csv(csv_row, record_defaults=record_defaults)

features = tf.pack([col[i] for i in range(256*256))

print("loading, " + str(file_length) + " line(s)\n")
with tf.Session() as sess:
  tf.initialize_all_variables().run()

  # start populating filename queue
  coord = tf.train.Coordinator()
  threads = tf.train.start_queue_runners(coord=coord)

  for i in range(file_length):
    # retrieve a single instance
    example, label = sess.run([features, col5])
    print(example, label)

  coord.request_stop()
  coord.join(threads)
  print("\ndone loading")

如何概括col1,... colN部分?

1 个答案:

答案 0 :(得分:0)

我的愚蠢错误。 tf.pack可以采用list参数,因此不需要将tf.decode_csv的输出分成不同的cols。它可以简单地用

完成
col = tf.decode_csv(csv_row, record_defaults=record_defaults)
features = tf.pack(col)