当前位置:网站首页>【pytorch】transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
【pytorch】transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
2022-07-01 09:03:00 【Enzo 想砸电脑】
ransform.Normalize(): 用均值和标准差对张量图像进行归一化
经常看到
transforms.Compose([transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
那transform.Normalize()是怎么工作的呢?以上面代码为例,
ToTensor() 做了两件事:
- 把灰度范围从0-255变换到0-1之间,其将每一个数值归一化到[0,1],其归一化方法比较简单,直接除以255即可
- 将shape为(H,W, C)的nump.ndarray或img转为shape为(C, H, W)的tensor
transforms.Normalize()
transforms.Normalize(std=(0.5,0.5,0.5),mean=(0.5,0.5,0.5)),则其作用就是先将输入归一化到(0,1),再使用公式"(x-mean)/std",将每个元素分布到(-1,1)
image=(image-mean)/std
其中mean 和 std分别通过 (0.5,0.5,0.5) 和 (0.5,0.5,0.5) 进行指定。原来的 0-1 最小值 0 则变成 (0-0.5)/0.5=-1,而最大值1则变成(1-0.5)/0.5=1.
可我看很多代码里面是这样的:
torchvision.transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
这一组值是怎么来的?这一组值是从imagenet训练集中抽样算出来的。
总结:
经过上面normalize()的变换后变成了均值为0 方差为1(其实就是最大最小值为1和-1)
每个样本图像变成了均值为0 方差为1 的标准正态分布,这就是最普通(科学研究价值最大的)的样本数据了
边栏推荐
- Public network cluster intercom +gps visual tracking | help the logistics industry with intelligent management and scheduling
- LogBack
- Memory size end
- Nacos - gestion de la configuration
- 嵌入式工程师面试-常问问题集
- Shell脚本-字符串
- Promise异步编程
- C language student information management system
- Shell脚本-select in循环
- Shell脚本-read命令:读取从键盘输入的数据
猜你喜欢

电视机尺寸与观看距离

Redis——Lettuce连接redis集群

5mo3 UHI HII HII 17mn4 19Mn6 executive standard
![[MFC development (16)] tree control](/img/b9/1de4330c0bd186cfe062b02478c058.png)
[MFC development (16)] tree control

Principle and application of single chip microcomputer timer, serial communication and interrupt system

大型工厂设备管理痛点和解决方案

Do you know how data is stored? (C integer and floating point)

Screenshot tips

FreeRTOS学习简易笔记

Installing Oracle EE
随机推荐
Ranking list of domestic databases in February, 2022: oceanbase regained the "three consecutive increases", and gaussdb is expected to achieve the largest increase this month
如何高效拉齐团队认知
ARM v7的体系结构A、R、M区别,分别应用在什么领域?
Shell脚本-位置参数(命令行参数)
Interrupt sharing variables with other functions and protection of critical resources
Win7 pyinstaller reports an error DLL load failed while importing after packaging exe_ Socket: parameter error
Performance improvement 2-3 times! The second generation Kunlun core server of Baidu AI Cloud was launched
Redis -- lattice connects to redis cluster
Shell脚本-字符串
VSYNC+三重缓存机制+Choreographer
Databinding source code analysis
Do you know how data is stored? (C integer and floating point)
类加载
JCL and slf4j
通过 代码实例 理解 浅复制 与 深复制
How to effectively align team cognition
Shell脚本-case in语句
小鸟识别APP
Computer tips
[interview brush 101] linked list