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爬取读者并制作成PDF
Mar 10 Python
Python使用pickle模块实现序列化功能示例
Jul 13 Python
python批量下载网站马拉松照片的完整步骤
Dec 05 Python
python3.6数独问题的解决
Jan 21 Python
利用matplotlib为图片上添加触发事件进行交互
Apr 23 Python
Python读取Excel数据并生成图表过程解析
Jun 18 Python
用opencv给图片换背景色的示例代码
Jul 08 Python
python中sys模块是做什么用的
Aug 16 Python
Python新建项目自动添加介绍和utf-8编码的方法
Dec 26 Python
Python 的 f-string 可以连接字符串与数字的原因解析
Feb 20 Python
pyqt5蒙版遮罩mask,setmask的使用
Jun 11 Python
python中的sys模块和os模块
Mar 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
php 前一天或后一天的日期
2008/06/28 PHP
PHPMailer安装方法及简单实例
2008/11/25 PHP
php 遍历目录,生成目录下每个文件的md5值并写入到结果文件中
2016/12/12 PHP
php代码调试利器firephp安装与使用方法分析
2018/08/21 PHP
js onpropertychange输入框 事件获取属性
2009/03/26 Javascript
13 个JavaScript 性能提升技巧分享
2012/07/26 Javascript
jquery 关于event.target使用的几点说明介绍
2013/04/26 Javascript
JavaScript获取onclick、onchange等事件值的代码
2013/07/22 Javascript
javascript解析json实例详解
2014/11/05 Javascript
jQuery中scrollTop()方法用法实例
2015/01/16 Javascript
JavaScript实现上下浮动的窗口效果代码
2015/10/12 Javascript
javascript中new关键字详解
2015/12/14 Javascript
最细致的vue.js基础语法 值得收藏!
2016/11/03 Javascript
新手vue构建单页面应用实例代码
2017/09/18 Javascript
解决Vue axios post请求,后台获取不到数据的问题方法
2018/08/11 Javascript
layui的table单击行勾选checkbox功能方法
2018/08/14 Javascript
浅谈关于JS下大批量异步任务按顺序执行解决方案一点思考
2019/01/08 Javascript
微信小程序实现简易table表格
2020/06/19 Javascript
Python 基础教程之闭包的使用方法
2017/09/29 Python
python学习基础之循环import及import过程
2018/04/22 Python
python实现彩票系统
2020/06/28 Python
python集合是否可变总结
2019/06/20 Python
深入了解如何基于Python读写Kafka
2019/12/31 Python
Python虚拟环境库virtualenvwrapper安装及使用
2020/06/17 Python
python正则表达式的懒惰匹配和贪婪匹配说明
2020/07/13 Python
浅析HTML5:'data-'属性的作用
2018/01/23 HTML / CSS
在线购买廉价折扣书籍和小说:BookOutlet.com
2018/02/19 全球购物
迎国庆演讲稿
2014/09/15 职场文书
基层党支部整改方案
2014/10/25 职场文书
酒店保洁员岗位职责
2015/02/26 职场文书
2015年保管员工作总结
2015/04/30 职场文书
党支部综合考察意见
2015/06/01 职场文书
银行中层干部培训心得体会
2016/01/11 职场文书
JavaScript实现简单计时器
2021/06/22 Javascript
Element实现动态表格的示例代码
2021/08/02 Javascript
win11系统中dhcp服务异常什么意思? Win11 DHCP服务异常修复方法
2022/04/08 数码科技