1. 程式人生 > >開啟程序讀

開啟程序讀

import tensorflow as tf
import cifar10.cifar10_input

path = 'beauty/'
filename = ['a.jpg', 'b.jpg', 'c.jpg']
filename = [path+x for x in filename]
print(filename)

#  雙執行緒,一個從檔案中讀到記憶體,一個負責執行
with tf.Session() as sess:
    filename_queue = tf.train.string_input_producer(filename, shuffle=False, num_epochs=5)
    #  To use, enqueue filenames in a Queue.  The output of Read will
    #  be a filename (key) and the contents of that file (value).
    reader = tf.WholeFileReader()
    key, value = reader.read(filename_queue)
    tf.local_variables_initializer().run()
    threads = tf.train.start_queue_runners(sess)
    i = 0
    while True:
        i += 1
        image_data = sess.run(value)
        with open('Outs/test_%d.jpg' % i, 'wb') as f:
            f.write(image_data)