当前位置:网站首页>【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:08:00 【Enzo tried to smash the computer】
ransform.Normalize(): The tensor image is normalized by mean and standard deviation
Often see
transforms.Compose([transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
that transform.Normalize() How does it work ? Take the above code for example ,
ToTensor() Did two things :
- Change the gray scale from 0-255 Change to 0-1 Between , It normalizes each value to [0,1], The normalization method is relatively simple , Divide directly by 255 that will do
- take shape by (H,W, C) Of nump.ndarray or img To shape by (C, H, W) Of tensor
transforms.Normalize()
transforms.Normalize(std=(0.5,0.5,0.5),mean=(0.5,0.5,0.5)), Its function is to normalize the input to (0,1), Then use the formula "(x-mean)/std", Distribute each element to (-1,1)
image=(image-mean)/std
among mean and std Pass respectively (0.5,0.5,0.5) and (0.5,0.5,0.5) Make a designation . The original 0-1 minimum value 0 Has become a (0-0.5)/0.5=-1, And the maximum 1 Has become a (1-0.5)/0.5=1.
But I think many codes are like this :
torchvision.transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
How does this group of values come from ? This set of values is from imagenet It's calculated by sampling in the training center .
summary :
Go over it normalize() After the transformation, the mean value becomes 0 The variance of 1( In fact, the maximum and minimum values are 1 and -1)
Each sample image becomes a mean value of 0 The variance of 1 The standard normal distribution of , This is the most common ( The greatest value of scientific research ) Sample data of
边栏推荐
- AVL树的理解和实现
- 【pytorch】softmax函数
- Common interview questions for embedded engineers 2-mcu_ STM32
- It is designed with high bandwidth, which is almost processed into an open circuit?
- Shell脚本-字符串
- [MFC development (16)] tree control
- 【电赛训练】红外光通信装置 2013年电赛真题
- Win7 pyinstaller reports an error DLL load failed while importing after packaging exe_ Socket: parameter error
- [ESP nanny level tutorial] crazy completion chapter - Case: gy906 infrared temperature measurement access card swiping system based on the Internet of things
- pcl_ Viewer command
猜你喜欢
随机推荐
jeecg 重启报40001
Shell script - definition, assignment and deletion of variables
Promise异步编程
钓鱼识别app
又到年中,固定资产管理该何去何从?
【ESP 保姆级教程】疯狂毕设篇 —— 案例:基于阿里云和Arduino的化学环境系统检测,支持钉钉机器人告警
How to manage fixed assets efficiently in one stop?
Flink面试题
[interview brush 101] linked list
【pytorch】2.4 卷积函数 nn.conv2d
MySQL optimization
Shell脚本-变量的定义、赋值和删除
大型工厂设备管理痛点和解决方案
Embedded Engineer Interview Question 3 Hardware
What are the differences between the architecture a, R and m of arm V7, and in which fields are they applied?
毕业季,我想对你说
Meituan machine test in 2022
[ESP nanny level tutorial] crazy completion chapter - Case: chemical environment system detection based on Alibaba cloud and Arduino, supporting nail robot alarm
Installing Oracle EE
LogBack








