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

yipeiwu_com6年前Python基础

一开始没看懂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还提供了平均分布等。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Django 简单实现分页与搜索功能的示例代码

Django 简单实现分页与搜索功能的示例代码

假设现有需求如下: 需要一个页面分页展示信息,在该页面添加搜索框以提供检索功能。 那么,我们知道,展示信息和检索功能是在同一个页面,也就是共用一个路由。 代码如下: 第一步,写路由:为了...

利用python在excel里面直接使用sql函数的方法

利用python在excel里面直接使用sql函数的方法

我们一般在Excel里面是使用数据连接属性里面写sql语句,或者vba里面利用ado组件执行sql语句。 新版的Excel里面带上了Power query的功能也可以使用Odbc.Dat...

python 获取url中的参数列表实例

Python的urlparse有对url的解析,从而获得url中的参数列表 import urlparse urldata = "http://en.wikipedia.org/w/...

python tkinter实现彩球碰撞屏保

python tkinter实现彩球碰撞屏保

利用Tkinter实现彩球碰撞屏保,供大家参考,具体内容如下 一、架构与思路 (1)主函数: main():通过类启动程序; (2)类: ScreenSaver():用于定义屏保和主画布...

Python的string模块中的Template类字符串模板用法

string.Template() string.Template()内添加替换的字符, 使用"$"符号, 或 在字符串内, 使用"${}"; 调用时使用string.substitut...