深入浅出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.)
相关推荐
Allen_LVyingbo5 分钟前
Python常用医疗AI库以及案例解析(2025年版、上)
开发语言·人工智能·python·学习·健康医疗
jndingxin8 分钟前
OpenCV中超分辨率(Super Resolution)模块类cv::dnn_superres::DnnSuperResImpl
人工智能·opencv·dnn
NAGNIP11 分钟前
一文搞懂FlashAttention怎么提升速度的?
人工智能·算法
智能砖头14 分钟前
LangChain 与 LlamaIndex 深度对比与选型指南
人工智能·python
大师兄带你刨AI15 分钟前
「AI产业」| 《中国信通院&华为:智能体技术和应用研究报告》
大数据·人工智能
老周聊大模型27 分钟前
《ChatGLM/Llama调优实战:从指令微调到RLHF的工业级对齐方案》
人工智能·程序员·架构
ResponsibilityAmbiti27 分钟前
AI 发展 && MCP
人工智能·llm·aigc
zkmall32 分钟前
ZKmall模块商城批发电商平台搭建方案,多商户支持 + 订单管理功能全覆盖
大数据·人工智能
Codebee34 分钟前
OneCode图生代码技术深度解析:从可视化设计到注解驱动实现的全链路架构
css·人工智能·算法
刘大猫2636 分钟前
Datax安装及基本使用
java·人工智能·算法