您的位置:首页 > 其它

简单理解TensorFlow textlinereader的例子

2017-09-10 00:19 986 查看
import tensorflow as tf
import numpy as np

def main():
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即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: