代码如下:
# -*- coding: utf-8 -*-
"""
Created on
@author: ASUS
"""
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
#获取图片数据
file = open('C:\\Users\\ASUS\\Desktop\\QQ截图20230927153842.png','rb')
data = file.read()
file.close()
#图片处理
image = tf.image.decode_png(data,channels = 4)
image = tf.expand_dims(image,0)
#初始化所有变量
init = tf.global_variables_initializer()
#定义日志保存路径
savedir = './imagessummary_log'
with tf.Session() as sess:
sess.run(init)
#创建summary
summary_op = tf.summary.image("image1",image)
#创建summary_writer,用于写文件
summary_writer = tf.summary.FileWriter(savedir,sess.graph)
#生成summary
summary_str = sess.run(summary_op)
#将summary写入文件
summary_writer.add_summary(summary_str)
运行后,
win+R打开终端,输入tensorboard --logdir C:\Users\ASUS\.spyder-py3\log4\imagessummary_log
复制其中的http://localhost:6006/,打开浏览器跳转来到tensorboard可视化界面,如下: