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


Posted in Python onFebruary 11, 2018

一开始没看懂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 相关文章推荐
Python 网络爬虫--关于简单的模拟登录实例讲解
Jun 01 Python
Python日期时间对象转换为字符串的实例
Jun 22 Python
Django 路由系统URLconf的使用
Oct 11 Python
详解Django的model查询操作与查询性能优化
Oct 16 Python
Windows 安装 Anaconda3+PyCharm的方法步骤
Jun 13 Python
Django自带日志 settings.py文件配置方法
Aug 30 Python
Pytorch 中retain_graph的用法详解
Jan 07 Python
Python 中@property的用法详解
Jan 15 Python
Python 写了个新型冠状病毒疫情传播模拟程序
Feb 14 Python
在python3.64中安装pyinstaller库的方法步骤
Jun 02 Python
python实现xlwt xlrd 指定条件给excel行添加颜色
Jul 14 Python
python使用布隆过滤器的实现示例
Aug 20 Python
python的staticmethod与classmethod实现实例代码
Feb 11 #Python
Python语言的变量认识及操作方法
Feb 11 #Python
利用Opencv中Houghline方法实现直线检测
Feb 11 #Python
tensorflow输出权重值和偏差的方法
Feb 10 #Python
详解tensorflow实现迁移学习实例
Feb 10 #Python
Python学习之Django的管理界面代码示例
Feb 10 #Python
Tensorflow 自带可视化Tensorboard使用方法(附项目代码)
Feb 10 #Python
You might like
支持oicq头像的留言簿(二)
2006/10/09 PHP
javascript,php获取函数参数对象的代码
2011/02/03 PHP
使用php+Ajax实现唯一校验实现代码[简单应用]
2011/11/29 PHP
PHP输入流php://input介绍
2012/09/18 PHP
PHP goto语句简介和使用实例
2014/03/11 PHP
php中的静态变量的基本用法
2014/03/20 PHP
网页图片延时加载的js代码
2010/04/22 Javascript
Extjs4实现两个GridPanel之间数据拖拽功能具体方法
2013/11/21 Javascript
jquery鼠标停止移动事件
2013/12/21 Javascript
js实现简单随机抽奖的方法
2015/01/27 Javascript
js简单设置与使用cookie的方法
2016/01/22 Javascript
微信小程序 详解下拉加载与上拉刷新实现方法
2017/01/13 Javascript
js 递归和定时器的实例解析
2017/02/03 Javascript
vue.js利用Object.defineProperty实现双向绑定
2017/03/09 Javascript
JavaScript 中的 this 工作原理
2018/06/20 Javascript
vue使用ElementUI时导航栏默认展开功能的实现
2018/07/04 Javascript
详解Vue.js v-for不支持IE9的解决方法
2018/12/29 Javascript
OpenLayers加载缩放控件使用方法详解
2020/09/25 Javascript
antd vue table跨行合并单元格,并且自定义内容实例
2020/10/28 Javascript
python中__call__内置函数用法实例
2015/06/04 Python
Python with语句上下文管理器两种实现方法分析
2018/02/09 Python
python安装教程
2018/02/28 Python
Django Rest framework之认证的实现代码
2018/12/17 Python
Python字符串格式化输出代码实例
2019/11/22 Python
python实现监控阿里云账户余额功能
2019/12/16 Python
Pytorch模型转onnx模型实例
2020/01/15 Python
Python3基本输入与输出操作实例分析
2020/02/14 Python
pytorch使用tensorboardX进行loss可视化实例
2020/02/24 Python
pycharm的python_stubs问题
2020/04/08 Python
python给视频添加背景音乐并改变音量的具体方法
2020/07/19 Python
Python 使用Opencv实现目标检测与识别的示例代码
2020/09/08 Python
关于探究python中sys.argv时遇到的问题详解
2021/02/23 Python
寒假思想汇报
2014/01/10 职场文书
新春联欢会主持词
2014/03/24 职场文书
思想作风整顿个人剖析材料
2014/10/06 职场文书
《夹竹桃》教学反思
2016/02/23 职场文书