当前位置:网站首页>Use of torchversion.transforms
Use of torchversion.transforms
2022-08-09 01:32:00 【chuanauc】
1. First look at the source code:
The content entered by clicking transform is:
Just select the circled .transforms in ctrl and enter the transform.py file. In fact, the implementation of the torchversion.transforms package is in this transform.py file
2. Introduce the Compose class:
This class is to combine multiple transforms, just like the example he gave, combine the two transforms transforms.CenterCrop(10) and transforms.Totensor() together, the output of transforms.CenterCrop(10)It is the input of transforms.Totensor().
3.ToTensor class:
Convert a PIL.Image or numpy.array data to a tensor type
4. Commonly used classes for transforms :
5. Here's a little more about:
Normalize class in transforms: (at 11:29): Common Transforms (1)_bilibili _bilibili
Risize class in transforms: (0:0) Common Transforms (2)_bilibili _bilibili
RandomCrop class: (at 10:36) Common Transforms (2) _ beep mile _bilibili
6. The usage of transform:
(1) Background knowledge: what is the tensor data type:
Why do we need the tensor data type: As shown in the following figure: The first picture shows the description of the picture in PIL.Image format, and the second picture shows the description of the picture in tensor format.We can obviously find that the tensor data type contains some content required for neural network training, such as gradient grad, etc.
PIL.Image:
tensor format:
(2) Background knowledge What is the __call__() function?
Take the following code as an example to explain:
In short, if there is a __call__() function implemented, then you can directly use the instance to pass parameters to call
(3) How to use transform:
First instantiate an instance by calling the class in transform as the tool to be used at the moment
(Of course, the parameters or precautions required for each type of instantiation are different, you need to check the official documentation yourself)
Then use this instantiated tool to process the content to be processed
from torchvision import transformsfrom PIL import Imageimg_path = "2222.jpg" #The relative path of the pictureimg = Image.open(img_path)print((img))tensor_trans = transforms.ToTensor() #Call the ToTensor class in transform to instantiate an instance tensor_trans as the tool to be used to convert PIL.Image to tensor type datatensor_img = tensor_trans(img)print(tensor_img)
边栏推荐
猜你喜欢
随机推荐
Docker redis master-slave replication setup, the container cannot be started?
【.NET 6】开发minimal api以及依赖注入的实现和代码演示
Discourse 的关闭主题(Close Topic )和重新开放主题
低代码接口开发平台——YesApi(API+数据表单)
ffplay playback control
【物理应用】基于El-centro地震波作用下隔震与非隔震支座下的顶层位移、速度、加速度的对比情况附matlab代码
Observer pattern
jetson nano 开机闪一下然后黑屏
Go-8-Gin框架
gstreamer 记录
DataNode重启
requestAnimationFrame实现浏览器动画
多语种翻译-免费多语种翻译软件
《LC刷题总结》——贪心
论文笔记:SAITS: SELF-ATTENTION-BASED IMPUTATION FOR TIMESERIES
【元胞自动机】基于元胞自动机模拟社会力因素下的灾害人员疏散应急仿真附matlab代码
qps tps rps 区别
字符串压缩
typescripet92-添加任务功能优化
5-2 Seaborn 分类绘图