当前位置:网站首页>Structure and usage of transform

Structure and usage of transform

2022-06-23 08:06:00 booze-J


One 、transform effect

chart 1

1

chart 2

 Insert picture description here

Two 、 The practical application tensor type

The detailed code is as follows :

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

# python  Usage of  -》 tensor data type 
#  adopt transform.ToTensor Look at two questions 
# 2、 Why do we need Tensor data type  : because tensor The type data contains the attributes needed to train the neural network 

image_path = r"D:\pycharm_professional\PycharmProjects\learning_pytorch\dataset\train\ants_image\0013035.jpg"

img = Image.open(image_path)

writer = SummaryWriter("logs") # ctrl+P View parameters  ctrl + alt Solve the problem of red explosion 

# 1、transforms How to use (python)
#  Generate an object 
tensor_trans = transforms.ToTensor()
tensor_img = tensor_trans(img)

#  Use tensorboard Exhibition 
writer.add_image("tensor_img",tensor_img,1)
writer.close()

terminal Terminal input instructions tensorboard --logdir="logs" --port=6007
 Insert picture description here
give the result as follows :
 Insert picture description here

原网站

版权声明
本文为[booze-J]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230733000445.html