Pytorch学习日记——常见的Transforms(一)

学习视频——B站【小土堆】

代码

from PIL import Image
from torch.utils.tensorboard import SummaryWriter
from torchvision import transforms



writer = SummaryWriter("logs")
img = Image.open("dataset/train/erciyuan_image/407-22641.jpg")
print(img)

#ToTensor使用
trans_totensor = transforms.ToTensor()
img_tensor = trans_totensor(img)
writer.add_image("ToTensor", img_tensor)

#Normalize归一化/规范化
print(img_tensor[0][0][0])
trans_norm = transforms.Normalize([1, 3, 5], [3, 2, 1])
img_norm = trans_norm(img_tensor)
print(img_norm[0][0][0])
writer.add_image("Normalize", img_norm, 1)

writer.close()

运行后在terminal终端输入

tensorboard --logdir=logs

点击链接

效果

Pytorch学习日记——常见的Transforms(一)_第1张图片

 

你可能感兴趣的:(pytorch,学习,深度学习)