当前位置: 代码迷 >> 综合 >> Tensorflow2.0 中 tf.keras.layers.Conv2D 里的初始化方法 'glorot_uniform' 到底是个啥?
  详细解决方案

Tensorflow2.0 中 tf.keras.layers.Conv2D 里的初始化方法 'glorot_uniform' 到底是个啥?

热度:35   发布时间:2023-10-28 14:33:30.0

在我们使用 tf.keras.layers.Conv2D 来构建卷积层时,一般使用的权值初始化方法就是这个函数默认的方法,即 ‘glorot_uniform’
源码对其做出了解释:

'''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 tensorand `fan_out` is the number of output units in the weight tensor. '''

也就是说,这个初始化方法使用的均匀分布的范围是 [-limit, limit],其中,
limit=sqrt(6fanin+fanout)limit=sqrt(\frac{6}{fan_{in} + fan_{out}})limit=sqrt(fanin?+fanout?6?)
这里的 faninfan_{in}fanin? 表示输入神经元的数量,fanoutfan_{out}fanout? 表示输出神经元的数量,即:
fanin?=channelsin?×kernerwidth×kernerheight??fan_{in}?=channels_{in}?\times kerner_{width}\times kerner_{height}??fanin??=channelsin??×kernerwidth?×kernerheight???
fanout?=channelsout?×kernerwidth?×kernerheight?fan_{out?}=channels_{out?}\times kerner_{width}?\times kerner_{height}?fanout??=channelsout??×kernerwidth??×kernerheight??
假设输入网络的一个 28*28*1 的数据,卷积核形状为 3*3,卷积核通道数有 32 个(即输出的通道数有 32 个),那么此时 limit 为:
limit=sqrt(63×3×1+3×3×32)limit=sqrt(\frac{6}{3\times 3\times 1 + 3\times 3\times 32})limit=sqrt(3×3×1+3×3×326?)

  相关解决方案