tf.decode_csv 持续时间过长

tf.decode_csv lasts too long

我正在使用 TensorFlow v0.8,奇怪的是打印第二个需要大约 5 分钟 print time.time()。我以为 tf.decode_csv() 只是简单地向图中添加一个操作而不进行任何计算。

为什么调用tf.decode_csv()需要这么长时间?

def main(argv=None): 
  # deal with arguments
  with tf.device("/cpu:0"):
    filename_queue = tf.train.string_input_producer(tf.train.match_filenames_once(train_set_filename + "*"))

    reader = tf.TextLineReader()
    _, line = reader.read(filename_queue)

    default = [[-1.0] for x in range(image_size * image_size * channels + 1)]
    print time.time()
    line = tf.decode_csv(line, record_defaults=default)
    print time.time()
    label = line[0]
    feature = tf.pack(list(line[1:]))

    ...

tf.decode_csv(line, record_defaults=default) 需要很多时间,因为您使用了太多的列。
我不知道您的 image_size,但如果它在 200 左右,您正试图将 120,001 列设置为您的 csv,这非常庞大。你是对的,TensorFlow 没有做任何计算,但它必须正确地构建图形并且有那么多列需要很多时间!

强烈建议您不要对图像使用 csv 格式。相反,您应该以 JPEG 格式存储图像,并使用 tf.image.decode_jpeg().