tf.gfile.FastGFile

4564 ワード

tf.gfile.FastGFile(path,decodestyle)関数機能:画像の読み取りを実現します.関数パラメータ:(1)path:ピクチャが存在するパス(2)decodestyle:ピクチャの復号方式.(‘r’:UTF-8符号化;‘rb’:非UTF-8符号化)
import matplotlib.pyplot as plt 
import tensorflow as tf 

#tf.gfileGFile() :   
image_jpg = tf.gfile.FastGFile('dog.jpg','rb').read()  
image_png = tf.gfile.FastGFile('lizard.png','rb').read()  

with tf.Session() as sess:  

    image_jpg = tf.image.decode_jpeg(image_jpg) # 
    print(sess.run(image_jpg))# ( [w,h,3])
    image_jpg = tf.image.convert_image_dtype(image_jpg,dtype=tf.uint8) #   

    image_png = tf.image.decode_png(image_png) 
    print(sess.run(image_jpg))
    image_png = tf.image.convert_image_dtype(image_png,dtype=tf.uint8)  

    plt.figure(1) #   
    plt.imshow(image_jpg.eval())  
    plt.figure(2)  
    plt.imshow(image_png.eval())