tf読取画像、起動図の3つの方式


一つ目は、画像を直接読み込んで、画像の元のデータを取得し、復号することです.
import tensorflow as tf;    

image_raw_data = tf.gfile.FastGFile('/home/penglu/Desktop/11.jpg').read()  
image = tf.image.decode_jpeg(image_raw_data) #      

print image.eval(session=tf.Session())

2つ目の方法は、画像を1つのファイルに見て、キューで読み取ることです.
import tensorflow as tf;    

path = '/home/penglu/Desktop/11.jpg'  
file_queue = tf.train.string_input_producer([path]) #        
image_reader = tf.WholeFileReader()  
_, image = image_reader.read(file_queue)  
image = tf.image.decode_jpeg(image)  

with tf.Session() as sess:  
    coord = tf.train.Coordinator() #         
    threads = tf.train.start_queue_runners(sess=sess, coord=coord) #          
    print sess.run(image)  
    coord.request_stop() #         
    coord.join(threads)  
sess = tf.Session()
sess.run(init)
with tf.Session() as sess:  
    sess.run(tf.global_variables_initializer())  
    print sess.run(op)
sess_ = tf.InteractiveSession()  
tf.global_variables_initializer().run()  
print op.eval()  
sess_.close()  

tf.train.Supervisor().managed_セッション()は、上記の2つの起動図と比較すると、Supervisor()は、checkpointに自動的にデータをロードするか、初期化データ(b)に自動的にSaverがあり、checkpoint eg:svを保存するのに使用できることを処理するのに役立ちます.saver.save(sess,save_path)(c)summary_computedはSummaryを保存するために使用されるので、(a)手動初期化またはcheckpointからデータをロード(b)Saverクラスを作成する必要はなく、sv内部を使用すれば(c)Summary_を作成する必要はありません.Writer()
sv = tf.train.Supervisor(logdir=None, init_op=tf.global_variables_initializer())  
with sv.managed_session() as sess:  
    print sess.run(preduct) 
#coding:utf-8  

import tensorflow as tf  

a = tf.Variable(1)  
b = tf.Variable(2)  
c = tf.add(a, b)  

update = tf.assign(a, c)  

init = tf.global_variables_initializer()  

sv = tf.train.Supervisor(logdir="./tmp/", init_op=init)  
saver = sv.saver  
with sv.managed_session() as sess:  
    for i in range(1000):  
        update_ = sess.run(update)  
        #print("11111", update)  

        if i % 100 == 0:  
            sv.saver.save(sess, "./tmp/", global_step=i)  
input1 = tf.placeholder(tf.float32)
input2 = tf.placeholder(tf.float32)
output = tf.mul(input1, input2)

with tf.Session() as sess:
  print sess.run([output], feed_dict={input1:[7.], input2:[2.]})