TensorFlow中权重的随机初始化的方法

 更新时间:2018年02月11日 09:19:30   作者:松松的鞋带儿  
本篇文章主要介绍了TensorFlow中权重的随机初始化的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

一开始没看懂stddev是什么参数,找了一下,在tensorflow/python/ops里有random_ops,其中是这么写的:

def random_normal(shape, mean=0.0, stddev=1.0, dtype=types.float32,
         seed=None, name=None):
 """Outputs random values from a normal distribution.

 Args:
  shape: A 1-D integer Tensor or Python array. The shape of the output tensor.
  mean: A 0-D Tensor or Python value of type `dtype`. The mean of the normal
   distribution.
  stddev: A 0-D Tensor or Python value of type `dtype`. The standard deviation
   of the normal distribution.
  dtype: The type of the output.
  seed: A Python integer. Used to create a random seed for the distribution.
   See
   [`set_random_seed`](../../api_docs/python/constant_op.md#set_random_seed)
   for behavior.
  name: A name for the operation (optional).

 Returns:
  A tensor of the specified shape filled with random normal values.
 """

也就是按照正态分布初始化权重,mean是正态分布的平均值,stddev是正态分布的标准差(standard deviation),seed是作为分布的random seed(随机种子,我百度了一下,跟什么伪随机数发生器还有关,就是产生随机数的),在mnist/concolutional中seed赋值为66478,挺有意思,不知道是什么原理。

后面还有truncated_normal的定义:

def truncated_normal(shape, mean=0.0, stddev=1.0, dtype=types.float32,
           seed=None, name=None):
 """Outputs random values from a truncated normal distribution.

 The generated values follow a normal distribution with specified mean and
 standard deviation, except that values whose magnitude is more than 2 standard
 deviations from the mean are dropped and re-picked.

 Args:
  shape: A 1-D integer Tensor or Python array. The shape of the output tensor.
  mean: A 0-D Tensor or Python value of type `dtype`. The mean of the
   truncated normal distribution.
  stddev: A 0-D Tensor or Python value of type `dtype`. The standard deviation
   of the truncated normal distribution.
  dtype: The type of the output.
  seed: A Python integer. Used to create a random seed for the distribution.
   See
   [`set_random_seed`](../../api_docs/python/constant_op.md#set_random_seed)
   for behavior.
  name: A name for the operation (optional).

 Returns:
  A tensor of the specified shape filled with random truncated normal values.
 """

截断正态分布,以前都没听说过。

TensorFlow还提供了平均分布等。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • Django文件存储 自己定制存储系统解析

    Django文件存储 自己定制存储系统解析

    这篇文章主要介绍了Django文件存储 自己定制存储系统解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2019-08-08
  • python调用golang中函数方法

    python调用golang中函数方法

    由于simhash方法有多种实现方式,现python中simhash方法与golang中的不一样,需要两者代码生成结果保持一致,故采用python中的代码调用golang编译的so文件来实现,需要的朋友可以参考下
    2024-02-02
  • 在Debian下配置Python+Django+Nginx+uWSGI+MySQL的教程

    在Debian下配置Python+Django+Nginx+uWSGI+MySQL的教程

    这篇文章主要介绍了在Debian下配置Python+Django+Nginx+uWSGI+MySQL的教程,Debian系统和Nginx服务器皆是高性能的选择,需要的朋友可以参考下
    2015-04-04
  • 分享2个方便调试Python代码的实用工具

    分享2个方便调试Python代码的实用工具

    这篇文章主要介绍了分享方便调试Python代码的2个实用工具,可以方便展示我们调试代码的中间状态,提升大家的编码效率,详细的介绍需要的小伙伴可以参考一下下面文章内容
    2022-05-05
  • Python实现暴力破解有密码的zip文件的方法

    Python实现暴力破解有密码的zip文件的方法

    这篇文章主要介绍了Python实现暴力破解有密码的zip文件的方法,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2021-03-03
  • Python:一行代码,导入Python所有库

    Python:一行代码,导入Python所有库

    在本篇内容里小编给大家分享如何用一行代码,导入Python所有库,有需要的朋友们可以学习下,希望能够给你带来帮助
    2021-10-10
  • Python实现非正太分布的异常值检测方式

    Python实现非正太分布的异常值检测方式

    今天小编就为大家分享一篇Python实现非正太分布的异常值检测方式,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2019-12-12
  • 深入了解PyQt5中的图形视图框架

    深入了解PyQt5中的图形视图框架

    PyQt5中图形视图框架主要包含三个类:QGraphicsItem图元类、QGraphicsScene场景类和QGraphicsView视图类。本文将通过示例详细讲解一下这三个类,感兴趣的可以学习一下
    2022-03-03
  • TensorFlow 合并/连接数组的方法

    TensorFlow 合并/连接数组的方法

    今天小编就为大家分享一篇TensorFlow 合并/连接数组的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2018-07-07
  • numpy.random.shuffle打乱顺序函数的实现

    numpy.random.shuffle打乱顺序函数的实现

    这篇文章主要介绍了numpy.random.shuffle打乱顺序函数的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-09-09

最新评论