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()
transform的简单使用
时间:2023-08-29
相关推荐