当前位置:网站首页>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)
边栏推荐
猜你喜欢
5-4 Seaborn 线性回归绘图
tf.pad()--填充操作
《LC刷题总结》——贪心
全文翻译:EDPB数据保护影响评估(DPIA:Data Protection Impact Assessment)指南
A double non-programmer interviewed Ant, Meituan, Ctrip and other big companies with offers to share the interview process
OpenSceneGraph3.5.1编译
基于机器学习之模型树短期负荷预测(Matlab代码实现)
Network In Network学习记录
4-4 Matplotlib库 直方图
Discourse 的关闭主题(Close Topic )和重新开放主题
随机推荐
makefile文件编译
ICMP差错报告报文数据字段
Image denoising based on edge enhancement Diffusion 】 (cEED) and Coherence Enhancing coursing together (cCED) filter to realize image denoising matlab code
【信号去噪】基于Sage-Husa自适应卡尔曼滤波器实现海浪磁场噪声抑制及海浪磁场噪声的产生附matlab代码
KQL和Lucene的区别
2022PMP项目管理认证考试报考指南(1)
Qt中QFile、QByteArray QDataStream和QTextStream区别
4-10 Matplotlib 多图布局
【图像去噪】基于边缘增强扩散 (cEED) 和 Coherence Enhancing Diffusion (cCED) 滤波器实现图像去噪附matlab代码
软件测试技术之如何编写测试用例(5)
等到中心化的平台不再,衍生于这个平台的一切都将化作泡影
深度学习模型的两种部署:ONNX与Caffe
typescript90-使用类型文件声明类型
Loadrunner结合Fiddler实现脚本的录制
clickhouse 思维导图
如何仿造一个websocket请求?
Mysql高级篇(逻辑架构和存储引擎)
德语翻译-德语在线批量翻译软件
设计师设计相关图表时,如何运用设计技巧与合理的用户体验?【大屏可视化(PC端、移动端)】
2022年中国全民健身发展白皮书