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


猜你喜欢
- APNS 是苹果为IOS设备提供的推送服务,全称是(Apple Push Notification service)。 如果你有接触移动互联
- 异常对象Python中遇到错误后,会引发异常。Python中使用异常对象来表示异常情况。如果异常对象未被处理或者捕捉,程序就会用所谓的回溯(
- 本文实例为大家分享了python实现图书管理系统的具体代码,供大家参考,具体内容如下添加新书查询借阅二次添加新书(读取已有的.xls并修改)
- 准备阶段我们需要安装pyautogui调用库(在命令提示符下安装pyautogui建议配置一个镜像源)pip install pyautog
- 机房一台服务器上的mysql运行一段时间了,突然出现了一个很奇怪的现象:重启后无法恢复了!准确情况是:启动mysql后随即就又关闭了。查看m
- MySQL密码正确却无法本地登录-1045 Access denied for user 'root'@'local
- 说明1、在使用之前需要在settings中打开。2、pipeline在settings中键表示位置(即pipeline在项目中的位置可以自定
- 本文实例讲述了php购物车实现方法。分享给大家供大家参考。具体分析如下:这里我们为你提供个简单的php购物车代码,从增加购物产品与发生购买了
- 概述 一、 初识setup函数 组件中所用到的:数据、方法等等均要配置在setup中,这也就意味着在Vue2中写的dat
- Python 处理数据的实例详解最近用python(3.2的版本)写了根据特定规则,处理数据的一个小程序,用到了一些python常用的基础知
- 问题描述在某些问题背景下,需要确认是否多台终端在线,也就是会使用我们牛逼的ping这个命令,做一些的ping操作,如果需要确认的设备比较少,
- 创建项目首先打开Pycharm勾选I confirm that I have read and accept the terms of th
- 本文实例讲述了Python3多进程 multiprocessing 模块。分享给大家供大家参考,具体如下:多进程 Multiprocessi
- 什么是 PiniaPinia (西班牙语中的菠萝),本质上依然是一个状态管理的库,用于跨组件、页面进行状态共享.pinia 与 vuex 的
- 关于Python语言,众说纷纭,但无外乎两种,强大,垃圾。大多数人还是对Python持肯定意见,认为它很强大。前些天和两个的大学同学聊天,一
- 要使用request对象的ServerVariables属性,通过它来获得环境变量的值。使用的语法为:Request.ServerVaria
- 网上找了半天都找不到好用的PyQt5无边框窗口的实现,借鉴部分前辈的窗口拖放代码,自己实现了一下无边框窗口,问题可能还有一点,慢慢改吧 先做
- 首先总结的意义就是让杂乱无章变得更加井然有序,这样在使用的过程思路会更加清晰。数组使用方法注意点:变异方法和非变异方法。即变异方法使用会改变
- 业务背景最近接到一个需求,在微信公众号界面设计一个独立界面,界面上有 A 电机进、A 电机退、B 电机进、B 电机退 4 个按钮,点击对应按
- 闭包闭包就是能够读取其他函数内部变量的函数。def test1(k, b): def test1_1(x): &n