深度学习-参数初始化

一、参数初始化分类及原理

1、简介

  • 神经网络的训练过程中的参数学习是基于梯度下降法进行优化的。梯度下降法需要在开始训练时给每一个参数赋一个初始值。这个初始值的选取十分关键。一般我们希望数据和参数的均值都为 0,输入和输出数据的方差一致。在实际应用中,参数服从高斯分布或者均匀分布都是比较有效的初始化方式。

  • A well chosen initialization can:

  • Speed up the convergence of gradient descent
  • Increase the odds of gradient descent converging to a lower training (and generalization) error
  • Poor initialization can:
    • lead to vanishing/exploding gradients, which also slows down the optimization algorithm
  • Random initialization is used to break symmetry and make sure different hidden units can learn different things
  • 2、分类

    参数初始化分类

    3、原理

    • 为了使得在经过多层网络后,信号不被过分放大或过分减弱,我们尽可能保持 每个神经元的输入和输出的方差一致
      参数初始化原理

    • 高斯分布

    • 均值为:mean=0mean=0

    4、总结

    • 使用 RELU(without BN) 激活函数时,最好选用 He 初始化方法,将参数初始化为服从高斯分布或者均匀分布的较小随机数
    • 使用 BN 时,减少了网络对参数初始值尺度的依赖,此时使用较小的标准差(eg:0.01)进行初始化即可
    • 借助预训练模型中参数作为新任务参数初始化的方式也是一种简便易行且十分有效的模型参数初始化方法

    二、参数初始化代码实践

    0、符合约定

    n_in:为网络的输入大小
    n_out:为网络的输出大小
    n:为 n_in 或 (n_in + n_out) * 0.5--->(同时考虑信号在前向和反向传播中都不被放大或缩小)
     
     
    • 1
    • 2
    • 3

    1、Xavier 初始化

    • 高斯分布初始化:
    # 适用于普通激活函数(tanh,sigmoid):stdev 为高斯分布的标准差,均值设为 0
    stdev = np.sqrt(1/n) 
    W = tf.Variable(np.random.randn(n_in, n_out) * stdev)
     
     
    • 1
    • 2
    • 3
    • 均匀分布初始化:
    # 适用于普通激活函数(tanh, sigmoid)
    scale = np.sqrt(3/n)
    W = tf.Variable(np.random.uniform(low=-scale, high=scale, size=[n_in, n_out]))
     
     
    • 1
    • 2
    • 3

    2、He 初始化

    • 高斯分布初始化:
    # 适用于 ReLU:stdev 为高斯分布的标准差,均值设为 0
    stdev = np.sqrt(2/n)
    W = tf.Variable(np.random.randn(n_in, n_out) * stdev) 
     
     
    • 1
    • 2
    • 3
    • 均匀分布初始化:
    # 适用于 ReLU
    scale = np.sqrt(6/n)
    W = tf.Variable(np.random.uniform(low=-scale, high=scale, size=[n_in, n_out]))
     
     
    • 1
    • 2
    • 3

    3、BN+高斯分布(小 σσ)随机初始化

    W = tf.Variable(np.random.randn(node_in, node_out) * 0.01)

    W = tf.Variable(np.random.randn(shape) * 0.01) # shape 可以不止二维!


    fc = tf.contrib.layers.batch_norm(fc, center=True, scale=True, is_training=True)
    fc = tf.nn.relu(fc)

    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    4、TensorFLow 中的实现


    三、参考文献

    1、聊一聊深度学习的weight initialization
    2、深度学习网络训练技巧汇总
    3、A tutorial on Deep Learning for Objects and Scenes at CVPR(Kaiming He)
    4、tensorflow 1.0 学习:参数初始化
    5、第七章 网络优化与正则化(复旦-邱锡鹏)

    文章转发自 https://blog.csdn.net/mzpmzk/article/details/79839047
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值