当前位置:网站首页>torchversion.transforms的使用
torchversion.transforms的使用
2022-08-09 01:23:00 【chuanauc】
1.首先看源代码:
点transform进入的内容是:
在ctrl再选中圈出来的.transforms就可以了,进入transform.py文件,其实torchversion.transforms包 的实现就是在这个transform.py文件中
2.介绍Compose类:
这个类就是将多个transforms结合到一起,就像他举的例子一样,将ransforms.CenterCrop(10)和transforms.Totensor()两个transforms结合到一起,ransforms.CenterCrop(10)的输出就是transforms.Totensor()的输入。
3.ToTensor 类:
将一个 PIL.Image类型或者numpy.array类型的数据转换成为tensor类型
4. transforms 常用的类 :
5. 这里还有一些关于:
transforms中Normalize类:(11:29处):常见的Transforms(一)_哔哩哔哩_bilibili
transforms中Risize类:(0:0处)常见的Transforms(二)_哔哩哔哩_bilibili
RandomCrop类:(10:36处)常见的Transforms(二)_哔哩哔哩_bilibili
6. transform的用法:
(1)背景知识:什么是tensor数据类型:
为什么我们需要tensor数据类型:如下图所示:第一张图显示的是PIL.Image格式下的图的描述,第二章图显示的是tensor格式下的图的描述。我们可以明显发现 tensor数据类型包含了一些神经网络训练时需要的内容,如梯度grad等等
PIL.Image:
tensor格式:
(2)背景知识__call__()函数 是什么?
以下面这段代码为例可以解释一下:
简言之就是,如果有实现__call__()函数,那么就可以直接用实例传参数调用
(3)如何使用transform :
首先通过调用transform中的类来实例化一个实例,作为当下要使用的工具
(当然个各类实例化时需要的参数或者注意事项各不相同,需要自己查阅一下官方的文档)
然后利用这个实例化的工具对要处理的内容进行处理
from torchvision import transforms
from PIL import Image
img_path = "2222.jpg" #图片的相对路径
img = Image.open(img_path)
print((img))
tensor_trans = transforms.ToTensor() #调用transform中的ToTensor类,来实例化出一个实例tensor_trans,作为当下将PIL.Image转换为tensor类型数据所要使用的工具
tensor_img = tensor_trans(img)
print(tensor_img)
边栏推荐
- 《LC刷题总结》——贪心
- Node.js:MySQL.js的基本操作增删改查
- Use Ehcache distributed cache to easily create commercial-grade high-concurrency, high-performance API interfaces!
- 轻量化网络ChannelNet--channel-wize Conv在channel维度卷积
- ffplay playback control
- 等到中心化的平台不再,衍生于这个平台的一切都将化作泡影
- Using MySQL in Ubuntu/Linux environment: Modify the database sql_mode to solve the "this is incompatible with sql_mode=only_full_group_by" problem
- 关于cordova的InAppBrowser插件的几点问题
- 轻量级网络SqueezeNet学习记录
- docker搭建redis主从复制,容器无法启动?
猜你喜欢
CondConv--动态卷积思想
微信企业号开发之开启回调模式
睿智的目标检测61——Tensorflow2 Focal loss详解与在YoloV4当中的实现
jetson nano 开机闪一下然后黑屏
[Signal denoising] Based on Sage-Husa adaptive Kalman filter to realize the suppression of ocean wave magnetic field noise and the generation of ocean wave magnetic field noise with matlab code
STM32H750VBT6 Keil5 error :flash download failed cortex-M7
Network In Network学习记录
【.NET 6】开发minimal api以及依赖注入的实现和代码演示
LeetCode精选200道--字符串篇
Non-major graduates, five-faced Ali: Four rounds of technical + HR have already taken an offer
随机推荐
进程和线程
《Go语言学习:基本变量与类型》
LeetCode每日两题02:轮转数组 (均1200道)
微信企业号开发之开启回调模式
在特征通道提升网络性能 --SENet网络详解
走向合规化的虚拟人直播
LeetCode每日两题01:有序数组的平方 (均1200道)方法:双指针
EfficientNet v2网络学习记录--更小更快
Docker redis master-slave replication setup, the container cannot be started?
在实际工作中如何开展性能测试?
Image denoising based on edge enhancement Diffusion 】 (cEED) and Coherence Enhancing coursing together (cCED) filter to realize image denoising matlab code
卷积神经网络EfficentNet v1学习记录--Model Scaling
4-5 Matplotlib库 散点图
LVGL简介(基于v8.1-8.2)
typescripet92-添加任务功能优化
[Signal denoising] Based on Sage-Husa adaptive Kalman filter to realize the suppression of ocean wave magnetic field noise and the generation of ocean wave magnetic field noise with matlab code
LeetCode每日一题:搜索插入位置 (均1200道)方法:二分查找
VS中如何添加依赖的库
The Best Open Source Web Application Firewall to Protect Your Web Applications
Cmake 报错 Could not find a package configuration file provided by “OpenCV“