TensorFlow中权重的随机初始化的方法
一开始没看懂stddev是什么参数,找了一下,在tensorflow/python/ops里有random_ops,其中是这么写的:
defrandom_normal(shape,mean=0.0,stddev=1.0,dtype=types.float32, seed=None,name=None): """Outputsrandomvaluesfromanormaldistribution. Args: shape:A1-DintegerTensororPythonarray.Theshapeoftheoutputtensor. mean:A0-DTensororPythonvalueoftype`dtype`.Themeanofthenormal distribution. stddev:A0-DTensororPythonvalueoftype`dtype`.Thestandarddeviation ofthenormaldistribution. dtype:Thetypeoftheoutput. seed:APythoninteger.Usedtocreatearandomseedforthedistribution. See [`set_random_seed`](../../api_docs/python/constant_op.md#set_random_seed) forbehavior. name:Anamefortheoperation(optional). Returns: Atensorofthespecifiedshapefilledwithrandomnormalvalues. """
也就是按照正态分布初始化权重,mean是正态分布的平均值,stddev是正态分布的标准差(standarddeviation),seed是作为分布的randomseed(随机种子,我百度了一下,跟什么伪随机数发生器还有关,就是产生随机数的),在mnist/concolutional中seed赋值为66478,挺有意思,不知道是什么原理。
后面还有truncated_normal的定义:
deftruncated_normal(shape,mean=0.0,stddev=1.0,dtype=types.float32, seed=None,name=None): """Outputsrandomvaluesfromatruncatednormaldistribution. Thegeneratedvaluesfollowanormaldistributionwithspecifiedmeanand standarddeviation,exceptthatvalueswhosemagnitudeismorethan2standard deviationsfromthemeanaredroppedandre-picked. Args: shape:A1-DintegerTensororPythonarray.Theshapeoftheoutputtensor. mean:A0-DTensororPythonvalueoftype`dtype`.Themeanofthe truncatednormaldistribution. stddev:A0-DTensororPythonvalueoftype`dtype`.Thestandarddeviation ofthetruncatednormaldistribution. dtype:Thetypeoftheoutput. seed:APythoninteger.Usedtocreatearandomseedforthedistribution. See [`set_random_seed`](../../api_docs/python/constant_op.md#set_random_seed) forbehavior. name:Anamefortheoperation(optional). Returns: Atensorofthespecifiedshapefilledwithrandomtruncatednormalvalues. """
截断正态分布,以前都没听说过。
TensorFlow还提供了平均分布等。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。