美文网首页我爱编程
简单理解TensorFlow textlinereader的例子

简单理解TensorFlow textlinereader的例子

作者: MiracleJQ | 来源:发表于2018-03-13 10:29 被阅读0次

import tensorflow as tfimport numpy as npdefmain(): filename_queue = tf.train.string_input_producer(["test.txt", "test2.txt"], num_epochs=1)

    reader = tf.TextLineReader()

    key, value = reader.read(filename_queue)

    with tf.Session() as sess:

        sess.run(tf.initialize_local_variables())

        tf.train.start_queue_runners()

        num_examples = 0        try:

            while True:

                s_key, s_value = sess.run([key, value])

                print( s_key, s_value)

            num_examples += 1        except tf.errors.OutOfRangeError:

            print ("There are", num_examples, "examples")if __name__ == "__main__":

    main()

test.txt test2.txt内容随意。 

其结果会输出test2.txt test.txt的内容(test2.txt的内容先输出)

核心是先建立TextlineReader() 然后reader.read(其参数为queue或tensor) 用string_input_producer来生成queue即可。

原文参考:http://blog.csdn.net/transmaple/article/details/77919313

相关文章

网友评论

    本文标题:简单理解TensorFlow textlinereader的例子

    本文链接:https://www.haomeiwen.com/subject/odnafftx.html