亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

python深度學(xué)習(xí)tensorflow1.0參數(shù)初始化initializer

 更新時(shí)間:2022年06月29日 16:26:53   作者:denny402  
這篇文章主要為大家介紹了python深度學(xué)習(xí)tensorflow1.0參數(shù)初始化initializer示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

正文

CNN中最重要的就是參數(shù)了,包括W,b。 我們訓(xùn)練CNN的最終目的就是得到最好的參數(shù),使得目標(biāo)函數(shù)取得最小值。參數(shù)的初始化也同樣重要,因此微調(diào)受到很多人的重視,那么tf提供了哪些初始化參數(shù)的方法呢,我們能不能自己進(jìn)行初始化呢?

所有初始化方法定義

# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Operations often used for initializing tensors.
All variable initializers returned by functions in this file should have the
following signature:
def _initializer(shape, dtype=dtypes.float32, partition_info=None):
  Args:
    shape: List of `int` representing the shape of the output `Tensor`. Some
      initializers may also be able to accept a `Tensor`.
    dtype: (Optional) Type of the output `Tensor`.
    partition_info: (Optional) variable_scope._PartitionInfo object holding
      additional information about how the variable is partitioned. May be
      `None` if the variable is not partitioned.
  Returns:
    A `Tensor` of type `dtype` and `shape`.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import math
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import linalg_ops
from tensorflow.python.ops import random_ops
class Initializer(object):
  """Initializer base class: all initializers inherit from this class.
  """
  def __call__(self, shape, dtype=None, partition_info=None):
    raise NotImplementedError
class Zeros(Initializer):
  """Initializer that generates tensors initialized to 0."""
  def __init__(self, dtype=dtypes.float32):
    self.dtype = dtype
  def __call__(self, shape, dtype=None, partition_info=None):
    if dtype is None:
      dtype = self.dtype
    return constant_op.constant(False if dtype is dtypes.bool else 0,
                                dtype=dtype, shape=shape)
class Ones(Initializer):
  """Initializer that generates tensors initialized to 1."""
  def __init__(self, dtype=dtypes.float32):
    self.dtype = dtype
  def __call__(self, shape, dtype=None, partition_info=None):
    if dtype is None:
      dtype = self.dtype
    return constant_op.constant(1, dtype=dtype, shape=shape)
class Constant(Initializer):
  """Initializer that generates tensors with constant values.
  The resulting tensor is populated with values of type `dtype`, as
  specified by arguments `value` following the desired `shape` of the
  new tensor (see examples below).
  The argument `value` can be a constant value, or a list of values of type
  `dtype`. If `value` is a list, then the length of the list must be less
  than or equal to the number of elements implied by the desired shape of the
  tensor. In the case where the total number of elements in `value` is less
  than the number of elements required by the tensor shape, the last element
  in `value` will be used to fill the remaining entries. If the total number of
  elements in `value` is greater than the number of elements required by the
  tensor shape, the initializer will raise a `ValueError`.
  Args:
    value: A Python scalar, list of values, or a N-dimensional numpy array. All
      elements of the initialized variable will be set to the corresponding
      value in the `value` argument.
    dtype: The data type.
    verify_shape: Boolean that enables verification of the shape of `value`. If
      `True`, the initializer will throw an error if the shape of `value` is not
      compatible with the shape of the initialized tensor.
  Examples:
    The following example can be rewritten using a numpy.ndarray instead
    of the `value` list, even reshaped, as shown in the two commented lines
    below the `value` list initialization.
  ```python
    >>> import numpy as np
    >>> import tensorflow as tf
    >>> value = [0, 1, 2, 3, 4, 5, 6, 7]
    >>> # value = np.array(value)
    >>> # value = value.reshape([2, 4])
    >>> init = tf.constant_initializer(value)
    >>> print('fitting shape:')
    >>> with tf.Session():
    >>>   x = tf.get_variable('x', shape=[2, 4], initializer=init)
    >>>   x.initializer.run()
    >>>   print(x.eval())
    fitting shape:
    [[ 0.  1.  2.  3.]
     [ 4.  5.  6.  7.]]
    >>> print('larger shape:')
    >>> with tf.Session():
    >>>   x = tf.get_variable('x', shape=[3, 4], initializer=init)
    >>>   x.initializer.run()
    >>>   print(x.eval())
    larger shape:
    [[ 0.  1.  2.  3.]
     [ 4.  5.  6.  7.]
     [ 7.  7.  7.  7.]]
    >>> print('smaller shape:')
    >>> with tf.Session():
    >>>   x = tf.get_variable('x', shape=[2, 3], initializer=init)
    ValueError: Too many elements provided. Needed at most 6, but received 8
    >>> print('shape verification:')
    >>> init_verify = tf.constant_initializer(value, verify_shape=True)
    >>> with tf.Session():
    >>>   x = tf.get_variable('x', shape=[3, 4], initializer=init_verify)
    TypeError: Expected Tensor's shape: (3, 4), got (8,).
  ```
  """
  def __init__(self, value=0, dtype=dtypes.float32, verify_shape=False):
    self.value = value
    self.dtype = dtype
    self.verify_shape = verify_shape
  def __call__(self, shape, dtype=None, partition_info=None):
    if dtype is None:
      dtype = self.dtype
    return constant_op.constant(self.value, dtype=dtype, shape=shape,
                                verify_shape=self.verify_shape)
class RandomUniform(Initializer):
  """Initializer that generates tensors with a uniform distribution.
  Args:
    minval: A python scalar or a scalar tensor. Lower bound of the range
      of random values to generate.
    maxval: A python scalar or a scalar tensor. Upper bound of the range
      of random values to generate.  Defaults to 1 for float types.
    seed: A Python integer. Used to create random seeds. See
      @{tf.set_random_seed}
      for behavior.
    dtype: The data type.
  """
  def __init__(self, minval=0, maxval=None, seed=None, dtype=dtypes.float32):
    self.minval = minval
    self.maxval = maxval
    self.seed = seed
    self.dtype = dtype
  def __call__(self, shape, dtype=None, partition_info=None):
    if dtype is None:
      dtype = self.dtype
    return random_ops.random_uniform(shape, self.minval, self.maxval,
                                     dtype, seed=self.seed)
class RandomNormal(Initializer):
  """Initializer that generates tensors with a normal distribution.
  Args:
    mean: a python scalar or a scalar tensor. Mean of the random values
      to generate.
    stddev: a python scalar or a scalar tensor. Standard deviation of the
      random values to generate.
    seed: A Python integer. Used to create random seeds. See
      @{tf.set_random_seed}
      for behavior.
    dtype: The data type. Only floating point types are supported.
  """
  def __init__(self, mean=0.0, stddev=1.0, seed=None, dtype=dtypes.float32):
    self.mean = mean
    self.stddev = stddev
    self.seed = seed
    self.dtype = _assert_float_dtype(dtype)
  def __call__(self, shape, dtype=None, partition_info=None):
    if dtype is None:
      dtype = self.dtype
    return random_ops.random_normal(shape, self.mean, self.stddev,
                                    dtype, seed=self.seed)
class TruncatedNormal(Initializer):
  """Initializer that generates a truncated normal distribution.
  These values are similar to values from a `random_normal_initializer`
  except that values more than two standard deviations from the mean
  are discarded and re-drawn. This is the recommended initializer for
  neural network weights and filters.
  Args:
    mean: a python scalar or a scalar tensor. Mean of the random values
      to generate.
    stddev: a python scalar or a scalar tensor. Standard deviation of the
      random values to generate.
    seed: A Python integer. Used to create random seeds. See
      @{tf.set_random_seed}
      for behavior.
    dtype: The data type. Only floating point types are supported.
  """
  def __init__(self, mean=0.0, stddev=1.0, seed=None, dtype=dtypes.float32):
    self.mean = mean
    self.stddev = stddev
    self.seed = seed
    self.dtype = _assert_float_dtype(dtype)
  def __call__(self, shape, dtype=None, partition_info=None):
    if dtype is None:
      dtype = self.dtype
    return random_ops.truncated_normal(shape, self.mean, self.stddev,
                                       dtype, seed=self.seed)
class UniformUnitScaling(Initializer):
  """Initializer that generates tensors without scaling variance.
  When initializing a deep network, it is in principle advantageous to keep
  the scale of the input variance constant, so it does not explode or diminish
  by reaching the final layer. If the input is `x` and the operation `x * W`,
  and we want to initialize `W` uniformly at random, we need to pick `W` from
      [-sqrt(3) / sqrt(dim), sqrt(3) / sqrt(dim)]
  to keep the scale intact, where `dim = W.shape[0]` (the size of the input).
  A similar calculation for convolutional networks gives an analogous result
  with `dim` equal to the product of the first 3 dimensions.  When
  nonlinearities are present, we need to multiply this by a constant `factor`.
  See [Sussillo et al., 2014](https://arxiv.org/abs/1412.6558)
  ([pdf](http://arxiv.org/pdf/1412.6558.pdf)) for deeper motivation, experiments
  and the calculation of constants. In section 2.3 there, the constants were
  numerically computed: for a linear layer it's 1.0, relu: ~1.43, tanh: ~1.15.
  Args:
    factor: Float.  A multiplicative factor by which the values will be scaled.
    seed: A Python integer. Used to create random seeds. See
      @{tf.set_random_seed}
      for behavior.
    dtype: The data type. Only floating point types are supported.
  """
  def __init__(self, factor=1.0, seed=None, dtype=dtypes.float32):
    self.factor = factor
    self.seed = seed
    self.dtype = _assert_float_dtype(dtype)
  def __call__(self, shape, dtype=None, partition_info=None):
    if dtype is None:
      dtype = self.dtype
    scale_shape = shape
    if partition_info is not None:
      scale_shape = partition_info.full_shape
    input_size = 1.0
    # Estimating input size is not possible to do perfectly, but we try.
    # The estimate, obtained by multiplying all dimensions but the last one,
    # is the right thing for matrix multiply and convolutions (see above).
    for dim in scale_shape[:-1]:
      input_size *= float(dim)
    # Avoid errors when initializing zero-size tensors.
    input_size = max(input_size, 1.0)
    max_val = math.sqrt(3 / input_size) * self.factor
    return random_ops.random_uniform(shape, -max_val, max_val,
                                     dtype, seed=self.seed)
class VarianceScaling(Initializer):
  """Initializer capable of adapting its scale to the shape of weights tensors.
  With `distribution="normal"`, samples are drawn from a truncated normal
  distribution centered on zero, with `stddev = sqrt(scale / n)`
  where n is:
    - number of input units in the weight tensor, if mode = "fan_in"
    - number of output units, if mode = "fan_out"
    - average of the numbers of input and output units, if mode = "fan_avg"
  With `distribution="uniform"`, samples are drawn from a uniform distribution
  within [-limit, limit], with `limit = sqrt(3 * scale / n)`.
  Arguments:
    scale: Scaling factor (positive float).
    mode: One of "fan_in", "fan_out", "fan_avg".
    distribution: Random distribution to use. One of "normal", "uniform".
    seed: A Python integer. Used to create random seeds. See
      @{tf.set_random_seed}
      for behavior.
    dtype: The data type. Only floating point types are supported.
  Raises:
    ValueError: In case of an invalid value for the "scale", mode" or
      "distribution" arguments.
  """
  def __init__(self, scale=1.0,
               mode="fan_in",
               distribution="normal",
               seed=None,
               dtype=dtypes.float32):
    if scale <= 0.:
      raise ValueError("`scale` must be positive float.")
    if mode not in {"fan_in", "fan_out", "fan_avg"}:
      raise ValueError("Invalid `mode` argument:", mode)
    distribution = distribution.lower()
    if distribution not in {"normal", "uniform"}:
      raise ValueError("Invalid `distribution` argument:", distribution)
    self.scale = scale
    self.mode = mode
    self.distribution = distribution
    self.seed = seed
    self.dtype = _assert_float_dtype(dtype)
  def __call__(self, shape, dtype=None, partition_info=None):
    if dtype is None:
      dtype = self.dtype
    scale = self.scale
    scale_shape = shape
    if partition_info is not None:
      scale_shape = partition_info.full_shape
    fan_in, fan_out = _compute_fans(scale_shape)
    if self.mode == "fan_in":
      scale /= max(1., fan_in)
    elif self.mode == "fan_out":
      scale /= max(1., fan_out)
    else:
      scale /= max(1., (fan_in + fan_out) / 2.)
    if self.distribution == "normal":
      stddev = math.sqrt(scale)
      return random_ops.truncated_normal(shape, 0.0, stddev,
                                         dtype, seed=self.seed)
    else:
      limit = math.sqrt(3.0 * scale)
      return random_ops.random_uniform(shape, -limit, limit,
                                       dtype, seed=self.seed)
class Orthogonal(Initializer):
  """Initializer that generates an orthogonal matrix.
  If the shape of the tensor to initialize is two-dimensional, i is initialized
  with an orthogonal matrix obtained from the singular value decomposition of a
  matrix of uniform random numbers.
  If the shape of the tensor to initialize is more than two-dimensional,
  a matrix of shape `(shape[0] * ... * shape[n - 2], shape[n - 1])`
  is initialized, where `n` is the length of the shape vector.
  The matrix is subsequently reshaped to give a tensor of the desired shape.
  Args:
    gain: multiplicative factor to apply to the orthogonal matrix
    dtype: The type of the output.
    seed: A Python integer. Used to create random seeds. See
      @{tf.set_random_seed}
      for behavior.
  """
  def __init__(self, gain=1.0, dtype=dtypes.float32, seed=None):
    self.gain = gain
    self.dtype = _assert_float_dtype(dtype)
    self.seed = seed
  def __call__(self, shape, dtype=None, partition_info=None):
    if dtype is None:
      dtype = self.dtype
    # Check the shape
    if len(shape) < 2:
      raise ValueError("The tensor to initialize must be "
                       "at least two-dimensional")
    # Flatten the input shape with the last dimension remaining
    # its original shape so it works for conv2d
    num_rows = 1
    for dim in shape[:-1]:
      num_rows *= dim
    num_cols = shape[-1]
    flat_shape = (num_rows, num_cols)
    # Generate a random matrix
    a = random_ops.random_uniform(flat_shape, dtype=dtype, seed=self.seed)
    # Compute the svd
    _, u, v = linalg_ops.svd(a, full_matrices=False)
    # Pick the appropriate singular value decomposition
    if num_rows > num_cols:
      q = u
    else:
      # Tensorflow departs from numpy conventions
      # such that we need to transpose axes here
      q = array_ops.transpose(v)
    return self.gain * array_ops.reshape(q, shape)
# Aliases.
# pylint: disable=invalid-name
zeros_initializer = Zeros
ones_initializer = Ones
constant_initializer = Constant
random_uniform_initializer = RandomUniform
random_normal_initializer = RandomNormal
truncated_normal_initializer = TruncatedNormal
uniform_unit_scaling_initializer = UniformUnitScaling
variance_scaling_initializer = VarianceScaling
orthogonal_initializer = Orthogonal
# pylint: enable=invalid-name
def glorot_uniform_initializer(seed=None, dtype=dtypes.float32):
  """The Glorot uniform initializer, also called Xavier uniform initializer.
  It draws samples from a uniform distribution within [-limit, limit]
  where `limit` is `sqrt(6 / (fan_in + fan_out))`
  where `fan_in` is the number of input units in the weight tensor
  and `fan_out` is the number of output units in the weight tensor.
  Reference: http://jmlr.org/proceedings/papers/v9/glorot10a/glorot10a.pdf
  Arguments:
    seed: A Python integer. Used to create random seeds. See
      @{tf.set_random_seed}
      for behavior.
    dtype: The data type. Only floating point types are supported.
  Returns:
    An initializer.
  """
  return variance_scaling_initializer(scale=1.0,
                                      mode="fan_avg",
                                      distribution="uniform",
                                      seed=seed,
                                      dtype=dtype)
def glorot_normal_initializer(seed=None, dtype=dtypes.float32):
  """The Glorot normal initializer, also called Xavier normal initializer.
  It draws samples from a truncated normal distribution centered on 0
  with `stddev = sqrt(2 / (fan_in + fan_out))`
  where `fan_in` is the number of input units in the weight tensor
  and `fan_out` is the number of output units in the weight tensor.
  Reference: http://jmlr.org/proceedings/papers/v9/glorot10a/glorot10a.pdf
  Arguments:
    seed: A Python integer. Used to create random seeds. See
      @{tf.set_random_seed}
      for behavior.
    dtype: The data type. Only floating point types are supported.
  Returns:
    An initializer.
  """
  return variance_scaling_initializer(scale=1.0,
                                      mode="fan_avg",
                                      distribution="normal",
                                      seed=seed,
                                      dtype=dtype)
# Utility functions.
def _compute_fans(shape):
  """Computes the number of input and output units for a weight shape.
  Arguments:
    shape: Integer shape tuple or TF tensor shape.
  Returns:
    A tuple of scalars (fan_in, fan_out).
  """
  if len(shape) < 1:  # Just to avoid errors for constants.
    fan_in = fan_out = 1
  elif len(shape) == 1:
    fan_in = fan_out = shape[0]
  elif len(shape) == 2:
    fan_in = shape[0]
    fan_out = shape[1]
  else:
    # Assuming convolution kernels (2D, 3D, or more).
    # kernel shape: (..., input_depth, depth)
    receptive_field_size = 1.
    for dim in shape[:-2]:
      receptive_field_size *= dim
    fan_in = shape[-2] * receptive_field_size
    fan_out = shape[-1] * receptive_field_size
  return fan_in, fan_out
def _assert_float_dtype(dtype):
  """Validate and return floating point type based on `dtype`.
  `dtype` must be a floating point type.
  Args:
    dtype: The data type to validate.
  Returns:
    Validated type.
  Raises:
    ValueError: if `dtype` is not a floating point type.
  """
  if not dtype.is_floating:
    raise ValueError("Expected floating point type, got %s." % dtype)
  return dtype

1、tf.constant_initializer()

也可以簡(jiǎn)寫(xiě)為tf.Constant()

初始化為常數(shù),這個(gè)非常有用,通常偏置項(xiàng)就是用它初始化的。

由它衍生出的兩個(gè)初始化方法:

a、 tf.zeros_initializer(), 也可以簡(jiǎn)寫(xiě)為tf.Zeros()

b、tf.ones_initializer(), 也可以簡(jiǎn)寫(xiě)為tf.Ones()

例:在卷積層中,將偏置項(xiàng)b初始化為0,則有多種寫(xiě)法:

conv1 = tf.layers.conv2d(batch_images, 
                         filters=64,
                         kernel_size=7,
                         strides=2,
                         activation=tf.nn.relu,
                         kernel_initializer=tf.TruncatedNormal(stddev=0.01)
                         bias_initializer=tf.Constant(0),
                        )

或者:

bias_initializer=tf.constant_initializer(0)

或者:

bias_initializer=tf.zeros_initializer()

或者:

bias_initializer=tf.Zeros()

例:如何將W初始化成拉普拉斯算子?

value = [1, 1, 1, 1, -8, 1, 1, 1,1]
init = tf.constant_initializer(value)
W= tf.get_variable('W', shape=[3, 3], initializer=init)

2、tf.truncated_normal_initializer()

或者簡(jiǎn)寫(xiě)為tf.TruncatedNormal()

生成截?cái)嗾龖B(tài)分布的隨機(jī)數(shù),這個(gè)初始化方法好像在tf中用得比較多。

它有四個(gè)參數(shù)(mean=0.0, stddev=1.0, seed=None, dtype=dtypes.float32),分別用于指定均值、標(biāo)準(zhǔn)差、隨機(jī)數(shù)種子和隨機(jī)數(shù)的數(shù)據(jù)類型,一般只需要設(shè)置stddev這一個(gè)參數(shù)就可以了。

例:

conv1 = tf.layers.conv2d(batch_images, 
                         filters=64,
                         kernel_size=7,
                         strides=2,
                         activation=tf.nn.relu,
                         kernel_initializer=tf.TruncatedNormal(stddev=0.01)
                         bias_initializer=tf.Constant(0),
                        )

或者:

conv1 = tf.layers.conv2d(batch_images, 
                         filters=64,
                         kernel_size=7,
                         strides=2,
                         activation=tf.nn.relu,
                         kernel_initializer=tf.truncated_normal_initializer(stddev=0.01)
                         bias_initializer=tf.zero_initializer(),
                        )

3、tf.random_normal_initializer()

可簡(jiǎn)寫(xiě)為 tf.RandomNormal()

生成標(biāo)準(zhǔn)正態(tài)分布的隨機(jī)數(shù),參數(shù)和truncated_normal_initializer一樣。

4、random_uniform_initializer = RandomUniform()

可簡(jiǎn)寫(xiě)為tf.RandomUniform()

生成均勻分布的隨機(jī)數(shù),參數(shù)有四個(gè)(minval=0, maxval=None, seed=None, dtype=dtypes.float32),分別用于指定最小值,最大值,隨機(jī)數(shù)種子和類型。

5、tf.uniform_unit_scaling_initializer()

可簡(jiǎn)寫(xiě)為tf.UniformUnitScaling()

和均勻分布差不多,只是這個(gè)初始化方法不需要指定最小最大值,是通過(guò)計(jì)算出來(lái)的。參數(shù)為(factor=1.0, seed=None, dtype=dtypes.float32)

max_val = math.sqrt(3 / input_size) * factor

這里的input_size是指輸入數(shù)據(jù)的維數(shù),假設(shè)輸入為x, 運(yùn)算為x * W,則input_size= W.shape[0]

它的分布區(qū)間為[ -max_val, max_val]

6、tf.variance_scaling_initializer()

可簡(jiǎn)寫(xiě)為tf.VarianceScaling()

參數(shù)為(scale=1.0,mode="fan_in",distribution="normal",seed=None,dtype=dtypes.float32)

scale: 縮放尺度(正浮點(diǎn)數(shù))

mode:  "fan_in", "fan_out", "fan_avg"中的一個(gè),用于計(jì)算標(biāo)準(zhǔn)差stddev的值。

distribution:分布類型,"normal"或“uniform"中的一個(gè)。

當(dāng) distribution="normal" 的時(shí)候,生成truncated normal   distribution(截?cái)嗾龖B(tài)分布) 的隨機(jī)數(shù),其中stddev = sqrt(scale / n) ,n的計(jì)算與mode參數(shù)有關(guān)。

  • 如果mode = "fan_in", n為輸入單元的結(jié)點(diǎn)數(shù);         
  • 如果mode = "fan_out",n為輸出單元的結(jié)點(diǎn)數(shù);
  • 如果mode = "fan_avg",n為輸入和輸出單元結(jié)點(diǎn)數(shù)的平均值。

當(dāng)distribution="uniform”的時(shí)候 ,生成均勻分布的隨機(jī)數(shù),假設(shè)分布區(qū)間為[-limit, limit],則

limit = sqrt(3 * scale / n)

7、tf.orthogonal_initializer()

簡(jiǎn)寫(xiě)為tf.Orthogonal()

生成正交矩陣的隨機(jī)數(shù)。

當(dāng)需要生成的參數(shù)是2維時(shí),這個(gè)正交矩陣是由均勻分布的隨機(jī)數(shù)矩陣經(jīng)過(guò)SVD分解而來(lái)。

8、tf.glorot_uniform_initializer()

也稱之為Xavier uniform initializer,由一個(gè)均勻分布(uniform distribution)來(lái)初始化數(shù)據(jù)。

假設(shè)均勻分布的區(qū)間是[-limit, limit],則

limit=sqrt(6 / (fan_in + fan_out))

其中的fan_in和fan_out分別表示輸入單元的結(jié)點(diǎn)數(shù)和輸出單元的結(jié)點(diǎn)數(shù)。

9、glorot_normal_initializer()

也稱之為 Xavier normal initializer. 由一個(gè) truncated normal distribution來(lái)初始化數(shù)據(jù).

stddev = sqrt(2 / (fan_in + fan_out))

其中的fan_in和fan_out分別表示輸入單元的結(jié)點(diǎn)數(shù)和輸出單元的結(jié)點(diǎn)數(shù)。

以上就是python深度學(xué)習(xí)tensorflow1.0參數(shù)初始化initializer的詳細(xì)內(nèi)容,更多關(guān)于python tensorflow1.0參數(shù)initializer的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • python文件和文件夾復(fù)制函數(shù)

    python文件和文件夾復(fù)制函數(shù)

    這篇文章主要為大家詳細(xì)介紹了python文件和文件夾復(fù)制函數(shù)的實(shí)現(xiàn)代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-02-02
  • TensorFlow高效讀取數(shù)據(jù)的方法示例

    TensorFlow高效讀取數(shù)據(jù)的方法示例

    這篇文章主要介紹了TensorFlow高效讀取數(shù)據(jù)的方法示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-02-02
  • python中threading.Semaphore和threading.Lock的具體使用

    python中threading.Semaphore和threading.Lock的具體使用

    python中的多線程是一個(gè)非常重要的知識(shí)點(diǎn),本文主要介紹了python中threading.Semaphore和threading.Lock的具體使用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2023-08-08
  • 玩轉(zhuǎn)python爬蟲(chóng)之URLError異常處理

    玩轉(zhuǎn)python爬蟲(chóng)之URLError異常處理

    這篇文章主要介紹了python爬蟲(chóng)的URLError異常處理,詳細(xì)探尋一下URL\HTTP異常處理的相關(guān)內(nèi)容,通過(guò)一些具體的實(shí)例來(lái)分析一下,非常的簡(jiǎn)單,但是卻很實(shí)用,感興趣的小伙伴們可以參考一下
    2016-02-02
  • python中將函數(shù)賦值給變量時(shí)需要注意的一些問(wèn)題

    python中將函數(shù)賦值給變量時(shí)需要注意的一些問(wèn)題

    變量賦值是我們?cè)谌粘i_(kāi)發(fā)中經(jīng)常會(huì)遇到的一個(gè)問(wèn)題,下面這篇文章主要給大家介紹了關(guān)于python中將函數(shù)賦值給變量時(shí)需要注意的一些問(wèn)題,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧。
    2017-08-08
  • 在Python中實(shí)現(xiàn)決策樹(shù)算法的示例代碼

    在Python中實(shí)現(xiàn)決策樹(shù)算法的示例代碼

    決策樹(shù)(Decision Tree)是一種常見(jiàn)的機(jī)器學(xué)習(xí)算法,被廣泛應(yīng)用于分類和回歸任務(wù)中,并且再其之上的隨機(jī)森林和提升樹(shù)等算法一直是表格領(lǐng)域的最佳模型,所以本文將介紹理解其數(shù)學(xué)概念,并在Python中動(dòng)手實(shí)現(xiàn),這可以作為了解這類算法的基礎(chǔ)知識(shí)
    2023-08-08
  • python模塊導(dǎo)入方式淺析步驟

    python模塊導(dǎo)入方式淺析步驟

    這篇文章主要為大家介紹了python中模塊導(dǎo)入的方式,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10
  • 使用pandas或numpy處理數(shù)據(jù)中的空值(np.isnan()/pd.isnull())

    使用pandas或numpy處理數(shù)據(jù)中的空值(np.isnan()/pd.isnull())

    這篇文章主要介紹了使用pandas或numpy處理數(shù)據(jù)中的空值(np.isnan()/pd.isnull()),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-05-05
  • Python 列表篩選數(shù)據(jù)詳解

    Python 列表篩選數(shù)據(jù)詳解

    這篇文章主要為大家介紹了Python 列表篩選數(shù)據(jù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2021-11-11
  • Python Tkinter對(duì)話框控件使用詳解

    Python Tkinter對(duì)話框控件使用詳解

    Tkinter中提供了三種對(duì)話框控件:文件選擇對(duì)話框、顏色選擇對(duì)話框和消息對(duì)話框。本文將具體為大家介紹一下這三種對(duì)話框的使用,需要的可以參考一下
    2022-01-01

最新評(píng)論