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

分类目录:《深入浅出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不会将其考虑在内。

该函数用1填充输入的张量或变量

语法

复制代码
torch.nn.init.ones_(tensor)

参数

  • tensor:[Tensor] 一个 N N N维张量torch.Tensor

返回值

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

实例

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

函数实现

复制代码
def ones_(tensor: Tensor) -> Tensor:
    r"""Fills the input Tensor with the scalar value `1`.

    Args:
        tensor: an n-dimensional `torch.Tensor`

    Examples:
        >>> w = torch.empty(3, 5)
        >>> nn.init.ones_(w)
    """
    return _no_grad_fill_(tensor, 1.)
相关推荐
kikikidult5 分钟前
Ubuntu20.04运行openmvg和openmvs实现三维重建(未成功,仅供参考)
人工智能·笔记·ubuntu·计算机视觉
1892280486141 分钟前
NW728NW733美光固态闪存NW745NW746
大数据·服务器·网络·人工智能·性能优化
大模型最新论文速读1 小时前
模拟注意力:少量参数放大 Attention 表征能力
人工智能·深度学习·机器学习·语言模型·自然语言处理
lishaoan772 小时前
用TensorFlow进行逻辑回归(二)
人工智能·tensorflow·逻辑回归
慌ZHANG2 小时前
智慧气象新范式:人工智能如何重构城市级气象服务生态?
人工智能
Eumenidus2 小时前
使用ESM3蛋白质语言模型进行快速大规模结构预测
人工智能·语言模型·自然语言处理
熊猫钓鱼>_>2 小时前
FastGPT革命:下一代语言模型的极速进化
人工智能·语言模型·自然语言处理
吕永强2 小时前
电网的智能觉醒——人工智能重构能源生态的技术革命与公平悖论
人工智能·科普
极限实验室2 小时前
喜报 - 极限科技荣获 2025 上海开源创新菁英荟「开源创新新星企业」奖
人工智能·开源
在美的苦命程序员2 小时前
芯片之后,AI之争的下一个战场是能源?
人工智能