欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

transform的简单使用

时间:2023-08-29

from PIL import Imagefrom torch.utils.tensorboard import SummaryWriterfrom torchvision import transformswriter = SummaryWriter("logs")img = Image.open("images/outside.jpg")trans_totensor = transforms.ToTensor()img_tensor = trans_totensor(img)writer.add_image("ToTensor", img_tensor)# normalizetrans_norm = transforms.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5])img_norm = trans_norm(img_tensor)writer.add_image("Normalize", img_norm, 2)#resizeprint(img.size)trans_resize = transforms.Resize((512, 512))img_resize = trans_resize(img_tensor)writer.add_image("resize", img_resize, 2)writer.close()

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。