当前位置:网站首页>PyTorch学习之归一化层(BatchNorm、LayerNorm、InstanceNorm、GroupNorm)[通俗易懂]
PyTorch学习之归一化层(BatchNorm、LayerNorm、InstanceNorm、GroupNorm)[通俗易懂]
2022-06-29 10:44:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
BN,LN,IN,GN从学术化上解释差异:BatchNorm:batch方向做归一化,算NHW的均值,对小batchsize效果不好;BN主要缺点是对batchsize的大小比较敏感,由于每次计算均值和方差是在一个batch上,所以如果batchsize太小,则计算的均值、方差不足以代表整个数据分布 LayerNorm:channel方向做归一化,算CHW的均值,主要对RNN作用明显; InstanceNorm:一个channel内做归一化,算H*W的均值,用在风格化迁移;因为在图像风格化中,生成结果主要依赖于某个图像实例,所以对整个batch归一化不适合图像风格化中,因而对HW做归一化。可以加速模型收敛,并且保持每个图像实例之间的独立。 GroupNorm:将channel方向分group,然后每个group内做归一化,算(C//G)HW的均值;这样与batchsize无关,不受其约束。 SwitchableNorm是将BN、LN、IN结合,赋予权重,让网络自己去学习归一化层应该使用什么方法。
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)
参数:
num_features: 来自期望输入的特征数,该期望输入的大小为’batch_size x num_features [x width]’ eps: 为保证数值稳定性(分母不能趋近或取0),给分母加上的值。默认为1e-5。 momentum: 动态均值和动态方差所使用的动量。默认为0.1。 affine: 布尔值,当设为true,给该层添加可学习的仿射变换参数。 track_running_stats:布尔值,当设为true,记录训练过程中的均值和方差;
实现公式:
2 GroupNorm
torch.nn.GroupNorm(num_groups, num_channels, eps=1e-05, affine=True)
参数:
num_groups:需要划分为的groups num_features: 来自期望输入的特征数,该期望输入的大小为’batch_size x num_features [x width]’ eps: 为保证数值稳定性(分母不能趋近或取0),给分母加上的值。默认为1e-5。 momentum: 动态均值和动态方差所使用的动量。默认为0.1。 affine: 布尔值,当设为true,给该层添加可学习的仿射变换参数。
实现公式:
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)
参数:
num_features: 来自期望输入的特征数,该期望输入的大小为’batch_size x num_features [x width]’ eps: 为保证数值稳定性(分母不能趋近或取0),给分母加上的值。默认为1e-5。 momentum: 动态均值和动态方差所使用的动量。默认为0.1。 affine: 布尔值,当设为true,给该层添加可学习的仿射变换参数。 track_running_stats:布尔值,当设为true,记录训练过程中的均值和方差;
实现公式:
4 LayerNorm
torch.nn.LayerNorm(normalized_shape, eps=1e-05, elementwise_affine=True)
参数:
normalized_shape: 输入尺寸 [∗×normalized_shape[0]×normalized_shape[1]×…×normalized_shape[−1]] eps: 为保证数值稳定性(分母不能趋近或取0),给分母加上的值。默认为1e-5。 elementwise_affine: 布尔值,当设为true,给该层添加可学习的仿射变换参数。
实现公式:
5 LocalResponseNorm
torch.nn.LocalResponseNorm(size, alpha=0.0001, beta=0.75, k=1.0)
参数:
size:用于归一化的邻居通道数 alpha:乘积因子,Default: 0.0001 beta :指数,Default: 0.75 k:附加因子,Default: 1
实现公式:
参考:BatchNormalization、LayerNormalization、InstanceNorm、GroupNorm、SwitchableNorm总结
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/132340.html原文链接:https://javaforall.cn
边栏推荐
- Today in history: musk was born; Microsoft launches office 365; The inventor of Chua's circuit was born
- Qt学习15 用户界面与业务逻辑的分离
- XML外部实体注入漏洞(一)
- Qt学习03 Qt的诞生和本质
- The use of variables in shell that you have to be familiar with
- Follow Me Study HCIE-Big Data-Data Mining 第一章 数据挖掘介绍 模块一
- Good news | Haitai Fangyuan has passed the cmmi-3 qualification certification, and its R & D capability has been internationally recognized
- 【高并发】2.8万字的Callable和Future面试知识点总结,看完我直接面进了字节跳动,原谅我有点飘了(中)
- Exclusive interview with head of suss NIFT: the future of Web3 is inseparable from the governance of "everyone for me, I for everyone"
- 5. migrate uboot set default environment variables, crop, and partition
猜你喜欢

Babbitt | yuancosmos daily must read: HTC announced the launch of the first yuancosmos mobile phone, which costs about 2700 yuan. What are the new ways to play

QT learning 08 set sail! First application instance

How to test the performance of container platform, including stability, expansion efficiency and component performance

Multi thread communication between client and server (primary version)

Necessary for cloud native development: the first common codeless development platform IVX editor

Evaluation of IP location query interface Ⅱ

ruoyi框架中添加sharding sphere5.0.0分表(通过spi添加自定义分表策略)

在日本的 IT 公司工作是怎样一番体验?

Discussion on QT learning 10 message processing in QT

Specific method and example program of Siemens s7-200smart control stepping motor
随机推荐
rxjs Observable 设计原理背后的 Pull 和 Push 思路
【每日3题(3)】重新格式化电话号码
【毕业季】总结过去,展望未来
Pipeline aggregations pipeline aggregation-sibling-1
[HBZ sharing] principle of semaphore and countdownlatch
(JS) responsibility chain mode
ETL为什么经常变成ELT甚至LET?
中科方德技术专家直播:如何基于 OpenStack、Ceph 构建私有云平台? | 第 27 期
【高并发】2.8万字的Callable和Future面试知识点总结,看完我直接面进了字节跳动,原谅我有点飘了(上)
信息技术应用创新专业人员(数据库)中级培训火热招生中(7月6-10日)
Online text filter less than specified length tool
Leetcode 535 encryption and decryption of tinyurl [map] the leetcode road of heroding
What is the experience of working in an IT company in Japan?
(JS) array flat
(JS) handwritten deep copy
CTO专访:合见工软深化产品布局 加速国产EDA技术革新
TTL serial port learning infrared remote control module can be extended to network control
Pull and push ideas behind rxjs observable design principles
(JS) array methods: slice and slice
Bs-gx-017 online examination management system based on SSM