网络编程
位置:首页>> 网络编程>> Python编程>> TensorFlow中权重的随机初始化的方法

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

作者:松松的鞋带儿  发布时间:2023-01-02 06:11:32 

标签:tensorflow,权重,初始化

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

来源:https://www.cnblogs.com/dcsds1/p/5203764.html

0
投稿

猜你喜欢

  • 本文实例讲述了Python实现抓取HTML网页并以PDF文件形式保存的方法。分享给大家供大家参考,具体如下:一、前言今天介绍将HTML网页抓
  • 首先给大家介绍ThinkPHP函数详解:M方法M方法用于实例化一个基础模型类,和D方法的区别在于:1、不需要自定义模型类,减少IO加载,性能
  • 阅读上一篇:一个完美网站的101项指标.第六部分.性能 符合 W3C 标准是网站的发展趋势,目前,几乎所有的浏览器都使用 W3C 标准,W3
  • 这问题在网络相信已经有不少人问到,最近再次被牵起讨论,籍此记录一下个人的理解,border:none;与border:0;的区别体现有两点:
  • 有过相关经验的朋友都知道,Jscript的效率毕竟有限,在数组中查找数据时如果用常规的算法来做执行起来会很慢。例如在一个含500个字符串的d
  • 本文实例讲述了Python三元运算实现方法。分享给大家供大家参考。具体分析如下:Python中没有像C++和Java等语言中的三元运算符,但
  • 1. 截取GB2312中文字符串 <?php //截取中文字符串 function mysubstr($str, $star
  • ASP通过XMLDom在服务器端操作XML文件的主要方法和实现对于小数据量,xml文件在检索更新上于ACCESS有很多优势。我曾经测试过不用
  • 数组:复制传递(不要按照c/c++的方式去理解,c/c++中数组是引用传递),定长切片:引用传递,底层实现是3个字段 array(数组) +
  • #python中的函数定义,使用和传参###------------------- 必要参数 -----------------------
  • 看到网上有一篇文章,是介绍如何做网站测试的.从一开始的链接测试,页面内容测试,到浏览器兼容性测试,负载压力测试,一直到最后的安全性测试,甚至
  • 本文实例为大家分享了python matlibplot绘制3D图形的具体代码,供大家参考,具体内容如下1、散点图使用scatterfrom
  • 操作系统会为每一个创建的进程分配一个独立的地址空间,不同进程的地址空间是完全隔离的,因此如果不加其他的措施,他们完全感觉不到彼此的存在。那么
  • oracle数据库的快照是一个表,它包含有对一个本地或远程数据库上一个或多个表或视图的查询的结果。正因为快照是一个主表的查询子集,使用快照可
  • 阅读《YUI学习笔记(1)》YAHOO.lang.dump 与 YAHOO.lang.substitute。1.&nbs
  • 有些网页制 * 好者提出了这样一个问题——怎么使用Dreamweaver制作出交换图像来。今天,我向大家介绍制作复杂交换图像的方法,相信能够对
  • SQL语句更改表所有者SQL语句更改表所有者单个修改所有者sql语句如下:查询分析器输入:EXEC sp_changeobject
  •     字体的处理在网页设计中无论怎么强调也不为过,毕竟网页使用来传递信息的,而最经典最直接的信息传递方式就是
  • 正则表达式在 PHP 中的应用在 PHP 应用中,正则表达式主要用于:•正则匹配:根据正则表达式匹配相应的内容•正则替换:根据正则表达式匹配
  • 学设计模式中有个装饰模式,用java实现起来不是很难,但是远远没有python简单,难怪越来越火了!这里就简单讨论下python的几种装饰模
手机版 网络编程 asp之家 www.aspxhome.com