深入浅出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.)
相关推荐
Coder_Boy_几秒前
基于Spring AI的分布式在线考试系统-事件处理架构实现方案
人工智能·spring boot·分布式·spring
Light6014 分钟前
智链未来:彭山物流园区从物理基建到数据智能体的全维度构建方案
人工智能·系统架构·数字孪生·智慧物流·实施路径·彭山项目
AI资源库18 分钟前
GLM-4.7-Flash模型深入解析
人工智能·语言模型
一切尽在,你来37 分钟前
1.2 LangChain 1.2.7 版本核心特性与升级点
人工智能·langchain
LYFlied40 分钟前
AI大时代下前端跨端解决方案的现状与演进路径
前端·人工智能
深蓝电商API42 分钟前
图片验证码识别:pytesseract+opencv入门
人工智能·opencv·计算机视觉·pytesseract
.Katherine௰42 分钟前
AI数字人模拟面试机器人
人工智能
光影少年43 分钟前
AI 前端 / 高级前端
前端·人工智能·状态模式
zhangshuang-peta1 小时前
OpenCode vs Claude Code vs OpenAI Codex:AI编程助手全面对比
人工智能·ai agent·mcp·peta
Bruk.Liu1 小时前
(LangChain 实战14):基于 ChatMessageHistory 自定义实现对话记忆功能
人工智能·python·langchain·agent