p7:TensorBoard的使用(一)
# p7:TensorBoard的使用(一)
from torch.utils.tensorboard import SummaryWriter
#1.创建日志文件
writer = SummaryWriter("logs0321")
# writer.add_image()
# y = x
for i in range(100):
# 2.writer.add_scalar("y=x(标题名)", 2*i(y轴)(scalar_value), i(x轴)(global_step))
writer.add_scalar("y=2x", 2 * i, i)
writer.close()
# 终端命令行:
# 1.tensorboard --logdir=logs --port=6007(自定义设置端口号)
# 2.writer.add_scalar("y=x(标题名)", 2*i(y轴), i(x轴))
p8:TensorBoard的使用(二)
# p8:TensorBoard的使用(二)
from torch.utils.tensorboard import SummaryWriter
from PIL import Image
import numpy as np
#1.创建tensorboard日志文件
writer = SummaryWriter("logs03072")
#2.赋值图片路径
image_path = "E:\\LTGKE\\zxworkspace\\xiaotudui\\data\\train\\bees_image\\150013791_969d9a968b.jpg"
#3.打开图片,将图片变量赋值给img_PIL(图片格式为PIL类型)
img_PIL = Image.open(image_path)
#4.将PIL图片格式转化为array格式,并赋值给image_array变量
image_array = np.array(img_PIL)
#5.输出图片类型
print(type(image_array))
#6.输出图片形状
print(image_array.shape)
#7."显示图像的窗口名","显示图片的名字","表示一张图片","数据格式为HWC格式"
writer.add_image("train02",image_array,2,dataformats='HWC')
for i in range(100):
writer.add_scalar("y=2x", 2 * i, i)
writer.close()
标签:PIL,22,记录,image,writer,scalar,2023.3,add,array From: https://www.cnblogs.com/zxpython/p/17247148.html