TensorFlow中權重的隨機初始化的方法
一開始沒看懂stddev是什么參數(shù),找了一下,在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.
"""
也就是按照正態(tài)分布初始化權重,mean是正態(tài)分布的平均值,stddev是正態(tài)分布的標準差(standard deviation),seed是作為分布的random seed(隨機種子,我百度了一下,跟什么偽隨機數(shù)發(fā)生器還有關,就是產生隨機數(shù)的),在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.
"""
截斷正態(tài)分布,以前都沒聽說過。
TensorFlow還提供了平均分布等。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
在Debian下配置Python+Django+Nginx+uWSGI+MySQL的教程
這篇文章主要介紹了在Debian下配置Python+Django+Nginx+uWSGI+MySQL的教程,Debian系統(tǒng)和Nginx服務器皆是高性能的選擇,需要的朋友可以參考下2015-04-04
Python實現(xiàn)暴力破解有密碼的zip文件的方法
這篇文章主要介紹了Python實現(xiàn)暴力破解有密碼的zip文件的方法,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-03-03
numpy.random.shuffle打亂順序函數(shù)的實現(xiàn)
這篇文章主要介紹了numpy.random.shuffle打亂順序函數(shù)的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-09-09

