本文整理汇总了Python中tensorflow.contrib.slim.arg_scope方法的典型用法代码示例。如果您正苦于以下问题:Python slim.arg_scope方法的具体用法?Python slim.arg_scope怎么用?Python slim.arg_scope使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.contrib.slim
的用法示例。
在下文中一共展示了slim.arg_scope方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import arg_scope [as 别名]
def __call__(self, x_input, return_logits=False):
"""Constructs model and return probabilities for given input."""
reuse = True if self.built else None
with slim.arg_scope(inception.inception_v3_arg_scope()):
# Inception preprocessing uses [-1, 1]-scaled input.
x_input = x_input * 2.0 - 1.0
_, end_points = inception.inception_v3(
x_input, num_classes=self.nb_classes, is_training=False,
reuse=reuse)
self.built = True
self.logits = end_points['Logits']
# Strip off the extra reshape op at the output
self.probs = end_points['Predictions'].op.inputs[0]
if return_logits:
return self.logits
else:
return self.probs
示例2: conv_tower_fn
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import arg_scope [as 别名]
def conv_tower_fn(self, images, is_training=True, reuse=None):
"""Computes convolutional features using the InceptionV3 model.
Args:
images: A tensor of shape [batch_size, height, width, channels].
is_training: whether is training or not.
reuse: whether or not the network and its variables should be reused. To
be able to reuse 'scope' must be given.
Returns:
A tensor of shape [batch_size, OH, OW, N], where OWxOH is resolution of
output feature map and N is number of output features (depends on the
network architecture).
"""
mparams = self._mparams['conv_tower_fn']
logging.debug('Using final_endpoint=%s', mparams.final_endpoint)
with tf.variable_scope('conv_tower_fn/INCE'):
if reuse:
tf.get_variable_scope().reuse_variables()
with slim.arg_scope(inception.inception_v3_arg_scope()):
net, _ = inception.inception_v3_base(
images, final_endpoint=mparams.final_endpoint)
return net
示例3: model
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import arg_scope [as 别名]
def model(image):
image = mean_image_subtraction(image)
with slim.arg_scope(vgg.vgg_arg_scope()):
conv5_3 = vgg.vgg_16(image)
rpn_conv = slim.conv2d(conv5_3, 512, 3)
lstm_output = Bilstm(rpn_conv, 512, 128, 512, scope_name='BiLSTM')
bbox_pred = lstm_fc(lstm_output, 512, 10 * 4, scope_name="bbox_pred")
cls_pred = lstm_fc(lstm_output, 512, 10 * 2, scope_name="cls_pred")
# transpose: (1, H, W, A x d) -> (1, H, WxA, d)
cls_pred_shape = tf.shape(cls_pred)
cls_pred_reshape = tf.reshape(cls_pred, [cls_pred_shape[0], cls_pred_shape[1], -1, 2])
cls_pred_reshape_shape = tf.shape(cls_pred_reshape)
cls_prob = tf.reshape(tf.nn.softmax(tf.reshape(cls_pred_reshape, [-1, cls_pred_reshape_shape[3]])),
[-1, cls_pred_reshape_shape[1], cls_pred_reshape_shape[2], cls_pred_reshape_shape[3]],
name="cls_prob")
return bbox_pred, cls_pred, cls_prob
示例4: delf_attention
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import arg_scope [as 别名]
def delf_attention(feature_map, config, is_training, arg_scope=None):
with tf.variable_scope('attonly/attention/compute'):
with slim.arg_scope(arg_scope):
is_training = config['train_attention'] and is_training
with slim.arg_scope([slim.conv2d, slim.batch_norm],
trainable=is_training):
with slim.arg_scope([slim.batch_norm], is_training=is_training):
attention = slim.conv2d(
feature_map, 512, config['attention_kernel'], rate=1,
activation_fn=tf.nn.relu, scope='conv1')
attention = slim.conv2d(
attention, 1, config['attention_kernel'], rate=1,
activation_fn=None, normalizer_fn=None, scope='conv2')
attention = tf.nn.softplus(attention)
if config['normalize_feature_map']:
feature_map = tf.nn.l2_normalize(feature_map, -1)
descriptor = tf.reduce_sum(feature_map*attention, axis=[1, 2])
if config['normalize_average']:
descriptor /= tf.reduce_sum(attention, axis=[1, 2])
return descriptor
示例5: tower
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import arg_scope [as 别名]
def tower(image, mode, config):
image = image_normalization(image)
if image.shape[-1] == 1:
image = tf.tile(image, [1, 1, 1, 3])
with slim.arg_scope(resnet.resnet_arg_scope()):
is_training = config['train_backbone'] and (mode == Mode.TRAIN)
with slim.arg_scope([slim.conv2d, slim.batch_norm], trainable=is_training):
_, encoder = resnet.resnet_v1_50(image,
is_training=is_training,
global_pool=False,
scope='resnet_v1_50')
feature_map = encoder['resnet_v1_50/block3']
if config['use_attention']:
descriptor = delf_attention(feature_map, config, mode == Mode.TRAIN,
resnet.resnet_arg_scope())
else:
descriptor = tf.reduce_max(feature_map, [1, 2])
if config['dimensionality_reduction']:
descriptor = dimensionality_reduction(descriptor, config)
return descriptor
示例6: _model
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import arg_scope [as 别名]
def _model(self, inputs, mode, **config):
image = image_normalization(inputs['image'])
if image.shape[-1] == 1:
image = tf.tile(image, [1, 1, 1, 3])
if config['resize_input']:
new_size = tf.to_int32(tf.round(
tf.to_float(tf.shape(image)[1:3]) / float(config['resize_input'])))
image = tf.image.resize_images(image, new_size)
is_training = config['train_backbone'] and (mode == Mode.TRAIN)
with slim.arg_scope(mobilenet.training_scope(
is_training=is_training, dropout_keep_prob=config['dropout_keep_prob'])):
_, encoder = mobilenet.mobilenet(image, num_classes=None, base_only=True,
depth_multiplier=config['depth_multiplier'],
final_endpoint=config['encoder_endpoint'])
feature_map = encoder[config['encoder_endpoint']]
descriptor = vlad(feature_map, config, mode == Mode.TRAIN)
if config['dimensionality_reduction']:
descriptor = dimensionality_reduction(descriptor, config)
return {'descriptor': descriptor}
示例7: tower
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import arg_scope [as 别名]
def tower(image, mode, config):
image = image_normalization(image)
if image.shape[-1] == 1:
image = tf.tile(image, [1, 1, 1, 3])
with slim.arg_scope(resnet.resnet_arg_scope()):
training = config['train_backbone'] and (mode == Mode.TRAIN)
with slim.arg_scope([slim.conv2d, slim.batch_norm], trainable=training):
_, encoder = resnet.resnet_v1_50(image,
is_training=training,
global_pool=False,
scope='resnet_v1_50')
feature_map = encoder['resnet_v1_50/block3']
descriptor = vlad(feature_map, config, mode == Mode.TRAIN)
if config['dimensionality_reduction']:
descriptor = dimensionality_reduction(descriptor, config)
return descriptor
示例8: E
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import arg_scope [as 别名]
def E(self, images, is_training = False, reuse=False):
if images.get_shape()[3] == 3:
images = tf.image.rgb_to_grayscale(images)
with tf.variable_scope('encoder',reuse=reuse):
with slim.arg_scope([slim.fully_connected], activation_fn=tf.nn.relu):
with slim.arg_scope([slim.conv2d], activation_fn=tf.nn.relu, padding='VALID'):
net = slim.conv2d(images, 64, 5, scope='conv1')
net = slim.max_pool2d(net, 2, stride=2, scope='pool1')
net = slim.conv2d(net, 128, 5, scope='conv2')
net = slim.max_pool2d(net, 2, stride=2, scope='pool2')
net = tf.contrib.layers.flatten(net)
net = slim.fully_connected(net, 1024, activation_fn=tf.nn.relu, scope='fc3')
net = slim.dropout(net, 0.5, is_training=is_training)
net = slim.fully_connected(net, self.hidden_repr_size, activation_fn=tf.tanh,scope='fc4')
# dropout here or not?
#~ net = slim.dropout(net, 0.5, is_training=is_training)
return net
示例9: mobilenetv2_scope
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import arg_scope [as 别名]
def mobilenetv2_scope(is_training=True,
trainable=True,
weight_decay=0.00004,
stddev=0.09,
dropout_keep_prob=0.8,
bn_decay=0.997):
"""Defines Mobilenet training scope.
In default. We do not use BN
ReWrite the scope.
"""
batch_norm_params = {
'is_training': False,
'trainable': False,
'decay': bn_decay,
}
with slim.arg_scope(training_scope(is_training=is_training, weight_decay=weight_decay)):
with slim.arg_scope([slim.conv2d, slim.fully_connected, slim.separable_conv2d],
trainable=trainable):
with slim.arg_scope([slim.batch_norm], **batch_norm_params) as sc:
return sc
示例10: training_scope
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import arg_scope [as 别名]
def training_scope(**kwargs):
"""Defines MobilenetV2 training scope.
Usage:
with tf.contrib.slim.arg_scope(mobilenet_v2.training_scope()):
logits, endpoints = mobilenet_v2.mobilenet(input_tensor)
with slim.
Args:
**kwargs: Passed to mobilenet.training_scope. The following parameters
are supported:
weight_decay- The weight decay to use for regularizing the model.
stddev- Standard deviation for initialization, if negative uses xavier.
dropout_keep_prob- dropout keep probability
bn_decay- decay for the batch norm moving averages.
Returns:
An `arg_scope` to use for the mobilenet v2 model.
"""
return lib.training_scope(**kwargs)
示例11: testBuildLogitsCifarModel
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import arg_scope [as 别名]
def testBuildLogitsCifarModel(self):
batch_size = 5
height, width = 32, 32
num_classes = 10
inputs = tf.random_uniform((batch_size, height, width, 3))
tf.train.create_global_step()
with slim.arg_scope(nasnet.nasnet_cifar_arg_scope()):
logits, end_points = nasnet.build_nasnet_cifar(inputs, num_classes)
auxlogits = end_points['AuxLogits']
predictions = end_points['Predictions']
self.assertListEqual(auxlogits.get_shape().as_list(),
[batch_size, num_classes])
self.assertListEqual(logits.get_shape().as_list(),
[batch_size, num_classes])
self.assertListEqual(predictions.get_shape().as_list(),
[batch_size, num_classes])
示例12: testBuildLogitsMobileModel
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import arg_scope [as 别名]
def testBuildLogitsMobileModel(self):
batch_size = 5
height, width = 224, 224
num_classes = 1000
inputs = tf.random_uniform((batch_size, height, width, 3))
tf.train.create_global_step()
with slim.arg_scope(nasnet.nasnet_mobile_arg_scope()):
logits, end_points = nasnet.build_nasnet_mobile(inputs, num_classes)
auxlogits = end_points['AuxLogits']
predictions = end_points['Predictions']
self.assertListEqual(auxlogits.get_shape().as_list(),
[batch_size, num_classes])
self.assertListEqual(logits.get_shape().as_list(),
[batch_size, num_classes])
self.assertListEqual(predictions.get_shape().as_list(),
[batch_size, num_classes])
示例13: testBuildLogitsLargeModel
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import arg_scope [as 别名]
def testBuildLogitsLargeModel(self):
batch_size = 5
height, width = 331, 331
num_classes = 1000
inputs = tf.random_uniform((batch_size, height, width, 3))
tf.train.create_global_step()
with slim.arg_scope(nasnet.nasnet_large_arg_scope()):
logits, end_points = nasnet.build_nasnet_large(inputs, num_classes)
auxlogits = end_points['AuxLogits']
predictions = end_points['Predictions']
self.assertListEqual(auxlogits.get_shape().as_list(),
[batch_size, num_classes])
self.assertListEqual(logits.get_shape().as_list(),
[batch_size, num_classes])
self.assertListEqual(predictions.get_shape().as_list(),
[batch_size, num_classes])
示例14: _extra_conv_arg_scope_with_bn
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import arg_scope [as 别名]
def _extra_conv_arg_scope_with_bn(weight_decay=0.00001,
activation_fn=None,
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,
}
with slim.arg_scope(
[slim.conv2d],
weights_regularizer=slim.l2_regularizer(weight_decay),
weights_initializer=slim.variance_scaling_initializer(),
activation_fn=tf.nn.relu,
normalizer_fn=slim.batch_norm,
normalizer_params=batch_norm_params):
with slim.arg_scope([slim.batch_norm], **batch_norm_params):
with slim.arg_scope([slim.max_pool2d], padding='SAME') as arg_sc:
return arg_sc
示例15: _extra_conv_arg_scope
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import arg_scope [as 别名]
def _extra_conv_arg_scope(weight_decay=0.00001, activation_fn=None, normalizer_fn=None):
with slim.arg_scope(
[slim.conv2d, slim.conv2d_transpose],
padding='SAME',
weights_regularizer=slim.l2_regularizer(weight_decay),
weights_initializer=tf.truncated_normal_initializer(stddev=0.001),
activation_fn=activation_fn,
normalizer_fn=normalizer_fn,) as arg_sc:
with slim.arg_scope(
[slim.fully_connected],
weights_regularizer=slim.l2_regularizer(weight_decay),
weights_initializer=tf.truncated_normal_initializer(stddev=0.001),
activation_fn=activation_fn,
normalizer_fn=normalizer_fn) as arg_sc:
return arg_sc