当前位置: 首页 > news >正文

深入浅出Pytorch函数——torch.nn.init.xavier_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不会将其考虑在内。

根据Glorot, X.和Bengio, Y.在《Understanding the difficulty of training deep feedforward neural networks》中描述的方法,用一个均匀分布生成值,填充输入的张量或变量。结果张量中的值采样自 U ( − a , a ) U(-a, a) U(a,a),其中:
a = gain × 6 fan_in + fan_put a=\text{gain}\times\sqrt{\frac{6}{\text{fan\_in}+\text{fan\_put}}} a=gain×fan_in+fan_put6

这种方法也被称为Glorot initialization。

语法

torch.nn.init.xavier_uniform_(tensor, gain=1)

参数

  • tensor:[Tensor] 一个 N N N维张量torch.Tensor
  • gain :[float] 可选的缩放因子

返回值

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

实例

w = torch.empty(3, 5)
nn.init.xavier_uniform_(w, gain=nn.init.calculate_gain('relu'))

函数实现

def xavier_uniform_(tensor: Tensor, gain: float = 1.) -> Tensor:r"""Fills the input `Tensor` with values according to the methoddescribed in `Understanding the difficulty of training deep feedforwardneural networks` - Glorot, X. & Bengio, Y. (2010), using a uniformdistribution. The resulting tensor will have values sampled from:math:`\mathcal{U}(-a, a)` where.. math::a = \text{gain} \times \sqrt{\frac{6}{\text{fan\_in} + \text{fan\_out}}}Also known as Glorot initialization.Args:tensor: an n-dimensional `torch.Tensor`gain: an optional scaling factorExamples:>>> w = torch.empty(3, 5)>>> nn.init.xavier_uniform_(w, gain=nn.init.calculate_gain('relu'))"""fan_in, fan_out = _calculate_fan_in_and_fan_out(tensor)std = gain * math.sqrt(2.0 / float(fan_in + fan_out))a = math.sqrt(3.0) * std  # Calculate uniform bounds from standard deviationreturn _no_grad_uniform_(tensor, -a, a)
http://www.lryc.cn/news/136136.html

相关文章:

  • 优橙内推安徽专场——5G网络优化(中高级)工程师
  • 2023年计算机设计大赛国三 数据可视化 (源码可分享)
  • 工业生产全面感知!工业感知云来了
  • Lnton羚通关于Optimization在【PyTorch】中的基础知识
  • 冒泡排序算法
  • 无人机航管应答机 ping200XR
  • oracle归档日志满了导致启动不起来解决
  • 高等数学:线性代数-第二章
  • 星戈瑞分析FITC-PEG-Alkyne的荧光特性和光谱特性
  • VB.NET调用VB6 Activex EXE实现PowerBasic和FreeBasic的标准DLL调用
  • 深入了解Unity的Physics类:一份详细的技术指南(七)(下篇)
  • C++入门:引用是什么
  • 2023年人工智能与自动化控制国际学术会议(AIAC 2023)
  • 分布式核心知识以及常见微服务框架
  • Unity记录4.1-存储-根据关键字加载Tile
  • 数据结构—树表的查找
  • 微信小程序测试策略和注意事项?
  • VUE3封装EL-ELEMENT-PLUS input组件
  • RISC-V公测平台发布 · 在SG2042上配置Jupiter+Octave科学计算环境
  • 初识Sentinel
  • 【官方中文文档】Mybatis-Spring #注入映射器
  • UG\NX 二次开发 相切面、相邻面的选择控件
  • Quartz任务调度框架介绍和使用
  • drools8尝试
  • 【机器学习】python基础实现线性回归
  • vue table合并行 动态列名
  • Spring Cloud Alibaba-Nacos Discovery--服务治理
  • 【C++】unordered_map和unordered_set的使用 及 OJ练习
  • 初识 JVM 01
  • FPGA应用学习笔记----I2S和总结