TensorFlow中权重的随机初始化的方法
作者:松松的鞋带儿 时间:2023-01-02 06:11:32
一开始没看懂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
标签:tensorflow,权重,初始化
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SqlServer表死锁的解决方法分享
2011-09-30 11:16:16
在ASP与ASP.NET之间共享对话状态(2)
2008-09-02 12:21:00
微软补丁KB967723造成MySQL频繁无法连接
2009-11-03 14:28:00
磁盘垃圾文件清理器python代码实现
2023-08-24 23:20:41
![](https://img.aspxhome.com/file/2023/9/60709_0s.jpg)
Python异常处理如何才能写得优雅(retrying模块)
2023-07-13 05:50:44
Python高阶函数与装饰器函数的深入讲解
2023-10-04 12:42:41
![](https://img.aspxhome.com/file/2023/7/63187_0s.png)
ASP截取中英文字符串固定长度
2009-08-19 17:12:00
CSS pointer-events下层元素被点击
2010-04-11 22:31:00
Python使用re模块实现信息筛选的方法
2021-10-10 09:34:46
在pytorch中对非叶节点的变量计算梯度实例
2021-08-26 10:13:53
![](https://img.aspxhome.com/file/2023/2/76852_0s.jpg)
剑走偏锋:体验ebay的AIR
2008-11-13 11:51:00
![](https://img.aspxhome.com/file/UploadPic/200811/13/01-14s.jpg)
讲解Python中fileno()方法的使用
2022-06-28 06:16:12
深入理解typescript中的infer关键字的使用
2023-10-13 19:19:33
在Python文件中指定Python解释器的方法
2023-06-24 13:22:50
Python调用.NET库的方法步骤
2022-07-02 06:46:17
python如何快速生成时间戳
2022-10-26 08:15:41
ASP 统计某字符串中“A”出现过的次数
2010-08-12 10:17:00
PHP实现手机归属地查询API接口实现代码
2023-11-14 09:10:33
在asp中调用sql server的存储过程方法
2007-08-13 13:28:00
![](https://img.aspxhome.com/file/UploadPic/up/2007081313422835.jpg)
读"设计的3个C"之构图
2008-12-24 13:25:00