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如何实现反向迭代
Mar 20 Python
django1.11.1 models 数据库同步方法
May 30 Python
Python UnboundLocalError和NameError错误根源案例解析
Oct 31 Python
Python实现简单层次聚类算法以及可视化
Mar 18 Python
python使用Qt界面以及逻辑实现方法
Jul 10 Python
python3实现在二叉树中找出和为某一值的所有路径(推荐)
Dec 26 Python
jupyter 实现notebook中显示完整的行和列
Apr 09 Python
Python unittest框架操作实例解析
Apr 13 Python
使用pytorch实现论文中的unet网络
Jun 24 Python
基于python实现图片转字符画代码实例
Sep 04 Python
解决pycharm不能自动保存在远程linux中的问题
Feb 06 Python
python正则表达式re.search()的基本使用教程
May 21 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
人族 Terran 魔法与科技
2020/03/14 星际争霸
PHP脚本数据库功能详解(中)
2006/10/09 PHP
PHP 9 大缓存技术总结
2015/09/17 PHP
浅谈Laravel核心解读之Console内核
2018/12/02 PHP
php使用pthreads v3多线程实现抓取新浪新闻信息操作示例
2020/02/21 PHP
某人初学javascript的时候写的学习笔记
2010/12/30 Javascript
js数值和和字符串进行转换时可以对不同进制进行操作
2014/03/05 Javascript
JavaScript动态改变表格单元格内容的方法
2015/03/30 Javascript
JS实现的仿东京商城菜单、仿Win右键菜单及仿淘宝TAB特效合集
2015/09/28 Javascript
微信小程序 教程之条件渲染
2016/10/18 Javascript
JavaScript中Math对象的方法介绍
2017/01/05 Javascript
vue.js开发环境安装教程
2017/03/17 Javascript
详解在vue-cli项目中安装node-sass
2017/06/21 Javascript
Vue.js数据绑定之data属性
2017/07/07 Javascript
JavaScript的Object.defineProperty详解
2018/07/09 Javascript
vue+springboot实现项目的CORS跨域请求
2018/09/05 Javascript
Bootstrap-table自定义可编辑每页显示记录数
2018/09/07 Javascript
Electron + vue 打包桌面操作流程详解
2019/06/24 Javascript
Vue中图片Src使用变量的方法
2019/10/30 Javascript
vue实现点击追加选中样式效果
2019/11/01 Javascript
ant design vue datepicker日期选择器中文化操作
2020/10/28 Javascript
Windows下安装python2.7及科学计算套装
2015/03/05 Python
Python中不同进制的语法及转换方法分析
2016/07/27 Python
python中urllib.unquote乱码的原因与解决方法
2017/04/24 Python
Python解析json之ValueError: Expecting property name enclosed in double quotes: line 1 column 2(char 1)
2017/07/06 Python
Python常见MongoDB数据库操作实例总结
2018/07/24 Python
Pandas DataFrame 取一行数据会得到Series的方法
2018/11/10 Python
python每5分钟从kafka中提取数据的例子
2019/12/23 Python
Tensorflow 自定义loss的情况下初始化部分变量方式
2020/01/06 Python
使用PyTorch实现MNIST手写体识别代码
2020/01/18 Python
《列夫托尔斯泰》教学反思
2014/02/10 职场文书
演讲稿格式范文
2014/05/19 职场文书
平安建设工作方案
2014/06/02 职场文书
服务员岗位职责范本
2015/04/09 职场文书
戒赌保证书
2015/05/11 职场文书
python中Pyqt5使用Qlabel标签播放视频
2022/04/22 Python