In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces Pytorch how to use transforms, the article is very detailed, has a certain reference value, interested friends must read it!
First of all, the tansforms function of this explanation is, generally speaking, similar to the data enhancement in the image preprocessing part of the computer vision process.
The principle of transforms:
Description: the picture (input) gets the result (output) through the tool, this tool is the transforms template tool, (tool=transforms.ToTensor () specific tool), using the tool result=tool (picture)
The call and use of tansforms can be obtained from the following figure:
First create a transforms.Tensor () and switch packets using from torchvision import transforms
Transforms demodulates init function
Init calls the real transforms class, and there are a lot of methods (green pentagram annotations), such as resize,ToTensor,CenterCrop (as you can see from these methods, many of them are data enhancement methods).
Next, go to the code:
Import osfrom torchvision import transformsfrom PIL import Imageroot_path = "D:\ data\\ basic\\ Image" label_path = "aligned" # 1. Get the name of the first picture of aligned img_dir = os.path.join (root_path, label_path) img_list = os.listdir (img_dir) img_path = img_list [0] # 2. Get the path of the first graph of aligned img = os.path.join (root_path, label_path, img_path) # 3. Use the PIL that comes with python to get the picture img = Image.open (img) # 4. Convert PIL to ToTensorto_tensor = transforms.ToTensor () # to create totensor () img = to_tensor (img) # convert PIL of a picture directly to tensorprint (img) # transforms using to_tensor
Code result:
The above is all the contents of the article "how Pytorch uses transforms". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.