【TensorFlow6】输入输出
🗓 2019年05月29日 📁 文章归类: TensorFlow 📝 Edit
版权声明:本文作者是郭飞。转载随意,标明原文链接即可。
原文链接: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()
您的支持将鼓励我继续创作!
