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列表去重的二种方法
Feb 14 Python
Python连接mysql数据库的正确姿势
Feb 03 Python
Python中使用bidict模块双向字典结构的奇技淫巧
Jul 12 Python
Python学习小技巧之列表项的推导式与过滤操作
May 20 Python
Python基于更相减损术实现求解最大公约数的方法
Apr 04 Python
基于anaconda下强大的conda命令介绍
Jun 11 Python
pyqt5中QThread在使用时出现重复emit的实例
Jun 21 Python
Python中的几种矩阵乘法(小结)
Jul 10 Python
Tensorflow训练MNIST手写数字识别模型
Feb 13 Python
使用opencv识别图像红色区域,并输出红色区域中心点坐标
Jun 02 Python
基于python实现监听Rabbitmq系统日志代码示例
Nov 28 Python
分享提高 Python 代码的可读性的技巧
Mar 03 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 分页函数multi() discuz
2009/06/21 PHP
ThinkPHP自动验证失败的解决方法
2011/06/09 PHP
百度地图API应用之获取用户的具体位置
2014/06/10 PHP
ThinkPHP3.2.3框架实现执行原生SQL语句的方法示例
2019/04/03 PHP
PHP中遍历数组的三种常用方法实例分析
2019/06/24 PHP
编写兼容IE和FireFox的脚本
2009/05/18 Javascript
使用jQuery的将桌面应用程序引入浏览器
2010/11/19 Javascript
D3.js 从P元素的创建开始(显示可加载数据)
2014/10/30 Javascript
Bootstrap模态对话框的简单使用
2016/04/29 Javascript
JavaScript实现in-place思想的快速排序方法
2016/08/07 Javascript
很棒的vue弹窗组件
2017/05/24 Javascript
bootstrap基本配置_动力节点Java学院整理
2017/07/14 Javascript
jQuery实现菜单栏导航效果
2017/08/15 jQuery
详解Vue项目部署遇到的问题及解决方案
2019/01/11 Javascript
小程序登录/注册页面设计的实现代码
2019/05/24 Javascript
详解javascript中var与ES6规范中let、const区别与用法
2020/01/11 Javascript
在vue中给后台接口传的值为数组的格式代码
2020/11/12 Javascript
[00:32]DOTA2上海特级锦标赛 COL战队宣传片
2016/03/04 DOTA
python使用PyGame播放Midi和Mp3文件的方法
2015/04/24 Python
Python3结合Dlib实现人脸识别和剪切
2018/01/24 Python
python实现dijkstra最短路由算法
2019/01/17 Python
Tensorflow实现酸奶销量预测分析
2019/07/19 Python
在tensorflow以及keras安装目录查询操作(windows下)
2020/06/19 Python
基于HTML5实现类似微信手机摇一摇功能(计算摇动次数)
2017/07/24 HTML / CSS
处理textarea中的换行和空格
2019/12/12 HTML / CSS
英国天然有机美容护肤品:Neal’s Yard Remedies
2018/05/05 全球购物
法学院方阵解说词
2014/01/29 职场文书
商务日语专业的自荐信
2014/05/23 职场文书
火箭队口号
2014/06/18 职场文书
大学生个人求职信例文
2014/07/07 职场文书
党支部意见范文
2015/06/02 职场文书
2016年五一国际劳动节活动总结
2016/04/06 职场文书
授权协议书范本(3篇)
2019/10/15 职场文书
Python开发之QT解决无边框界面拖动卡屏问题(附带源码)
2021/05/27 Python
Python语言中的数据类型-序列
2022/02/24 Python
Docker与K8s关系介绍不会Docker也可以使用K8s
2022/06/25 Servers