本文整理汇总了Python中tensorflow.contrib.slim.avg_pool2d方法的典型用法代码示例。如果您正苦于以下问题:Python slim.avg_pool2d方法的具体用法?Python slim.avg_pool2d怎么用?Python slim.avg_pool2d使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.contrib.slim
的用法示例。
在下文中一共展示了slim.avg_pool2d方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _build_aux_head
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import avg_pool2d [as 别名]
def _build_aux_head(net, end_points, num_classes, hparams, scope):
"""Auxiliary head used for all models across all datasets."""
with tf.variable_scope(scope):
aux_logits = tf.identity(net)
with tf.variable_scope('aux_logits'):
aux_logits = slim.avg_pool2d(
aux_logits, [5, 5], stride=3, padding='VALID')
aux_logits = slim.conv2d(aux_logits, 128, [1, 1], scope='proj')
aux_logits = slim.batch_norm(aux_logits, scope='aux_bn0')
aux_logits = tf.nn.relu(aux_logits)
# Shape of feature map before the final layer.
shape = aux_logits.shape
if hparams.data_format == 'NHWC':
shape = shape[1:3]
else:
shape = shape[2:4]
aux_logits = slim.conv2d(aux_logits, 768, shape, padding='VALID')
aux_logits = slim.batch_norm(aux_logits, scope='aux_bn1')
aux_logits = tf.nn.relu(aux_logits)
aux_logits = contrib_layers.flatten(aux_logits)
aux_logits = slim.fully_connected(aux_logits, num_classes)
end_points['AuxLogits'] = aux_logits
示例2: _d_residual_block
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import avg_pool2d [as 别名]
def _d_residual_block(self, x, out_ch, idx, is_training, resize=True, is_head=False):
update_collection = self._get_update_collection(is_training)
with tf.variable_scope("d_resblock_"+str(idx), reuse=tf.AUTO_REUSE):
h = x
if not is_head:
h = tf.nn.relu(h)
h = snconv2d(h, out_ch, name='d_resblock_conv_1', update_collection=update_collection)
h = tf.nn.relu(h)
h = snconv2d(h, out_ch, name='d_resblock_conv_2', update_collection=update_collection)
if resize:
h = slim.avg_pool2d(h, [2, 2])
# Short cut
s = x
if resize:
s = slim.avg_pool2d(s, [2, 2])
s = snconv2d(s, out_ch, k_h=1, k_w=1, name='d_resblock_conv_sc', update_collection=update_collection)
return h + s
示例3: compute_ssim_loss
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import avg_pool2d [as 别名]
def compute_ssim_loss(self, x, y):
"""Computes a differentiable structured image similarity measure."""
c1 = 0.01**2
c2 = 0.03**2
mu_x = slim.avg_pool2d(x, 3, 1, 'VALID')
mu_y = slim.avg_pool2d(y, 3, 1, 'VALID')
sigma_x = slim.avg_pool2d(x**2, 3, 1, 'VALID') - mu_x**2
sigma_y = slim.avg_pool2d(y**2, 3, 1, 'VALID') - mu_y**2
sigma_xy = slim.avg_pool2d(x * y, 3, 1, 'VALID') - mu_x * mu_y
ssim_n = (2 * mu_x * mu_y + c1) * (2 * sigma_xy + c2)
ssim_d = (mu_x**2 + mu_y**2 + c1) * (sigma_x + sigma_y + c2)
ssim = ssim_n / ssim_d
return tf.clip_by_value((1 - ssim) / 2, 0, 1)
# reference: https://github.com/yzcjtr/GeoNet/blob/master/geonet_model.py
# and https://arxiv.org/abs/1712.00175
示例4: __init__
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import avg_pool2d [as 别名]
def __init__(self, images, pretrained_ckpt, reuse=False,
random_projection=False, random_projection_dim=32):
# Build InceptionV3 graph.
(inception_output,
self.inception_variables,
self.init_fn) = build_inceptionv3_graph(
images, 'Mixed_7c', False, pretrained_ckpt, reuse)
# Pool 8x8x2048 -> 1x1x2048.
embedding = slim.avg_pool2d(inception_output, [8, 8], stride=1)
embedding = tf.squeeze(embedding, [1, 2])
if random_projection:
embedding = tf.matmul(
embedding, tf.random_normal(
shape=[2048, random_projection_dim], seed=123))
self.embedding = embedding
示例5: block_inception_a
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import avg_pool2d [as 别名]
def block_inception_a(inputs, scope=None, reuse=None):
"""Builds Inception-A block for Inception v4 network."""
# By default use stride=1 and SAME padding
with slim.arg_scope(
[slim.conv2d, slim.avg_pool2d, slim.max_pool2d], stride=1,
padding='SAME'):
with variable_scope.variable_scope(
scope, 'BlockInceptionA', [inputs], reuse=reuse):
with variable_scope.variable_scope('Branch_0'):
branch_0 = slim.conv2d(inputs, 96, [1, 1], scope='Conv2d_0a_1x1')
with variable_scope.variable_scope('Branch_1'):
branch_1 = slim.conv2d(inputs, 64, [1, 1], scope='Conv2d_0a_1x1')
branch_1 = slim.conv2d(branch_1, 96, [3, 3], scope='Conv2d_0b_3x3')
with variable_scope.variable_scope('Branch_2'):
branch_2 = slim.conv2d(inputs, 64, [1, 1], scope='Conv2d_0a_1x1')
branch_2 = slim.conv2d(branch_2, 96, [3, 3], scope='Conv2d_0b_3x3')
branch_2 = slim.conv2d(branch_2, 96, [3, 3], scope='Conv2d_0c_3x3')
with variable_scope.variable_scope('Branch_3'):
branch_3 = slim.avg_pool2d(inputs, [3, 3], scope='AvgPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, 96, [1, 1], scope='Conv2d_0b_1x1')
return array_ops.concat(
axis=3, values=[branch_0, branch_1, branch_2, branch_3])
示例6: block_inception_b
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import avg_pool2d [as 别名]
def block_inception_b(inputs, scope=None, reuse=None):
"""Builds Inception-B block for Inception v4 network."""
# By default use stride=1 and SAME padding
with slim.arg_scope(
[slim.conv2d, slim.avg_pool2d, slim.max_pool2d], stride=1,
padding='SAME'):
with variable_scope.variable_scope(
scope, 'BlockInceptionB', [inputs], reuse=reuse):
with variable_scope.variable_scope('Branch_0'):
branch_0 = slim.conv2d(inputs, 384, [1, 1], scope='Conv2d_0a_1x1')
with variable_scope.variable_scope('Branch_1'):
branch_1 = slim.conv2d(inputs, 192, [1, 1], scope='Conv2d_0a_1x1')
branch_1 = slim.conv2d(branch_1, 224, [1, 7], scope='Conv2d_0b_1x7')
branch_1 = slim.conv2d(branch_1, 256, [7, 1], scope='Conv2d_0c_7x1')
with variable_scope.variable_scope('Branch_2'):
branch_2 = slim.conv2d(inputs, 192, [1, 1], scope='Conv2d_0a_1x1')
branch_2 = slim.conv2d(branch_2, 192, [7, 1], scope='Conv2d_0b_7x1')
branch_2 = slim.conv2d(branch_2, 224, [1, 7], scope='Conv2d_0c_1x7')
branch_2 = slim.conv2d(branch_2, 224, [7, 1], scope='Conv2d_0d_7x1')
branch_2 = slim.conv2d(branch_2, 256, [1, 7], scope='Conv2d_0e_1x7')
with variable_scope.variable_scope('Branch_3'):
branch_3 = slim.avg_pool2d(inputs, [3, 3], scope='AvgPool_0a_3x3')
branch_3 = slim.conv2d(branch_3, 128, [1, 1], scope='Conv2d_0b_1x1')
return array_ops.concat(
axis=3, values=[branch_0, branch_1, branch_2, branch_3])
示例7: SSIM
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import avg_pool2d [as 别名]
def SSIM(self, x, y):
C1 = 0.01 ** 2
C2 = 0.03 ** 2
mu_x = slim.avg_pool2d(x, 3, 1, 'VALID')
mu_y = slim.avg_pool2d(y, 3, 1, 'VALID')
sigma_x = slim.avg_pool2d(x ** 2, 3, 1, 'VALID') - mu_x ** 2
sigma_y = slim.avg_pool2d(y ** 2, 3, 1, 'VALID') - mu_y ** 2
sigma_xy = slim.avg_pool2d(x * y , 3, 1, 'VALID') - mu_x * mu_y
SSIM_n = (2 * mu_x * mu_y + C1) * (2 * sigma_xy + C2)
SSIM_d = (mu_x ** 2 + mu_y ** 2 + C1) * (sigma_x + sigma_y + C2)
SSIM = SSIM_n / SSIM_d
return tf.clip_by_value((1 - SSIM) / 2, 0, 1)
示例8: SSIM
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import avg_pool2d [as 别名]
def SSIM(self, x, y):
C1 = 0.01 ** 2
C2 = 0.03 ** 2
x = tf.pad(x, [[0, 0], [1, 1], [1, 1], [0, 0]], mode='REFLECT')
y = tf.pad(y, [[0, 0], [1, 1], [1, 1], [0, 0]], mode='REFLECT')
mu_x = slim.avg_pool2d(x, 3, 1, 'VALID')
mu_y = slim.avg_pool2d(y, 3, 1, 'VALID')
sigma_x = slim.avg_pool2d(x ** 2, 3, 1, 'VALID') - mu_x ** 2
sigma_y = slim.avg_pool2d(y ** 2, 3, 1, 'VALID') - mu_y ** 2
sigma_xy = slim.avg_pool2d(x * y, 3, 1, 'VALID') - mu_x * mu_y
SSIM_n = (2 * mu_x * mu_y + C1) * (2 * sigma_xy + C2)
SSIM_d = (mu_x ** 2 + mu_y ** 2 + C1) * (sigma_x + sigma_y + C2)
SSIM = SSIM_n / SSIM_d
return tf.clip_by_value((1 - SSIM) / 2, 0, 1)
示例9: se_module
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import avg_pool2d [as 别名]
def se_module(input_net, ratio=16, reuse = None, scope = None):
with tf.variable_scope(scope, 'SE', [input_net], reuse=reuse):
h,w,c = tuple([dim.value for dim in input_net.shape[1:4]])
assert c % ratio == 0
hidden_units = int(c / ratio)
squeeze = slim.avg_pool2d(input_net, [h,w], padding='VALID')
excitation = slim.flatten(squeeze)
excitation = slim.fully_connected(excitation, hidden_units, scope='se_fc1',
weights_regularizer=None,
weights_initializer=slim.xavier_initializer(),
activation_fn=tf.nn.relu)
excitation = slim.fully_connected(excitation, c, scope='se_fc2',
weights_regularizer=None,
weights_initializer=slim.xavier_initializer(),
activation_fn=tf.nn.sigmoid)
excitation = tf.reshape(excitation, [-1,1,1,c])
output_net = input_net * excitation
return output_net
示例10: test_slim_lenet
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import avg_pool2d [as 别名]
def test_slim_lenet(self):
graph = tf.Graph()
with graph.as_default() as g:
inputs = tf.placeholder(tf.float32, shape=[None,28,28,1],
name='test_slim_lenet/input')
net = slim.conv2d(inputs, 4, [5,5], scope='conv1')
net = slim.avg_pool2d(net, [2,2], scope='pool1')
net = slim.conv2d(net, 6, [5,5], scope='conv2')
net = slim.max_pool2d(net, [2,2], scope='pool2')
net = slim.flatten(net, scope='flatten3')
net = slim.fully_connected(net, 10, scope='fc4')
net = slim.fully_connected(net, 10, activation_fn=None, scope='fc5')
output_name = [net.op.name]
self._test_tf_model(graph,
{"test_slim_lenet/input:0":[1,28,28,1]},
output_name, delta=1e-2)
示例11: SSIM
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import avg_pool2d [as 别名]
def SSIM(self, x, y):
C1 = 0.01 ** 2
C2 = 0.03 ** 2
mu_x = slim.avg_pool2d(x, 3, 1, 'VALID')
mu_y = slim.avg_pool2d(y, 3, 1, 'VALID')
sigma_x = slim.avg_pool2d(x ** 2, 3, 1, 'VALID') - mu_x ** 2
sigma_y = slim.avg_pool2d(y ** 2, 3, 1, 'VALID') - mu_y ** 2
sigma_xy = slim.avg_pool2d(x * y , 3, 1, 'VALID') - mu_x * mu_y
SSIM_n = (2 * mu_x * mu_y + C1) * (2 * sigma_xy + C2)
SSIM_d = (mu_x ** 2 + mu_y ** 2 + C1) * (sigma_x + sigma_y + C2)
SSIM = SSIM_n / SSIM_d
return tf.clip_by_value((1 - SSIM) / 2, 0, 1)
示例12: se_module
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import avg_pool2d [as 别名]
def se_module(input_net, ratio=16, reuse = None, scope = None):
with tf.variable_scope(scope, 'SE', [input_net], reuse=reuse):
h,w,c = tuple([dim.value for dim in input_net.shape[1:4]])
assert c % ratio == 0
hidden_units = int(c / ratio)
squeeze = slim.avg_pool2d(input_net, [h,w], padding='VALID')
excitation = slim.flatten(squeeze)
excitation = slim.fully_connected(excitation, hidden_units, scope='se_fc1',
weights_regularizer=None,
# weights_initializer=tf.truncated_normal_initializer(stddev=0.1),
weights_initializer=slim.xavier_initializer(),
activation_fn=tf.nn.relu)
excitation = slim.fully_connected(excitation, c, scope='se_fc2',
weights_regularizer=None,
# weights_initializer=tf.truncated_normal_initializer(stddev=0.1),
weights_initializer=slim.xavier_initializer(),
activation_fn=tf.nn.sigmoid)
excitation = tf.reshape(excitation, [-1,1,1,c])
output_net = input_net * excitation
return output_net
示例13: SSIM
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import avg_pool2d [as 别名]
def SSIM(self, x, y):
C1 = 0.01 ** 2
C2 = 0.03 ** 2
mu_x = slim.avg_pool2d(x, 3, 1, 'SAME')
mu_y = slim.avg_pool2d(y, 3, 1, 'SAME')
sigma_x = slim.avg_pool2d(x ** 2, 3, 1, 'SAME') - mu_x ** 2
sigma_y = slim.avg_pool2d(y ** 2, 3, 1, 'SAME') - mu_y ** 2
sigma_xy = slim.avg_pool2d(x * y , 3, 1, 'SAME') - mu_x * mu_y
SSIM_n = (2 * mu_x * mu_y + C1) * (2 * sigma_xy + C2)
SSIM_d = (mu_x ** 2 + mu_y ** 2 + C1) * (sigma_x + sigma_y + C2)
SSIM = SSIM_n / SSIM_d
return tf.clip_by_value((1 - SSIM) / 2, 0, 1)
示例14: build_simple_conv_net
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import avg_pool2d [as 别名]
def build_simple_conv_net(images, flags, is_training, reuse=None, scope=None):
conv2d_arg_scope, dropout_arg_scope = _get_scope(is_training, flags)
with conv2d_arg_scope, dropout_arg_scope:
with tf.variable_scope(scope or 'feature_extractor', reuse=reuse):
h = images
for i in range(4):
h = slim.conv2d(h, num_outputs=flags.num_filters, kernel_size=3, stride=1,
scope='conv' + str(i), padding='SAME',
weights_initializer=ScaledVarianceRandomNormal(factor=flags.weights_initializer_factor))
h = slim.max_pool2d(h, kernel_size=2, stride=2, padding='VALID', scope='max_pool' + str(i))
if flags.embedding_pooled == True:
kernel_size = h.shape.as_list()[-2]
h = slim.avg_pool2d(h, kernel_size=kernel_size, scope='avg_pool')
h = slim.flatten(h)
return h
示例15: avgpool
# 需要导入模块: from tensorflow.contrib import slim [as 别名]
# 或者: from tensorflow.contrib.slim import avg_pool2d [as 别名]
def avgpool(x,kernel_size,strides=2,padding='same'):
x=slim.avg_pool2d(x,kernel_size,strides,padding=padding)
return x