深入浅出Pytorch函数——torch.nn.init.uniform_

分类目录:《深入浅出Pytorch函数》总目录

相关文章:

· 深入浅出Pytorch函数------torch.nn.init.calculate_gain

· 深入浅出Pytorch函数------torch.nn.init.uniform_

· 深入浅出Pytorch函数------torch.nn.init.normal_

· 深入浅出Pytorch函数------torch.nn.init.constant_

· 深入浅出Pytorch函数------torch.nn.init.ones_

· 深入浅出Pytorch函数------torch.nn.init.zeros_

· 深入浅出Pytorch函数------torch.nn.init.eye_

· 深入浅出Pytorch函数------torch.nn.init.dirac_

· 深入浅出Pytorch函数------torch.nn.init.xavier_uniform_

· 深入浅出Pytorch函数------torch.nn.init.xavier_normal_

· 深入浅出Pytorch函数------torch.nn.init.kaiming_uniform_

· 深入浅出Pytorch函数------torch.nn.init.kaiming_normal_

· 深入浅出Pytorch函数------torch.nn.init.trunc_normal_

· 深入浅出Pytorch函数------torch.nn.init.orthogonal_

· 深入浅出Pytorch函数------torch.nn.init.sparse_


torch.nn.init模块中的所有函数都用于初始化神经网络参数,因此它们都在torc.no_grad()模式下运行,autograd不会将其考虑在内。

该函数从均匀分布 U ( a , b ) U(a, b) U(a,b)中生成值,填充输入的张量或变量

语法

复制代码
torch.nn.init.uniform_(tensor, a=0.0, b=1.0)

参数

  • tensor:[Tensor] 一个 N N N维张量torch.Tensor
  • a:[float] 均匀分布的下界
  • b:[float] 均匀分布的上界

返回值

一个torch.Tensor且参数tensor也会更新

实例

复制代码
w = torch.empty(3, 5)
nn.init.uniform_(w)

函数实现

复制代码
def uniform_(tensor: Tensor, a: float = 0., b: float = 1.) -> Tensor:
    r"""Fills the input Tensor with values drawn from the uniform
    distribution :math:`\mathcal{U}(a, b)`.

    Args:
        tensor: an n-dimensional `torch.Tensor`
        a: the lower bound of the uniform distribution
        b: the upper bound of the uniform distribution

    Examples:
        >>> w = torch.empty(3, 5)
        >>> nn.init.uniform_(w)
    """
    if torch.overrides.has_torch_function_variadic(tensor):
        return torch.overrides.handle_torch_function(uniform_, (tensor,), tensor=tensor, a=a, b=b)
    return _no_grad_uniform_(tensor, a, b)
相关推荐
格林威10 分钟前
UV紫外相机的简单介绍和场景应用
人工智能·数码相机·计算机视觉·视觉检测·制造·uv·工业相机
番石榴AI1 小时前
自己动手做一款ChatExcel数据分析系统,智能分析 Excel 数据
人工智能·python·数据挖掘·excel
laopeng3011 小时前
基于Spring AI Deep Researcher Agent
java·人工智能·spring
lzptouch1 小时前
数据预处理(音频/图像/视频/文字)及多模态统一大模型输入方案
人工智能·音视频
星期天要睡觉1 小时前
深度学习——循环神经网络(RNN)
人工智能·python·rnn·深度学习·神经网络
jieba121381 小时前
CAA机器学习
人工智能
TextIn智能文档云平台1 小时前
LLM 文档处理:如何让 AI 更好地理解中文 PDF 中的复杂格式?
人工智能·pdf
Blossom.1181 小时前
把AI“撒”进农田:基于极值量化与状态机的1KB边缘灌溉决策树
人工智能·python·深度学习·算法·目标检测·决策树·机器学习
takashi_void2 小时前
本地实现斯坦福小镇(利用大语言模型使虚拟角色自主发展剧情)类似项目“Microverse”
人工智能·语言模型·自然语言处理·godot·游戏程序·斯坦福小镇
java1234_小锋2 小时前
TensorFlow2 Python深度学习 - 循环神经网络(LSTM)示例
python·rnn·深度学习·tensorflow2