当前位置:网站首页>Normalization layer of pytorch learning (batchnorm, layernorm, instancenorm, groupnorm) [easy to understand]
Normalization layer of pytorch learning (batchnorm, layernorm, instancenorm, groupnorm) [easy to understand]
2022-06-29 13:48:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
BN,LN,IN,GN Explain the differences academically :BatchNorm:batch The direction is normalized , count NHW The average of , Yes, small batchsize The result is bad ;BN The main drawback is to batchsize It's more sensitive to the size of , Because the mean and variance of each calculation are in one batch On , So if batchsize Too small , Then the calculated mean 、 Variance is not enough to represent the entire data distribution LayerNorm:channel The direction is normalized , count CHW The average of , Mainly for RNN The effect is obvious ; InstanceNorm: One channel Do normalization inside , count H*W The average of , Used in stylized migration ; Because in image stylization , The result depends on an image instance , So for the whole batch Normalization is not suitable for image stylization , Therefore, the HW Normalization . It can accelerate the convergence of the model , And keep each image instance independent . GroupNorm: take channel Direction points group, Then each group Do normalization inside , count (C//G)HW The average of ; In this way batchsize irrelevant , Not bound by it . SwitchableNorm Yes, it will BN、LN、IN combination , Give weight to , Let the network go by itself Study What method should be used for the normalization layer .
1 BatchNorm
torch.nn.BatchNorm1d(num_features, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) torch.nn.BatchNorm2d(num_features, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) torch.nn.BatchNorm3d(num_features, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
Parameters :
num_features: The number of features from the desired input , The expected input size is ’batch_size x num_features [x width]’ eps: To ensure numerical stability ( The denominator cannot approach or take 0), The value added to the denominator . The default is 1e-5. momentum: Momentum used for dynamic mean and variance . The default is 0.1. affine: Boolean value , When set to true, Add learning affine transformation parameters to this layer . track_running_stats: Boolean value , When set to true, Record the mean and variance during training ;
Implementation formula :
2 GroupNorm
torch.nn.GroupNorm(num_groups, num_channels, eps=1e-05, affine=True)
Parameters :
num_groups: Need to be divided into groups num_features: The number of features from the desired input , The expected input size is ’batch_size x num_features [x width]’ eps: To ensure numerical stability ( The denominator cannot approach or take 0), The value added to the denominator . The default is 1e-5. momentum: Momentum used for dynamic mean and variance . The default is 0.1. affine: Boolean value , When set to true, Add learning affine transformation parameters to this layer .
Implementation formula :
3 InstanceNorm
torch.nn.InstanceNorm1d(num_features, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) torch.nn.InstanceNorm2d(num_features, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False) torch.nn.InstanceNorm3d(num_features, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False)
Parameters :
num_features: The number of features from the desired input , The expected input size is ’batch_size x num_features [x width]’ eps: To ensure numerical stability ( The denominator cannot approach or take 0), The value added to the denominator . The default is 1e-5. momentum: Momentum used for dynamic mean and variance . The default is 0.1. affine: Boolean value , When set to true, Add learning affine transformation parameters to this layer . track_running_stats: Boolean value , When set to true, Record the mean and variance during training ;
Implementation formula :
4 LayerNorm
torch.nn.LayerNorm(normalized_shape, eps=1e-05, elementwise_affine=True)
Parameters :
normalized_shape: Enter dimensions [∗×normalized_shape[0]×normalized_shape[1]×…×normalized_shape[−1]] eps: To ensure numerical stability ( The denominator cannot approach or take 0), The value added to the denominator . The default is 1e-5. elementwise_affine: Boolean value , When set to true, Add learning affine transformation parameters to this layer .
Implementation formula :
5 LocalResponseNorm
torch.nn.LocalResponseNorm(size, alpha=0.0001, beta=0.75, k=1.0)
Parameters :
size: Number of neighbor channels used for normalization alpha: Product factor ,Default: 0.0001 beta : Index ,Default: 0.75 k: Additional factor ,Default: 1
Implementation formula :
Reference resources :BatchNormalization、LayerNormalization、InstanceNorm、GroupNorm、SwitchableNorm summary
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/132340.html Link to the original text :https://javaforall.cn
边栏推荐
- AOSP ~ initialization language
- 3个最佳实践助力企业改善供应链安全
- Five years after graduation, I asked all the leaders around me and summarized their learning methods
- 手把手教你在windows上安装mysql8.0最新版本数据库,保姆级教学
- Mondo rescue creates an image file (which is conducive to image damage recovery)
- PHP FPM startup parameters and important configuration details
- System.currentTimeMillis() 和 System.nanoTime() 哪个更快?大部分人都会答错!
- PG Basics - logical structure management (1)
- GEE——美国LANDFIRE火灾数据集
- C语言字符函数
猜你喜欢

思科模拟器简单校园网设计,期末作业难度

C language character function

iMile 利用 Zadig 多云环境周部署千次,跨云跨地域持续交付全球业务

WinDbg common commands
![[graduation season · advanced technology Er] 10.76 million graduates, the most difficult employment season in history? I can't roll it up again. I lie down again and again. Where is the road?](/img/d5/7e093b898807b96b89bbe74174990b.png)
[graduation season · advanced technology Er] 10.76 million graduates, the most difficult employment season in history? I can't roll it up again. I lie down again and again. Where is the road?
![[untitled] error in installation dependency: refusing to install package with name](/img/53/8c871037b7586343fd509dcecb0d96.png)
[untitled] error in installation dependency: refusing to install package with name "* * *" under a package

Ordinary users use vscode to log in to SSH and edit the root file

Uncover the secret! Pay attention to those machines under the membership system!

【无标题】安装依赖报错:Refusing to install package with name “***“ under a package

Imile uses Zadig's multi cloud environment to deploy thousands of times a week to continuously deliver global business across clouds and regions
随机推荐
PG基础篇--逻辑结构管理(1)
weserver发布地图服务
如何让 Dapper 支持 DateOnly 类型
[graduation season] it's worth it all the way over the past four years -- advice from the senior students
成功解决ValueError: Only TF native optimizers are supported in Eager mode
Cisco simulator simple campus network design, final assignment difficulty
[cloud resident co creation] break through the performance bottleneck of image recognition through rust language computing acceleration technology
urllib urllib2
3个最佳实践助力企业改善供应链安全
Leetcode game 299
Create an API rapid development platform, awesome!
Online text filter less than specified length tool
sqlite3入门
Check yaml file security configuration: kubesec
weserver發布地圖服務
C语言模拟实现所有字符函数
How to set the safety line and safety margin for futures trading?
成功解决NotImplementedError: numpy() is only available when eager execution is enabled.
Cvpr2022 | a convnet for the 2020s & how to design neural network Summary
思科模拟器简单校园网设计,期末作业难度