当前位置:网站首页>【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 的标准正态分布,这就是最普通(科学研究价值最大的)的样本数据了
边栏推荐
- Shell脚本-case in语句
- 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
- Only in China! Alicloud container service enters the Forrester leader quadrant
- Foundation: 2 The essence of image
- 安装Oracle EE
- How can enterprises and developers take the lead in the outbreak of cloud native landing?
- How to manage fixed assets efficiently in one stop?
- 用C语言编程:用公式计算:e≈1+1/1!+1/2! …+1/n!,精度为10-6
- FreeRTOS学习简易笔记
- Nacos - Configuration Management
猜你喜欢

Redis——Lettuce连接redis集群

Phishing identification app

个人装修笔记

钓鱼识别app

Redis -- lattice connects to redis cluster

小鸟识别APP

Only in China! Alicloud container service enters the Forrester leader quadrant
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

Which method is good for the management of fixed assets of small and medium-sized enterprises?

安装Oracle EE
随机推荐
pcl_viewer命令
Nacos - 配置管理
毕业季,我想对你说
Performance improvement 2-3 times! The second generation Kunlun core server of Baidu AI Cloud was launched
Summary of reptile knowledge points
大型工厂设备管理痛点和解决方案
Public network cluster intercom +gps visual tracking | help the logistics industry with intelligent management and scheduling
5mo3 UHI HII HII 17mn4 19Mn6 executive standard
【ESP 保姆级教程 预告】疯狂Node.js服务器篇 ——案例:ESP8266 + DS18B20温度传感器 +NodeJs本地服务+ MySQL数据库
中小企业固定资产管理办法哪种好?
Jetson nano installs tensorflow GPU and problem solving
如何一站式高效管理固定资产?
Shell脚本-case in语句
Shell script - positional parameters (command line parameters)
Databinding source code analysis
Advanced C language pointer (Part 2)
It technology ebook collection
Differences among tasks, threads and processes
中考体育项目满分标准(深圳、安徽、湖北)
Which method is good for the management of fixed assets of small and medium-sized enterprises?