深入浅出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.)
相关推荐
ahead~10 分钟前
【大模型原理与技术-毛玉仁】第五章 模型编辑
人工智能·深度学习·机器学习
迪娜学姐16 分钟前
GenSpark vs Manus实测对比:文献综述与学术PPT,哪家强?
论文阅读·人工智能·prompt·powerpoint·论文笔记
TDengine (老段)18 分钟前
TDengine 在电力行业如何使用 AI ?
大数据·数据库·人工智能·时序数据库·tdengine·涛思数据
猎板PCB厚铜专家大族20 分钟前
高频 PCB 技术发展趋势与应用解析
人工智能·算法·设计规范
l0sgAi24 分钟前
SpringBoot整合LangChain4j实现RAG (检索增强生成)
人工智能
祐言QAQ25 分钟前
浅谈边缘计算
人工智能·边缘计算
lboyj25 分钟前
高频通信与航天电子的材料革命:猎板PCB高端压合基材技术解析
人工智能
奔跑吧邓邓子43 分钟前
DeepSeek 赋能智能教育知识图谱:从构建到应用的革命性突破
人工智能·知识图谱·应用·deepseek·智能教育
Mantanmu1 小时前
Python训练day40
人工智能·python·机器学习
ss.li1 小时前
TripGenie:畅游济南旅行规划助手:个人工作纪实(二十二)
javascript·人工智能·python