本文整理汇总了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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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