TensorFlow文件操作
生活随笔
收集整理的這篇文章主要介紹了
TensorFlow文件操作
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
本文演示如何讀取文件,并輸出文件到另外的目錄。
# 導入TensorFlow import tensorflow as tffilename = ['A.png', 'B.png', 'C.png', 'D.png'] epoch = 2# string_input_producer會產生一個文件名隊列 filename_queue = tf.train.string_input_producer(filename, shuffle=False, num_epochs=epoch) # reader從文件名隊列中讀數據。 reader = tf.WholeFileReader() key, value = reader.read(filename_queue)# 新建一個Session with tf.Session() as sess:# tf.train.string_input_producer定義了一個epoch變量,要對它進行初始化tf.local_variables_initializer().run()# 使用start_queue_runners之后,才會開始填充隊列threads = tf.train.start_queue_runners(sess=sess)i = 0count = len(filename) * epochfor i in range(count):i += 1# 獲取圖片數據并保存image_data = sess.run(value)with open('read/test_%d.jpg' % i, 'wb') as f:f.write(image_data)總結
以上是生活随笔為你收集整理的TensorFlow文件操作的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 史上最复杂业务场景,逼出阿里高可用三大法
- 下一篇: Kaggle入门 (Titanic Te