当前位置: 首页>>代码示例>>Python>>正文


Python initializers.variance_scaling_initializer方法代码示例

本文整理汇总了Python中tensorflow.contrib.layers.python.layers.initializers.variance_scaling_initializer方法的典型用法代码示例。如果您正苦于以下问题:Python initializers.variance_scaling_initializer方法的具体用法?Python initializers.variance_scaling_initializer怎么用?Python initializers.variance_scaling_initializer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow.contrib.layers.python.layers.initializers的用法示例。


在下文中一共展示了initializers.variance_scaling_initializer方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: predictron_arg_scope

# 需要导入模块: from tensorflow.contrib.layers.python.layers import initializers [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.initializers import variance_scaling_initializer [as 别名]
def predictron_arg_scope(weight_decay=0.0001,
                         batch_norm_decay=0.997,
                         batch_norm_epsilon=1e-5,
                         batch_norm_scale=True):
  batch_norm_params = {
    'decay': batch_norm_decay,
    'epsilon': batch_norm_epsilon,
    'scale': batch_norm_scale,
    'updates_collections': tf.GraphKeys.UPDATE_OPS,
  }

  # Set weight_decay for weights in Conv and FC layers.
  with arg_scope(
      [layers.conv2d, layers_lib.fully_connected],
      weights_regularizer=regularizers.l2_regularizer(weight_decay)):
    with arg_scope(
        [layers.conv2d],
        weights_initializer=initializers.variance_scaling_initializer(),
        activation_fn=None,
        normalizer_fn=layers_lib.batch_norm,
        normalizer_params=batch_norm_params) as sc:
      return sc 
开发者ID:zhongwen,项目名称:predictron,代码行数:24,代码来源:util.py

示例2: inception_v2_arg_scope

# 需要导入模块: from tensorflow.contrib.layers.python.layers import initializers [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.initializers import variance_scaling_initializer [as 别名]
def inception_v2_arg_scope(weight_decay=0.00004,
                           batch_norm_var_collection='moving_vars'):
  """Defines the default InceptionV2 arg scope.

  Args:
    weight_decay: The weight decay to use for regularizing the model.
    batch_norm_var_collection: The name of the collection for the batch norm
      variables.

  Returns:
    An `arg_scope` to use for the inception v3 model.
  """
  batch_norm_params = {
      # Decay for the moving averages.
      'decay': 0.9997,
      # epsilon to prevent 0s in variance.
      'epsilon': 0.001,
      # collection containing update_ops.
      'updates_collections': ops.GraphKeys.UPDATE_OPS,
      # collection containing the moving mean and moving variance.
      'variables_collections': {
          'beta': None,
          'gamma': None,
          'moving_mean': [batch_norm_var_collection],
          'moving_variance': [batch_norm_var_collection],
      }
  }

  # Set weight_decay for weights in Conv and FC layers.
  with arg_scope(
      [layers.conv2d, layers_lib.fully_connected],
      weights_regularizer=regularizers.l2_regularizer(weight_decay)):
    with arg_scope(
        [layers.conv2d],
        weights_initializer=initializers.variance_scaling_initializer(),
        activation_fn=nn_ops.relu,
        normalizer_fn=layers_lib.batch_norm,
        normalizer_params=batch_norm_params) as sc:
      return sc 
开发者ID:MingtaoGuo,项目名称:Chinese-Character-and-Calligraphic-Image-Processing,代码行数:41,代码来源:inception_v2.py

示例3: resnet_arg_scope

# 需要导入模块: from tensorflow.contrib.layers.python.layers import initializers [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.initializers import variance_scaling_initializer [as 别名]
def resnet_arg_scope(is_training=True,
                     weight_decay=cfg.TRAIN.WEIGHT_DECAY,
                     batch_norm_decay=0.997,
                     batch_norm_epsilon=1e-5,
                     batch_norm_scale=True):
  batch_norm_params = {
    # NOTE 'is_training' here does not work because inside resnet it gets reset:
    # https://github.com/tensorflow/models/blob/master/slim/nets/resnet_v1.py#L187
    'is_training': False,
    'decay': batch_norm_decay,
    'epsilon': batch_norm_epsilon,
    'scale': batch_norm_scale,
    'trainable': cfg.RESNET.BN_TRAIN,
    'updates_collections': ops.GraphKeys.UPDATE_OPS
  }

  with arg_scope(
      [slim.conv2d],
      weights_regularizer=regularizers.l2_regularizer(weight_decay),
      weights_initializer=initializers.variance_scaling_initializer(),
      trainable=is_training,
      activation_fn=nn_ops.relu,
      normalizer_fn=layers.batch_norm,
      normalizer_params=batch_norm_params):
    with arg_scope([layers.batch_norm], **batch_norm_params) as arg_sc:
      return arg_sc 
开发者ID:pengzhou1108,项目名称:RGB-N,代码行数:28,代码来源:resnet_fusion_noise.py

示例4: linear_mapping_weightnorm

# 需要导入模块: from tensorflow.contrib.layers.python.layers import initializers [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.initializers import variance_scaling_initializer [as 别名]
def linear_mapping_weightnorm(self, inputs, out_dim,
                                var_scope_name="linear",
                                output_collection=None):
    with tf.variable_scope(var_scope_name):
      # pylint: disable=invalid-name
      input_shape = inputs.get_shape().as_list()  # static shape. may has None
      # use weight normalization (Salimans & Kingma, 2016)  w = g* v/2-norm(v)
      V = tf.get_variable(
          name='V',
          shape=[int(input_shape[-1]), out_dim],
          dtype=tf.float32,
          initializer=initializers.variance_scaling_initializer())
      # V shape is M*N,  V_norm shape is N
      V_norm = tf.norm(V.initialized_value(), axis=0)
      g = tf.get_variable('g', dtype=tf.float32, initializer=V_norm)
      # weightnorm bias is init zero
      b = tf.get_variable(
          name='b',
          shape=[out_dim],
          dtype=tf.float32,
          initializer=tf.zeros_initializer())

      assert len(input_shape) == 3
      if input_shape[0] is None:
        input_shape = tf.shape(inputs)
      inputs = tf.reshape(inputs, [-1, input_shape[-1]])
      inputs = tf.matmul(inputs, V)
      inputs = tf.reshape(inputs, [input_shape[0], -1, out_dim])

      # g/2-norm(v)
      scaler = tf.div(g, tf.norm(V, axis=0))
      # x*v g/2-norm(v) + b
      inputs = tf.reshape(scaler, [1, out_dim]) * inputs + tf.reshape(b, [1, out_dim])

      if self.is_training:
        tf.add_to_collection(output_collection, inputs)
      return inputs 
开发者ID:FangShancheng,项目名称:conv-ensemble-str,代码行数:39,代码来源:decoder_conv.py

示例5: conv1d_weightnorm

# 需要导入模块: from tensorflow.contrib.layers.python.layers import initializers [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.initializers import variance_scaling_initializer [as 别名]
def conv1d_weightnorm(self, inputs, out_dim, kernel_size, padding="SAME",
                        var_scope_name="conv1d", output_collection=None):
    with tf.variable_scope(var_scope_name):
      # pylint: disable=invalid-name
      in_dim = int(inputs.get_shape()[-1])
      V = tf.get_variable(
          name='V',
          shape=[kernel_size, in_dim, out_dim],
          dtype=tf.float32,
          initializer=initializers.variance_scaling_initializer())
      # V shape is M*N*k,  V_norm shape is k
      V_norm = tf.norm(V.initialized_value(), axis=[0, 1])
      g = tf.get_variable('g', dtype=tf.float32, initializer=V_norm)
      b = tf.get_variable(
          name='b',
          shape=[out_dim],
          dtype=tf.float32,
          initializer=tf.zeros_initializer())

      # use weight normalization (Salimans & Kingma, 2016)
      W = tf.reshape(g, [1, 1, out_dim]) * tf.nn.l2_normalize(V, [0, 1])
      inputs = tf.nn.conv1d(value=inputs, filters=W, stride=1, padding=padding)
      inputs = tf.nn.bias_add(inputs, b)

      if self.is_training:
        tf.add_to_collection(output_collection, inputs)
      return inputs 
开发者ID:FangShancheng,项目名称:conv-ensemble-str,代码行数:29,代码来源:decoder_conv.py

示例6: Encoder_fc3_dropout

# 需要导入模块: from tensorflow.contrib.layers.python.layers import initializers [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.initializers import variance_scaling_initializer [as 别名]
def Encoder_fc3_dropout(x,
                        num_output=85,
                        is_training=True,
                        reuse=False,
                        name="3D_module"):
    """
    3D inference module. 3 MLP layers (last is the output)
    With dropout  on first 2.
    Input:
    - x: N x [|img_feat|, |3D_param|]
    - reuse: bool

    Outputs:
    - 3D params: N x num_output
      if orthogonal: 
           either 85: (3 + 24*3 + 10) or 109 (3 + 24*4 + 10) for factored axis-angle representation
      if perspective:
          86: (f, tx, ty, tz) + 24*3 + 10, or 110 for factored axis-angle.
    - variables: tf variables
    """
    if reuse:
        print('Reuse is on!')
    with tf.variable_scope(name, reuse=reuse) as scope:
        net = slim.fully_connected(x, 1024, scope='fc1')
        net = slim.dropout(net, 0.5, is_training=is_training, scope='dropout1')
        net = slim.fully_connected(net, 1024, scope='fc2')
        net = slim.dropout(net, 0.5, is_training=is_training, scope='dropout2')
        small_xavier = variance_scaling_initializer(
            factor=.01, mode='FAN_AVG', uniform=True)
        net = slim.fully_connected(
            net,
            num_output,
            activation_fn=None,
            weights_initializer=small_xavier,
            scope='fc3')

    variables = tf.contrib.framework.get_variables(scope)
    return net, variables 
开发者ID:akanazawa,项目名称:motion_reconstruction,代码行数:40,代码来源:models.py

示例7: inception_v1_arg_scope

# 需要导入模块: from tensorflow.contrib.layers.python.layers import initializers [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.initializers import variance_scaling_initializer [as 别名]
def inception_v1_arg_scope(weight_decay=0.00004,
                           use_batch_norm=True,
                           batch_norm_var_collection='moving_vars'):
  """Defines the default InceptionV1 arg scope.

  Note: Althougth the original paper didn't use batch_norm we found it useful.

  Args:
    weight_decay: The weight decay to use for regularizing the model.
    use_batch_norm: "If `True`, batch_norm is applied after each convolution.
    batch_norm_var_collection: The name of the collection for the batch norm
      variables.

  Returns:
    An `arg_scope` to use for the inception v3 model.
  """
  batch_norm_params = {
      # Decay for the moving averages.
      'decay': 0.9997,
      # epsilon to prevent 0s in variance.
      'epsilon': 0.001,
      # collection containing update_ops.
      'updates_collections': ops.GraphKeys.UPDATE_OPS,
      # collection containing the moving mean and moving variance.
      'variables_collections': {
          'beta': None,
          'gamma': None,
          'moving_mean': [batch_norm_var_collection],
          'moving_variance': [batch_norm_var_collection],
      }
  }
  if use_batch_norm:
    normalizer_fn = layers_lib.batch_norm
    normalizer_params = batch_norm_params
  else:
    normalizer_fn = None
    normalizer_params = {}
  # Set weight_decay for weights in Conv and FC layers.
  with arg_scope(
      [layers.conv2d, layers_lib.fully_connected],
      weights_regularizer=regularizers.l2_regularizer(weight_decay)):
    with arg_scope(
        [layers.conv2d],
        weights_initializer=initializers.variance_scaling_initializer(),
        activation_fn=nn_ops.relu,
        normalizer_fn=normalizer_fn,
        normalizer_params=normalizer_params) as sc:
      return sc 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:50,代码来源:inception_v1.py

示例8: resnet_arg_scope

# 需要导入模块: from tensorflow.contrib.layers.python.layers import initializers [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.initializers import variance_scaling_initializer [as 别名]
def resnet_arg_scope(is_training=True,
                     weight_decay=0.0001,
                     batch_norm_decay=0.997,
                     batch_norm_epsilon=1e-5,
                     batch_norm_scale=True):
  """Defines the default ResNet arg scope.

  TODO(gpapan): The batch-normalization related default values above are
    appropriate for use in conjunction with the reference ResNet models
    released at https://github.com/KaimingHe/deep-residual-networks. When
    training ResNets from scratch, they might need to be tuned.

  Args:
    is_training: Whether or not we are training the parameters in the batch
      normalization layers of the model. (deprecated)
    weight_decay: The weight decay to use for regularizing the model.
    batch_norm_decay: The moving average decay when estimating layer activation
      statistics in batch normalization.
    batch_norm_epsilon: Small constant to prevent division by zero when
      normalizing activations by their variance in batch normalization.
    batch_norm_scale: If True, uses an explicit `gamma` multiplier to scale the
      activations in the batch normalization layer.

  Returns:
    An `arg_scope` to use for the resnet models.
  """
  batch_norm_params = {
      'is_training': is_training,
      'decay': batch_norm_decay,
      'epsilon': batch_norm_epsilon,
      'scale': batch_norm_scale,
      'updates_collections': ops.GraphKeys.UPDATE_OPS,
  }

  with arg_scope(
      [layers_lib.conv2d],
      weights_regularizer=regularizers.l2_regularizer(weight_decay),
      weights_initializer=initializers.variance_scaling_initializer(),
      activation_fn=nn_ops.relu,
      normalizer_fn=layers.batch_norm):
    with arg_scope([layers.batch_norm], **batch_norm_params):
      # The following implies padding='SAME' for pool1, which makes feature
      # alignment easier for dense prediction tasks. This is also used in
      # https://github.com/facebook/fb.resnet.torch. However the accompanying
      # code of 'Deep Residual Learning for Image Recognition' uses
      # padding='VALID' for pool1. You can switch to that choice by setting
      # tf.contrib.framework.arg_scope([tf.contrib.layers.max_pool2d], padding='VALID').
      with arg_scope([layers.max_pool2d], padding='SAME') as arg_sc:
        return arg_sc 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:51,代码来源:resnet_utils.py

示例9: resnet_arg_scope

# 需要导入模块: from tensorflow.contrib.layers.python.layers import initializers [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.initializers import variance_scaling_initializer [as 别名]
def resnet_arg_scope(is_training=True,
                     weight_decay=0.0001,
                     batch_norm_decay=0.997,
                     batch_norm_epsilon=1e-5,
                     batch_norm_scale=True):
  """Defines the default ResNet arg scope.

  TODO(gpapan): The batch-normalization related default values above are
    appropriate for use in conjunction with the reference ResNet models
    released at https://github.com/KaimingHe/deep-residual-networks. When
    training ResNets from scratch, they might need to be tuned.

  Args:
    is_training: Whether or not we are training the parameters in the batch
      normalization layers of the model.
    weight_decay: The weight decay to use for regularizing the model.
    batch_norm_decay: The moving average decay when estimating layer activation
      statistics in batch normalization.
    batch_norm_epsilon: Small constant to prevent division by zero when
      normalizing activations by their variance in batch normalization.
    batch_norm_scale: If True, uses an explicit `gamma` multiplier to scale the
      activations in the batch normalization layer.

  Returns:
    An `arg_scope` to use for the resnet models.
  """
  batch_norm_params = {
      'is_training': is_training,
      'decay': batch_norm_decay,
      'epsilon': batch_norm_epsilon,
      'scale': batch_norm_scale,
      'updates_collections': ops.GraphKeys.UPDATE_OPS,
  }

  with arg_scope(
      [layers_lib.conv2d],
      weights_regularizer=regularizers.l2_regularizer(weight_decay),
      weights_initializer=initializers.variance_scaling_initializer(),
      activation_fn=nn_ops.relu,
      normalizer_fn=layers.batch_norm,
      normalizer_params=batch_norm_params):
    with arg_scope([layers.batch_norm], **batch_norm_params):
      # The following implies padding='SAME' for pool1, which makes feature
      # alignment easier for dense prediction tasks. This is also used in
      # https://github.com/facebook/fb.resnet.torch. However the accompanying
      # code of 'Deep Residual Learning for Image Recognition' uses
      # padding='VALID' for pool1. You can switch to that choice by setting
      # tf.contrib.framework.arg_scope([tf.contrib.layers.max_pool2d], padding='VALID').
      with arg_scope([layers.max_pool2d], padding='SAME') as arg_sc:
        return arg_sc 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:52,代码来源:resnet_utils.py

示例10: inception_v2_arg_scope

# 需要导入模块: from tensorflow.contrib.layers.python.layers import initializers [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.initializers import variance_scaling_initializer [as 别名]
def inception_v2_arg_scope(weight_decay=0.00004,
                           batch_norm_var_collection='moving_vars',
                           batch_norm_decay=0.9997,
                           batch_norm_epsilon=0.001,
                           updates_collections=ops.GraphKeys.UPDATE_OPS,
                           use_fused_batchnorm=True):
  """Defines the default InceptionV2 arg scope.

  Args:
    weight_decay: The weight decay to use for regularizing the model.
    batch_norm_var_collection: The name of the collection for the batch norm
      variables.
    batch_norm_decay: Decay for batch norm moving average
    batch_norm_epsilon: Small float added to variance to avoid division by zero
    updates_collections: Collections for the update ops of the layer
    use_fused_batchnorm: Enable fused batchnorm.

  Returns:
    An `arg_scope` to use for the inception v3 model.
  """
  batch_norm_params = {
      # Decay for the moving averages.
      'decay': batch_norm_decay,
      # epsilon to prevent 0s in variance.
      'epsilon': batch_norm_epsilon,
      # collection containing update_ops.
      'updates_collections': updates_collections,
      # Enable fused batchnorm.
      'fused': use_fused_batchnorm,
      # collection containing the moving mean and moving variance.
      'variables_collections': {
          'beta': None,
          'gamma': None,
          'moving_mean': [batch_norm_var_collection],
          'moving_variance': [batch_norm_var_collection],
      }
  }

  # Set weight_decay for weights in Conv and FC layers.
  with arg_scope(
      [layers.conv2d, layers_lib.fully_connected],
      weights_regularizer=regularizers.l2_regularizer(weight_decay)):
    with arg_scope(
        [layers.conv2d],
        weights_initializer=initializers.variance_scaling_initializer(),
        activation_fn=nn_ops.relu,
        normalizer_fn=layers_lib.batch_norm,
        normalizer_params=batch_norm_params) as sc:
      return sc 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:51,代码来源:inception_v2_tpu_model.py

示例11: inception_v3_arg_scope

# 需要导入模块: from tensorflow.contrib.layers.python.layers import initializers [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.initializers import variance_scaling_initializer [as 别名]
def inception_v3_arg_scope(weight_decay=0.00004,
                           batch_norm_var_collection='moving_vars',
                           use_fused_batchnorm=True):
  """Defines the default InceptionV3 arg scope.

  Args:
    weight_decay: The weight decay to use for regularizing the model.
    batch_norm_var_collection: The name of the collection for the batch norm
      variables.
    use_fused_batchnorm: Enable fused batchnorm.

  Returns:
    An `arg_scope` to use for the inception v3 model.
  """
  batch_norm_params = {
    # Decay for the moving averages.
    'decay': 0.9997,
    # epsilon to prevent 0s in variance.
    'epsilon': 0.001,
    # collection containing update_ops.
    'updates_collections': ops.GraphKeys.UPDATE_OPS,
    # Use fused batch norm if possible.
    'fused': use_fused_batchnorm,
    # collection containing the moving mean and moving variance.
    'variables_collections': {
      'beta': None,
      'gamma': None,
      'moving_mean': [batch_norm_var_collection],
      'moving_variance': [batch_norm_var_collection],
    }
  }

  # Set weight_decay for weights in Conv and FC layers.
  with arg_scope(
      [layers.conv2d, layers_lib.fully_connected],
      weights_regularizer=regularizers.l2_regularizer(weight_decay)):
    with arg_scope(
        [layers.conv2d],
        weights_initializer=initializers.variance_scaling_initializer(),
        activation_fn=nn_ops.relu,
        normalizer_fn=layers_lib.batch_norm,
        normalizer_params=batch_norm_params) as sc:
      return sc 
开发者ID:lifeiteng,项目名称:TF_SpeechRecoChallenge,代码行数:45,代码来源:model_inception_v3.py

示例12: resnet_arg_scope

# 需要导入模块: from tensorflow.contrib.layers.python.layers import initializers [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.initializers import variance_scaling_initializer [as 别名]
def resnet_arg_scope(weight_decay=0.0001,
                     batch_norm_decay=0.997,
                     batch_norm_epsilon=1e-5,
                     batch_norm_scale=True):
    """Defines the default ResNet arg scope.

    TODO(gpapan): The batch-normalization related default values above are
      appropriate for use in conjunction with the reference ResNet models
      released at https://github.com/KaimingHe/deep-residual-networks. When
      training ResNets from scratch, they might need to be tuned.

    Args:
      weight_decay: The weight decay to use for regularizing the model.
      batch_norm_decay: The moving average decay when estimating layer activation
        statistics in batch normalization.
      batch_norm_epsilon: Small constant to prevent division by zero when
        normalizing activations by their variance in batch normalization.
      batch_norm_scale: If True, uses an explicit `gamma` multiplier to scale the
        activations in the batch normalization layer.

    Returns:
      An `arg_scope` to use for the resnet models.
    """
    batch_norm_params = {
        'decay': batch_norm_decay,
        'epsilon': batch_norm_epsilon,
        'scale': batch_norm_scale,
        'updates_collections': ops.GraphKeys.UPDATE_OPS,
    }

    with arg_scope(
            [layers_lib.conv2d],
            weights_regularizer=regularizers.l2_regularizer(weight_decay),
            weights_initializer=initializers.variance_scaling_initializer(),
            activation_fn=nn_ops.relu,
            normalizer_fn=layers.batch_norm,
            normalizer_params=batch_norm_params):
        with arg_scope([layers.batch_norm], **batch_norm_params):
            # The following implies padding='SAME' for pool1, which makes feature
            # alignment easier for dense prediction tasks. This is also used in
            # https://github.com/facebook/fb.resnet.torch. However the accompanying
            # code of 'Deep Residual Learning for Image Recognition' uses
            # padding='VALID' for pool1. You can switch to that choice by setting
            # tf.contrib.framework.arg_scope([tf.contrib.layers.max_pool2d], padding='VALID').
            with arg_scope([layers.max_pool2d], padding='SAME') as arg_sc:
                return arg_sc 
开发者ID:POSTECH-IMLAB,项目名称:LaneSegmentationNetwork,代码行数:48,代码来源:resnet_utils.py


注:本文中的tensorflow.contrib.layers.python.layers.initializers.variance_scaling_initializer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。