Display images with Tensorboard
First, download a picture in png format (note: only support png format), named 1.png. Then, open PythonShell and enter the following code:
Import tensorflow TF AS
# acquires image data
# Picture
# added to the log
# Run and write to the log
# close
import tensorflow as tf
# 获取图片数据
file = open('1.png', 'rb')
data = file.read()
file.close()
# 图片处理
image = tf.image.decode_png(data, channels=4)
image = tf.expand_dims(image, 0)
# 添加到日志中
sess = tf.Session()
writer = tf.summary.FileWriter('logs')
summary_op = tf.summary.image("image1", image)
# 运行并写入日志
summary = sess.run(summary_op)
writer.add_summary(summary)
# 关闭
writer.close()
sess.close()
# 获取图片数据
file = open('1.png', 'rb')
data = file.read()
file.close()
# 图片处理
image = tf.image.decode_png(data, channels=4)
image = tf.expand_dims(image, 0)
# 添加到日志中
sess = tf.Session()
writer = tf.summary.FileWriter('logs')
summary_op = tf.summary.image("image1", image)
# 运行并写入日志
summary = sess.run(summary_op)
writer.add_summary(summary)
# 关闭
writer.close()
sess.close()
0 comments:
Post a Comment