nn.init.xavier_uniform_()的作用:根据均匀分布生成Tensor

该文介绍了Glorot初始化方法,即Xavier均匀分布,用于填充神经网络权重,以解决深度学习模型训练中的梯度消失或爆炸问题。该方法基于数学公式`a=sqrt(6/(fan_in+fan_out))`来确定分布范围,确保输入和输出层的方差平衡。示例展示了如何使用PyTorch的`nn.init.xavier_uniform_`函数进行权重初始化,并关联到Glorot和Bengio在2010年的研究工作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

官网解释如下:
Signature: nn.init.xavier_uniform_(tensor: torch.Tensor, gain: float = 1.0) -> torch.Tensor
Docstring:
Fills the input Tensor with values according to the method
described in Understanding the difficulty of training deep feedforward neural networks - Glorot, X. & Bengio, Y. (2010), using a uniform
distribution. The resulting tensor will have values sampled from
:math:\mathcal{U}(-a, a) where

… math::
a = \text{gain} \times \sqrt{\frac{6}{\text{fan_in} + \text{fan_out}}}

Also known as Glorot initialization.

Args:
tensor: an n-dimensional torch.Tensor
gain: an optional scaling factor

Examples:
>>> w = torch.empty(3, 5)
>>> nn.init.xavier_uniform_(w, gain=nn.init.calculate_gain(‘relu’))
File: c:\users\administrator\appdata\roaming\python\python37\site-packages\torch\nn\init.py
Type: function

其中
U = ( − a , a ) \mathcal{U}=(-\mathrm{a}, \mathrm{a}) U=(a,a)


在这里插入图片描述

参见:
Glorot, X. & Bengio, Y. (2010). Understanding the difficulty of training deep feedforward neural networks.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值