1
【TensorFlow6】输入输出
source link: https://www.guofei.site/2019/05/29/tf7.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
【TensorFlow6】输入输出
2019年05月29日Author: Guofei
文章归类: 2-3-神经网络与TF ,文章编号: 286
版权声明:本文作者是郭飞。转载随意,但需要标明原文链接,并通知本人
原文链接:https://www.guofei.site/2019/05/29/tf7.html
图像
import tensorflow as tf
## 读入
image_raw_data = tf.gfile.FastGFile("F:/datasets/cup.jpg", 'rb').read()
img_data = tf.image.decode_jpeg(image_raw_data) # unit8格式
resized = tf.image.resize_images(img_data, [300, 300], method=0) # float32 格式
显示与读出
sess = tf.Session()
import matplotlib.pyplot as plt
plt.imshow(sess.run(resized/255)) # 因为是float格式,所以显示时应当在0~1之间
plt.show()
# 写出
retype = tf.cast(resized, tf.uint8)
encoder_image = tf.image.encode_png(retype)
with tf.gfile.GFile("F:/output.png", 'wb') as f:
f.write(sess.run(encoder_image))
sess.close()
您的支持将鼓励我继续创作!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK