性能:tf.read_file(filename)与tf.WholeFileReader()

时间:2017-01-16 18:47:21

标签: tensorflow

tf.read_file(filename)tf.WholeFileReader()之间的性能(预取意义)是否存在差异?

例如,这两个代码示例之间的性能是否存在差异:

def example_read_file():
    filename_list = tf.convert_to_tensor([["file1_1", "file1_2", "file1_3"], ["file2_1", "file2_2", "file2_3"]])
    filename_queue = tf.train.slice_input_producer(filename_list)

    f0 = tf.read_file(filename_queue[0])
    f1 = tf.read_file(filename_queue[1])
    f2 = tf.read_file(filename_queue[2])

    loss = calculate_loss(f0, f1, f2)
    with tf.Session() as sess:
        coord = tf.train.Coordinator()
        threads = tf.train.start_queue_runners(coord=coord)

        for i in range(0, 10):
            print(sess.run([loss]))

        coord.request_stop()
        coord.join(threads)

def example_WholeFileReader():
    filename_list = tf.convert_to_tensor([["file1_1", "file1_2", "file1_3"], ["file2_1", "file2_2", "file2_3"]])
    fn0, fn1, fn2 = tf.split(1, 3, filename_list)

    # queues
    fq0 = tf.train.string_input_producer(tf.reshape(fn0, [-1]), shuffle=False)
    fq1 = tf.train.string_input_producer(tf.reshape(fn1, [-1]), shuffle=False)
    fq2 = tf.train.string_input_producer(tf.reshape(fn2, [-1]), shuffle=False)

    # read files
    r0 = tf.WholeFileReader()
    k0, v0 = r0.read(fq0)
    r1 = tf.WholeFileReader()
    k1, v1 = r1.read(fq1)
    r2 = tf.WholeFileReader()
    k2, v2 = r2.read(fq2)

    loss = calculate_loss(v0, v1, v2)
    with tf.Session() as sess:
        coord = tf.train.Coordinator()
        threads = tf.train.start_queue_runners(coord=coord)

        for i in range(0, 10):
            print(sess.run([loss]))

        coord.request_stop()
        coord.join(threads)

提前致谢!

0 个答案:

没有答案