https://blog.csdn.net/u011534057/article/details/51673458

https://blog.csdn.net/qq_34784753/article/details/78668884

https://blog.csdn.net/kangroger/article/details/61414426

https://www.cnblogs.com/lindaxin/p/8027283.html

神经网络中权值初始化的方法

《Understanding the difficulty of training deep feedforward neural networks》

可惜直到近两年,这个方法才逐渐得到更多人的应用和认可。

为了使得网络中信息更好的流动,每一层输出的方差应该尽量相等。

基于这个目标,现在我们就去推导一下:每一层的权重应该满足哪种条件。

文章先假设的是线性激活函数,而且满足0点处导数为1,即 

现在我们先来分析一层卷积: 
 
其中ni表示输入个数。

根据概率统计知识我们有下面的方差公式: 

特别的,当我们假设输入和权重都是0均值时(目前有了BN之后,这一点也较容易满足),上式可以简化为: 

进一步假设输入x和权重w独立同分布,则有: 

于是,为了保证输入与输出方差一致,则应该有: 

对于一个多层的网络,某一层的方差可以用累积的形式表达: 

特别的,反向传播计算梯度时同样具有类似的形式: 

综上,为了保证前向传播和反向传播时每一层的方差一致,应满足:

但是,实际当中输入与输出的个数往往不相等,于是为了均衡考量,最终我们的权重方差应满足:

——————————————————————————————————————— 
 
———————————————————————————————————————

学过概率统计的都知道 [a,b] 间的均匀分布的方差为: 

因此,Xavier初始化的实现就是下面的均匀分布:

—————————————————————————————————————————— 

caffe的Xavier实现有三种选择

(1) 默认情况,方差只考虑输入个数: 

(2) FillerParameter_VarianceNorm_FAN_OUT,方差只考虑输出个数: 

(3) FillerParameter_VarianceNorm_AVERAGE,方差同时考虑输入和输出个数: 

之所以默认只考虑输入,我个人觉得是因为前向信息的传播更重要一些

———————————————————————————————————————————

Tensorflow 调用接口

https://www.tensorflow.org/api_docs/python/tf/glorot_uniform_initializer

 

tf.glorot_uniform_initializer

 

Aliases:

  • tf.glorot_uniform_initializer
  • tf.keras.initializers.glorot_uniform
 
tf.glorot_uniform_initializer(
    seed=None,
    dtype=tf.float32
)

Defined in tensorflow/python/ops/init_ops.py.

The Glorot uniform initializer, also called Xavier uniform initializer.

It draws samples from a uniform distribution within [-limit, limit] where limit is sqrt(6 / (fan_in + fan_out))where fan_in is the number of input units in the weight tensor and fan_out is the number of output units in the weight tensor.

Reference: http://jmlr.org/proceedings/papers/v9/glorot10a/glorot10a.pdf

Args:

  • seed: A Python integer. Used to create random seeds. See tf.set_random_seed for behavior.
  • dtype: The data type. Only floating point types are supported.

Returns:

An initializer.

Mxnet 调用接口

https://mxnet.apache.org/api/python/optimization/optimization.html#mxnet.initializer.Xavier

class mxnet.initializer.Xavier(rnd_type='uniform', factor_type='avg', magnitude=3)[source]

Returns an initializer performing “Xavier” initialization for weights.

This initializer is designed to keep the scale of gradients roughly the same in all layers.

By default, rnd_type is 'uniform' and factor_type is 'avg', the initializer fills the weights with random numbers in the range of [−c,c][−c,c], where c=3.0.5∗(nin+nout)−−−−−−−−−√c=3.0.5∗(nin+nout). ninnin is the number of neurons feeding into weights, and noutnout is the number of neurons the result is fed to.

If rnd_type is 'uniform' and factor_type is 'in', the c=3.nin−−−√c=3.nin. Similarly when factor_type is 'out', the c=3.nout−−−√c=3.nout.

If rnd_type is 'gaussian' and factor_type is 'avg', the initializer fills the weights with numbers from normal distribution with a standard deviation of 3.0.5∗(nin+nout)−−−−−−−−−√3.0.5∗(nin+nout).

Parameters:
  • rnd_type (stroptional) – Random generator type, can be 'gaussian' or 'uniform'.
  • factor_type (stroptional) – Can be 'avg''in', or 'out'.
  • magnitude (floatoptional) – Scale of random number.

神经网络权值初始化方法-Xavier的更多相关文章

  1. caffe中权值初始化方法

    首先说明:在caffe/include/caffe中的 filer.hpp文件中有它的源文件,如果想看,可以看看哦,反正我是不想看,代码细节吧,现在不想知道太多,有个宏观的idea就可以啦,如果想看代 ...

  2. [PyTorch 学习笔记] 4.1 权值初始化

    本章代码:https://github.com/zhangxiann/PyTorch_Practice/blob/master/lesson4/grad_vanish_explod.py 在搭建好网络 ...

  3. pytorch(14)权值初始化

    权值的方差过大导致梯度爆炸的原因 方差一致性原则分析Xavier方法与Kaiming初始化方法 饱和激活函数tanh,非饱和激活函数relu pytorch提供的十种初始化方法 梯度消失与爆炸 \[H ...

  4. 权值初始化 - Xavier和MSRA方法

    设计好神经网络结构以及loss function 后,训练神经网络的步骤如下: 初始化权值参数 选择一个合适的梯度下降算法(例如:Adam,RMSprop等) 重复下面的迭代过程: 输入的正向传播 计 ...

  5. PyTorch 学习笔记(四):权值初始化的十种方法

    pytorch在torch.nn.init中提供了常用的初始化方法函数,这里简单介绍,方便查询使用. 介绍分两部分: 1. Xavier,kaiming系列: 2. 其他方法分布 Xavier初始化方 ...

  6. python面向对象的基础语法(dir内置函数、self参数、初始化方法、内置方法和属性)

    面相对象基础语法 目标 dir 内置函数 定义简单的类(只包含方法) 方法中的 self 参数 初始化方法 内置方法和属性 01. dir 内置函数(知道) 在 Python 中 对象几乎是无所不在的 ...

  7. 深度学习----Xavier初始化方法

    “Xavier”初始化方法是一种很有效的神经网络初始化方法,方法来源于2010年的一篇论文<Understanding the difficulty of training deep feedf ...

  8. 网络权重初始化方法总结(下):Lecun、Xavier与He Kaiming

    目录 权重初始化最佳实践 期望与方差的相关性质 全连接层方差分析 tanh下的初始化方法 Lecun 1998 Xavier 2010 ReLU/PReLU下的初始化方法 He 2015 for Re ...

  9. 深度学习——Xavier初始化方法

    “Xavier”初始化方法是一种很有效的神经网络初始化方法,方法来源于2010年的一篇论文<Understanding the difficulty of training deep feedf ...

随机推荐

  1. Vue 常见问题汇总

    Q:我给组件内的原生控件添加事件,怎么不生效了!!! <!--比如用了第三方框架,或者一些封装的内置组件; 然后想绑定事件--> <!--// 错误例子1--> <el- ...

  2. HTML5学习笔记(八):CSS定位

    CSS 定位 (Positioning) 属性允许你对元素进行定位. 定位和浮动 CSS 为定位和浮动提供了一些属性,利用这些属性,可以建立列式布局,将布局的一部分与另一部分重叠.定位的基本思想很简单 ...

  3. 聊一聊 Spring 中的线程安全性

    Spring与线程安全 Spring作为一个IOC/DI容器,帮助我们管理了许许多多的“bean”.但其实,Spring并没有保证这些对象的线程安全,需要由开发者自己编写解决线程安全问题的代码. Sp ...

  4. 部署ArcGIS JS API 离线包(Tomcat与IIS)

    http://www.cnblogs.com/ventlam/archive/2012/12/13/2815583.html

  5. java8的新特性以及用法简介

    1. 介绍 2 接口的默认方法 2 lambda表达式 2.1 函数式接口 2.2 方法与构造函数引用 2.3 访问局部变量 2.4 访问对象字段与静态变量 3. 内建函数式接口 3.1 Predic ...

  6. OpenCV探索之路(十七):Mat和IplImage访问像素的方法总结

    在opencv的编程中,遍历访问图像元素是经常遇到的操作,掌握其方法非常重要,无论是Mat类的像素访问,还是IplImage结构体的访问的方法,都必须扎实掌握,毕竟,图像处理本质上就是对像素的各种操作 ...

  7. maven 使用之自动编译热部署设置

    参见创建webapp项目 eclipse Maven 使用记录 ------ 建立 webapp项目 在maven中为实现热部署设置,部署至webapp,即webroot 设置classes输出目的地 ...

  8. SFTP文件上传与下载(window 上传文件到linux服务器)

    一.文件上传 说明1:所谓上传window上的文件上传到linux上 说明2:上传的文件会自动放到当前的用户的家目录 1:打开SFTP的窗口 Alt+p 输入上传命令: 语法: put  path/f ...

  9. C# JAVA 记录代码运行时间

    C# System.Diagnostics.Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); // 开始监视代码运行时间 // cod ...

  10. [Python] 探索性编程与idleX

    1 探索式编程 前面介绍过几个Python的Interactive Shell,对于Python, Ruby这类动态语言来说,一个交互式的shell(用 emacs的术语来说,叫做REPL,也就是Re ...