当前位置:网站首页>【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 的标准正态分布,这就是最普通(科学研究价值最大的)的样本数据了
边栏推荐
- Nacos - Configuration Management
- Nacos - 配置管理
- Shell脚本-变量的定义、赋值和删除
- C语言学生信息管理系统
- 通过 代码实例 理解 浅复制 与 深复制
- Log4j 日志框架
- Shell script - definition, assignment and deletion of variables
- Embedded Engineer Interview frequently asked questions
- It technology ebook collection
- V79.01 Hongmeng kernel source code analysis (user mode locking) | how to use the fast lock futex (Part 1) | hundreds of blogs analyze the openharmony source code
猜你喜欢

Insert mathematical formula in MD document and mathematical formula in typora

Phishing identification app

Bimianhongfu queren()
V79.01 Hongmeng kernel source code analysis (user mode locking) | how to use the fast lock futex (Part 1) | hundreds of blogs analyze the openharmony source code

钓鱼识别app

jeecg 重启报40001

Personal decoration notes

Redis——Lettuce连接redis集群

5mo3 UHI HII HII 17mn4 19Mn6 executive standard

Centos7 shell script one click installation of JDK, Mongo, Kafka, FTP, PostgreSQL, PostGIS, pgrouting
随机推荐
Nacos - gestion de la configuration
V79.01 Hongmeng kernel source code analysis (user mode locking) | how to use the fast lock futex (Part 1) | hundreds of blogs analyze the openharmony source code
Is it safe to dig up money and make new shares
Mysql8.0 learning record 17 -create table
Software Engineer Interview Question brushing website and experience method
类加载
Embedded Engineer Interview frequently asked questions
Dynamic proxy
Principles of Microcomputer - internal and external structure of microprocessor
Daily office consumables management solution
Personal decoration notes
易点易动助力企业设备高效管理,提升设备利用率
Only in China! Alicloud container service enters the Forrester leader quadrant
Principles of Microcomputer - Introduction
【ESP 保姆级教程 预告】疯狂Node.js服务器篇 ——案例:ESP8266 + DHT11 +NodeJs本地服务+ MySQL数据库
JCL and slf4j
[MFC development (16)] tree control
Which method is good for the management of fixed assets of small and medium-sized enterprises?
如何高效拉齐团队认知
Shell脚本-特殊变量:Shell $#、$*、[email protected]、$?、$$