当前位置:网站首页>【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 的标准正态分布,这就是最普通(科学研究价值最大的)的样本数据了
边栏推荐
- AVL树的理解和实现
- Set the type of the input tag to number, and remove the up and down arrows
- Principles of Microcomputer - Introduction
- LogBack
- 类加载
- Shell脚本-while循环详解
- Shell script - array definition and getting array elements
- Common interview questions for embedded engineers 2-mcu_ STM32
- [MFC development (16)] tree control
- Shell脚本-read命令:读取从键盘输入的数据
猜你喜欢
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

5mo3 UHI HII HII 17mn4 19Mn6 executive standard

Advanced level of C language pointer (Part 1)

Advanced C language pointer (Part 2)

1. Connection between Jetson and camera

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

NiO zero copy

Understanding and implementation of AVL tree

Football and basketball game score live broadcast platform source code /app development and construction project

Bimianhongfu queren()
随机推荐
Shell script case in and regular expressions
Principles of Microcomputer - internal and external structure of microprocessor
Introduction to 18mnmo4-5 steel plate executive standard and delivery status of 18mnmo4-5 steel plate, European standard steel plate 18mnmo4-5 fixed rolling
Shell script -for loop and for int loop
Differences among tasks, threads and processes
jeecg 重启报40001
AVL树的理解和实现
Dynamic proxy
Principles of Microcomputer - Introduction
[interview brush 101] linked list
An overview of the design of royalties and service fees of mainstream NFT market platforms
ARM v7的体系结构A、R、M区别,分别应用在什么领域?
Shell脚本-read命令:读取从键盘输入的数据
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
猿人学第20题(题目会不定时更新)
Shell脚本-case in 和正则表达式
Summary of reptile knowledge points
【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于阿里云、小程序、Arduino的WS2812灯控系统
美团2022年机试
I would like to know the process of stock registration and account opening by mobile phone? In addition, is it safe to open a mobile account?