当前位置:网站首页>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)
边栏推荐
猜你喜欢
[Cellular Automata] Simulation of emergency evacuation of disaster personnel under social force factors based on cellular automata with matlab code attached
考研人总结的时间管理7大忌,你中了几条?
【元胞自动机】基于元胞自动机模拟社会力因素下的灾害人员疏散应急仿真附matlab代码
解决有路由策略的情况下域内NAT不通的问题
LeetCode每日两题02:第一个错误的版本 (均1200道)方法:二分查找
Network In Network学习记录
【.NET 6】开发minimal api以及依赖注入的实现和代码演示
日文翻译-在线免费日文翻译软件
C语言-大端存储和小端存储
tf.pad()--填充操作
随机推荐
网络安全基础-基本dos命令(一)
Bugs encountered in remote control projects
轻量级神经网络SqueezeNext--考虑硬件提速
LeetCode每日两题01:有序数组的平方 (均1200道)方法:双指针
轻量级CNN网络高效设计准则-ShuffleNet v2学习记录
经典卷积神经网络ZFNet--解卷积可视化
class path resource [bean.xml] cannot be opened because it does not 错误解决方案
睿智的目标检测61——Tensorflow2 Focal loss详解与在YoloV4当中的实现
clickhouse 思维导图
5-4 Seaborn 线性回归绘图
Docker redis master-slave replication setup, the container cannot be started?
Go-8-Gin框架
LeetCode每日两题02:第一个错误的版本 (均1200道)方法:二分查找
Mysql高级篇(逻辑架构和存储引擎)
PostMan导入证书 添加证书
Go-10-模块与包
PMP有什么答题技巧?
容器运维平台的故障处理-1
2022年中国全民健身发展白皮书
【Fiddler】Fiddler实现mock测试(模拟接口数据)