本文整理汇总了Python中tensorflow.contrib.framework.python.ops.arg_scope方法的典型用法代码示例。如果您正苦于以下问题:Python ops.arg_scope方法的具体用法?Python ops.arg_scope怎么用?Python ops.arg_scope使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.contrib.framework.python.ops
的用法示例。
在下文中一共展示了ops.arg_scope方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: vgg_arg_scope
# 需要导入模块: from tensorflow.contrib.framework.python import ops [as 别名]
# 或者: from tensorflow.contrib.framework.python.ops import arg_scope [as 别名]
def vgg_arg_scope(weight_decay=0.0005):
"""Defines the VGG arg scope.
Args:
weight_decay: The l2 regularization coefficient.
Returns:
An arg_scope.
"""
with arg_scope(
[layers.conv2d, layers_lib.fully_connected],
activation_fn=nn_ops.relu,
weights_regularizer=regularizers.l2_regularizer(weight_decay),
biases_initializer=init_ops.zeros_initializer()):
with arg_scope([layers.conv2d], padding='SAME') as arg_sc:
return arg_sc
示例2: testClassificationShapes
# 需要导入模块: from tensorflow.contrib.framework.python import ops [as 别名]
# 或者: from tensorflow.contrib.framework.python.ops import arg_scope [as 别名]
def testClassificationShapes(self):
global_pool = True
num_classes = 10
inputs = create_test_input(2, 224, 224, 3)
with arg_scope(resnet_utils.resnet_arg_scope()):
_, end_points = self._resnet_small(
inputs, num_classes, global_pool, scope='resnet')
endpoint_to_shape = {
'resnet/block1': [2, 28, 28, 4],
'resnet/block2': [2, 14, 14, 8],
'resnet/block3': [2, 7, 7, 16],
'resnet/block4': [2, 7, 7, 32]
}
for endpoint in endpoint_to_shape:
shape = endpoint_to_shape[endpoint]
self.assertListEqual(end_points[endpoint].get_shape().as_list(), shape)
示例3: testFullyConvolutionalEndpointShapes
# 需要导入模块: from tensorflow.contrib.framework.python import ops [as 别名]
# 或者: from tensorflow.contrib.framework.python.ops import arg_scope [as 别名]
def testFullyConvolutionalEndpointShapes(self):
global_pool = False
num_classes = 10
inputs = create_test_input(2, 321, 321, 3)
with arg_scope(resnet_utils.resnet_arg_scope()):
_, end_points = self._resnet_small(
inputs, num_classes, global_pool, scope='resnet')
endpoint_to_shape = {
'resnet/block1': [2, 41, 41, 4],
'resnet/block2': [2, 21, 21, 8],
'resnet/block3': [2, 11, 11, 16],
'resnet/block4': [2, 11, 11, 32]
}
for endpoint in endpoint_to_shape:
shape = endpoint_to_shape[endpoint]
self.assertListEqual(end_points[endpoint].get_shape().as_list(), shape)
示例4: testRootlessFullyConvolutionalEndpointShapes
# 需要导入模块: from tensorflow.contrib.framework.python import ops [as 别名]
# 或者: from tensorflow.contrib.framework.python.ops import arg_scope [as 别名]
def testRootlessFullyConvolutionalEndpointShapes(self):
global_pool = False
num_classes = 10
inputs = create_test_input(2, 128, 128, 3)
with arg_scope(resnet_utils.resnet_arg_scope()):
_, end_points = self._resnet_small(
inputs,
num_classes,
global_pool,
include_root_block=False,
scope='resnet')
endpoint_to_shape = {
'resnet/block1': [2, 64, 64, 4],
'resnet/block2': [2, 32, 32, 8],
'resnet/block3': [2, 16, 16, 16],
'resnet/block4': [2, 16, 16, 32]
}
for endpoint in endpoint_to_shape:
shape = endpoint_to_shape[endpoint]
self.assertListEqual(end_points[endpoint].get_shape().as_list(), shape)
示例5: testAtrousFullyConvolutionalEndpointShapes
# 需要导入模块: from tensorflow.contrib.framework.python import ops [as 别名]
# 或者: from tensorflow.contrib.framework.python.ops import arg_scope [as 别名]
def testAtrousFullyConvolutionalEndpointShapes(self):
global_pool = False
num_classes = 10
output_stride = 8
inputs = create_test_input(2, 321, 321, 3)
with arg_scope(resnet_utils.resnet_arg_scope()):
_, end_points = self._resnet_small(
inputs,
num_classes,
global_pool,
output_stride=output_stride,
scope='resnet')
endpoint_to_shape = {
'resnet/block1': [2, 41, 41, 4],
'resnet/block2': [2, 41, 41, 8],
'resnet/block3': [2, 41, 41, 16],
'resnet/block4': [2, 41, 41, 32]
}
for endpoint in endpoint_to_shape:
shape = endpoint_to_shape[endpoint]
self.assertListEqual(end_points[endpoint].get_shape().as_list(), shape)
示例6: testAtrousFullyConvolutionalValues
# 需要导入模块: from tensorflow.contrib.framework.python import ops [as 别名]
# 或者: from tensorflow.contrib.framework.python.ops import arg_scope [as 别名]
def testAtrousFullyConvolutionalValues(self):
"""Verify dense feature extraction with atrous convolution."""
nominal_stride = 32
for output_stride in [4, 8, 16, 32, None]:
with arg_scope(resnet_utils.resnet_arg_scope(is_training=False)):
with ops.Graph().as_default():
with self.test_session() as sess:
random_seed.set_random_seed(0)
inputs = create_test_input(2, 81, 81, 3)
# Dense feature extraction followed by subsampling.
output, _ = self._resnet_small(
inputs, None, global_pool=False, output_stride=output_stride)
if output_stride is None:
factor = 1
else:
factor = nominal_stride // output_stride
output = resnet_utils.subsample(output, factor)
# Make the two networks use the same weights.
variable_scope.get_variable_scope().reuse_variables()
# Feature extraction at the nominal network rate.
expected, _ = self._resnet_small(inputs, None, global_pool=False)
sess.run(variables.global_variables_initializer())
self.assertAllClose(
output.eval(), expected.eval(), atol=1e-4, rtol=1e-4)
示例7: actnorm
# 需要导入模块: from tensorflow.contrib.framework.python import ops [as 别名]
# 或者: from tensorflow.contrib.framework.python.ops import arg_scope [as 别名]
def actnorm(name, x, scale=1., logdet=None, logscale_factor=3., batch_variance=False, reverse=False, init=False, trainable=True):
if arg_scope([get_variable_ddi], trainable=trainable):
if not reverse:
x = actnorm_center(name+"_center", x, reverse)
x = actnorm_scale(name+"_scale", x, scale, logdet,
logscale_factor, batch_variance, reverse, init)
if logdet != None:
x, logdet = x
else:
x = actnorm_scale(name + "_scale", x, scale, logdet,
logscale_factor, batch_variance, reverse, init)
if logdet != None:
x, logdet = x
x = actnorm_center(name+"_center", x, reverse)
if logdet != None:
return x, logdet
return x
# Activation normalization
示例8: up
# 需要导入模块: from tensorflow.contrib.framework.python import ops [as 别名]
# 或者: from tensorflow.contrib.framework.python.ops import arg_scope [as 别名]
def up(self, input, **_):
hps = self.hps
h_size = hps.h_size
z_size = hps.z_size
stride = [2, 2] if self.downsample else [1, 1]
with arg_scope([conv2d]):
x = tf.nn.elu(input)
x = conv2d("up_conv1", x, 2 * z_size + 2 * h_size, stride=stride)
self.qz_mean, self.qz_logsd, self.up_context, h = split(x, 1, [z_size, z_size, h_size, h_size])
h = tf.nn.elu(h)
h = conv2d("up_conv3", h, h_size)
if self.downsample:
input = resize_nearest_neighbor(input, 0.5)
return input + 0.1 * h
示例9: predictron_arg_scope
# 需要导入模块: from tensorflow.contrib.framework.python import ops [as 别名]
# 或者: from tensorflow.contrib.framework.python.ops import arg_scope [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
示例10: vgg_arg_scope
# 需要导入模块: from tensorflow.contrib.framework.python import ops [as 别名]
# 或者: from tensorflow.contrib.framework.python.ops import arg_scope [as 别名]
def vgg_arg_scope(weight_decay=0.0005):
"""Defines the VGG arg scope.
Args:
weight_decay: The l2 regularization coefficient.
Returns:
An arg_scope.
"""
with arg_scope(
[layers.conv2d, layers_lib.fully_connected],
activation_fn=nn_ops.relu,
weights_regularizer=regularizers.l2_regularizer(weight_decay),
biases_initializer=init_ops.zeros_initializer()
):
with arg_scope([layers.conv2d], padding='SAME') as arg_sc:
return arg_sc
示例11: inception_v2_arg_scope
# 需要导入模块: from tensorflow.contrib.framework.python import ops [as 别名]
# 或者: from tensorflow.contrib.framework.python.ops import arg_scope [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
示例12: alexnet_v2_arg_scope
# 需要导入模块: from tensorflow.contrib.framework.python import ops [as 别名]
# 或者: from tensorflow.contrib.framework.python.ops import arg_scope [as 别名]
def alexnet_v2_arg_scope(weight_decay=0.0005):
with arg_scope(
[layers.conv2d, layers_lib.fully_connected],
activation_fn=nn_ops.relu,
biases_initializer=init_ops.constant_initializer(0.1),
weights_regularizer=regularizers.l2_regularizer(weight_decay)):
with arg_scope([layers.conv2d], padding='SAME'):
with arg_scope([layers_lib.max_pool2d], padding='VALID') as arg_sc:
return arg_sc
开发者ID:MingtaoGuo,项目名称:Chinese-Character-and-Calligraphic-Image-Processing,代码行数:11,代码来源:alexnet_v2.py
示例13: overfeat_arg_scope
# 需要导入模块: from tensorflow.contrib.framework.python import ops [as 别名]
# 或者: from tensorflow.contrib.framework.python.ops import arg_scope [as 别名]
def overfeat_arg_scope(weight_decay=0.0005):
with arg_scope(
[layers.conv2d, layers_lib.fully_connected],
activation_fn=nn_ops.relu,
weights_regularizer=regularizers.l2_regularizer(weight_decay),
biases_initializer=init_ops.zeros_initializer()):
with arg_scope([layers.conv2d], padding='SAME'):
with arg_scope([layers_lib.max_pool2d], padding='VALID') as arg_sc:
return arg_sc
示例14: _resnet_plain
# 需要导入模块: from tensorflow.contrib.framework.python import ops [as 别名]
# 或者: from tensorflow.contrib.framework.python.ops import arg_scope [as 别名]
def _resnet_plain(self, inputs, blocks, output_stride=None, scope=None):
"""A plain ResNet without extra layers before or after the ResNet blocks."""
with variable_scope.variable_scope(scope, values=[inputs]):
with arg_scope([layers.conv2d], outputs_collections='end_points'):
net = resnet_utils.stack_blocks_dense(inputs, blocks, output_stride)
end_points = utils.convert_collection_to_dict('end_points')
return net, end_points
示例15: testEndPointsV2
# 需要导入模块: from tensorflow.contrib.framework.python import ops [as 别名]
# 或者: from tensorflow.contrib.framework.python.ops import arg_scope [as 别名]
def testEndPointsV2(self):
"""Test the end points of a tiny v2 bottleneck network."""
bottleneck = resnet_v2.bottleneck
blocks = [
resnet_utils.Block('block1', bottleneck, [(4, 1, 1), (4, 1, 2)]),
resnet_utils.Block('block2', bottleneck, [(8, 2, 1), (8, 2, 1)])
]
inputs = create_test_input(2, 32, 16, 3)
with arg_scope(resnet_utils.resnet_arg_scope()):
_, end_points = self._resnet_plain(inputs, blocks, scope='tiny')
expected = [
'tiny/block1/unit_1/bottleneck_v2/shortcut',
'tiny/block1/unit_1/bottleneck_v2/conv1',
'tiny/block1/unit_1/bottleneck_v2/conv2',
'tiny/block1/unit_1/bottleneck_v2/conv3',
'tiny/block1/unit_2/bottleneck_v2/conv1',
'tiny/block1/unit_2/bottleneck_v2/conv2',
'tiny/block1/unit_2/bottleneck_v2/conv3',
'tiny/block2/unit_1/bottleneck_v2/shortcut',
'tiny/block2/unit_1/bottleneck_v2/conv1',
'tiny/block2/unit_1/bottleneck_v2/conv2',
'tiny/block2/unit_1/bottleneck_v2/conv3',
'tiny/block2/unit_2/bottleneck_v2/conv1',
'tiny/block2/unit_2/bottleneck_v2/conv2',
'tiny/block2/unit_2/bottleneck_v2/conv3'
]
self.assertItemsEqual(expected, end_points)