「深度学习一遍过」必修16:Tensorboard与Transforms
Posted 荣仔!最靓的仔!
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了「深度学习一遍过」必修16:Tensorboard与Transforms相关的知识,希望对你有一定的参考价值。
本专栏用于记录关于深度学习的笔记,不光方便自己复习与查阅,同时也希望能给您解决一些关于深度学习的相关问题,并提供一些微不足道的人工神经网络模型设计思路。
专栏地址:「深度学习一遍过」必修篇
目录
1 Tensorboard
1.1 初始化
终端键入
tensorboard --logdir=*** --port=****
- 事件文件所在文件夹名
- 路径后缀数字名(可自定义)
1.2 使用实例
1.2.1 画一条直线
from tensorboardX import SummaryWriter
writer = SummaryWriter('logs')
for i in range(100):
writer.add_scalar('y=x', i, i)
writer.close()
tensorboard --logdir=logs --port=6007
1.2.2 查看一张图片
import numpy as np
from PIL import Image
from tensorboardX import SummaryWriter
writer = SummaryWriter('logs')
img_path = r'H:\\girl.jpeg'
img_PIL = Image.open(img_path)
img_array = np.array(img_PIL)
print(type(img_array))
print(img_array.shape)
writer.add_image('test', img_array, 1, dataformats='HWC')
writer.close()
1.2.3 滑动查看多张图片
在 基础上再在 上运行下列代码:
import numpy as np
from PIL import Image
from tensorboardX import SummaryWriter
writer = SummaryWriter('logs')
img_path = r'H:girlfriend.jpg'
img_PIL = Image.open(img_path)
img_array = np.array(img_PIL)
print(type(img_array))
print(img_array.shape)
writer.add_image('test', img_array, 1, dataformats='HWC')
writer.close()
2 Transforms
2.1 常见的Transforms
- 输入 --> -->
- 输出 --> -->
- 作用 --> -->
2.2 Transforms该如何使用
from PIL import Image
from torchvision import transforms
img_path = 'E:/img.PNG'
img = Image.open(img_path)
tensor_trans = transforms.ToTensor()
tensor_img = tensor_trans(img)
print(tensor_img)
from PIL import Image
from tensorboardX import SummaryWriter
from torchvision import transforms
writer = SummaryWriter('logs')
img_path = r'female.jpg'
img = Image.open(img_path)
print(img)
# ToTensor
trans_tensors = transforms.ToTensor()
img_tensor = trans_tensors(img)
writer.add_image('ToTensor', img_tensor)
# Normalize
print(img_tensor[0][0][0])
trans_norm = transforms.Normalize([0.5,0.5,0.5], [0.5,0.5,0.5])
img_norm = trans_norm(img_tensor)
print(img_norm[0][0][0])
writer.add_image('Normalize', img_norm)
writer.close()
欢迎大家交流评论,一起学习
希望本文能帮助您解决您在这方面遇到的问题
感谢阅读
END
以上是关于「深度学习一遍过」必修16:Tensorboard与Transforms的主要内容,如果未能解决你的问题,请参考以下文章