本文整理汇总了Python中tensorflow.contrib.layers.avg_pool2d方法的典型用法代码示例。如果您正苦于以下问题:Python layers.avg_pool2d方法的具体用法?Python layers.avg_pool2d怎么用?Python layers.avg_pool2d使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.contrib.layers
的用法示例。
在下文中一共展示了layers.avg_pool2d方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _block_a
# 需要导入模块: from tensorflow.contrib import layers [as 别名]
# 或者: from tensorflow.contrib.layers import avg_pool2d [as 别名]
def _block_a(net, scope='BlockA'):
# 35 x 35 x 384 grid
# default padding = SAME
# default stride = 1
with tf.variable_scope(scope):
with tf.variable_scope('Br1_Pool'):
br1 = layers.avg_pool2d(net, [3, 3], scope='Pool1_3x3')
br1 = layers.conv2d(br1, 96, [1, 1], scope='Conv1_1x1')
with tf.variable_scope('Br2_1x1'):
br2 = layers.conv2d(net, 96, [1, 1], scope='Conv1_1x1')
with tf.variable_scope('Br3_3x3'):
br3 = layers.conv2d(net, 64, [1, 1], scope='Conv1_1x1')
br3 = layers.conv2d(br3, 96, [3, 3], scope='Conv2_3x3')
with tf.variable_scope('Br4_3x3Dbl'):
br4 = layers.conv2d(net, 64, [1, 1], scope='Conv1_1x1')
br4 = layers.conv2d(br4, 96, [3, 3], scope='Conv2_3x3')
br4 = layers.conv2d(br4, 96, [3, 3], scope='Conv3_3x3')
net = tf.concat(3, [br1, br2, br3, br4], name='Concat1')
# 35 x 35 x 384
return net
示例2: _block_b
# 需要导入模块: from tensorflow.contrib import layers [as 别名]
# 或者: from tensorflow.contrib.layers import avg_pool2d [as 别名]
def _block_b(net, scope='BlockB'):
# 17 x 17 x 1024 grid
# default padding = SAME
# default stride = 1
with tf.variable_scope(scope):
with tf.variable_scope('Br1_Pool'):
br1 = layers.avg_pool2d(net, [3, 3], scope='Pool1_3x3')
br1 = layers.conv2d(br1, 128, [1, 1], scope='Conv1_1x1')
with tf.variable_scope('Br2_1x1'):
br2 = layers.conv2d(net, 384, [1, 1], scope='Conv1_1x1')
with tf.variable_scope('Br3_7x7'):
br3 = layers.conv2d(net, 192, [1, 1], scope='Conv1_1x1')
br3 = layers.conv2d(br3, 224, [1, 7], scope='Conv2_1x7')
br3 = layers.conv2d(br3, 256, [7, 1], scope='Conv3_7x1')
with tf.variable_scope('Br4_7x7Dbl'):
br4 = layers.conv2d(net, 192, [1, 1], scope='Conv1_1x1')
br4 = layers.conv2d(br4, 192, [1, 7], scope='Conv2_1x7')
br4 = layers.conv2d(br4, 224, [7, 1], scope='Conv3_7x1')
br4 = layers.conv2d(br4, 224, [1, 7], scope='Conv4_1x7')
br4 = layers.conv2d(br4, 256, [7, 1], scope='Conv5_7x1')
net = tf.concat(3, [br1, br2, br3, br4], name='Concat1')
# 17 x 17 x 1024
return net
示例3: _block_b_reduce
# 需要导入模块: from tensorflow.contrib import layers [as 别名]
# 或者: from tensorflow.contrib.layers import avg_pool2d [as 别名]
def _block_b_reduce(net, endpoints, scope='BlockReduceB'):
# 17 x 17 -> 8 x 8 reduce
with arg_scope([layers.conv2d, layers.max_pool2d, layers.avg_pool2d], padding='VALID'):
with tf.variable_scope(scope):
with tf.variable_scope('Br1_Pool'):
br1 = layers.max_pool2d(net, [3, 3], stride=2, scope='Pool1_3x3/2')
with tf.variable_scope('Br2_3x3'):
br2 = layers.conv2d(net, 192, [1, 1], padding='SAME', scope='Conv1_1x1')
br2 = layers.conv2d(br2, 192, [3, 3], stride=2, scope='Conv2_3x3/2')
with tf.variable_scope('Br3_7x7x3'):
br3 = layers.conv2d(net, 256, [1, 1], padding='SAME', scope='Conv1_1x1')
br3 = layers.conv2d(br3, 256, [1, 7], padding='SAME', scope='Conv2_1x7')
br3 = layers.conv2d(br3, 320, [7, 1], padding='SAME', scope='Conv3_7x1')
br3 = layers.conv2d(br3, 320, [3, 3], stride=2, scope='Conv4_3x3/2')
net = tf.concat(3, [br1, br2, br3], name='Concat1')
endpoints[scope] = net
print('%s output shape: %s' % (scope, net.get_shape()))
return net
示例4: _squeezenet
# 需要导入模块: from tensorflow.contrib import layers [as 别名]
# 或者: from tensorflow.contrib.layers import avg_pool2d [as 别名]
def _squeezenet(images, num_classes=1000, data_format='NCHW'):
net = conv2d(images, 96, [2, 2], stride=2, scope='conv1')
net = max_pool2d(net, [3, 3], stride=2, scope='maxpool1')
net = fire_module(net, 16, 64, scope='fire2', data_format=data_format)
net = fire_module(net, 16, 64, scope='fire3', data_format=data_format)
net = fire_module(net, 32, 128, scope='fire4', data_format=data_format)
net = max_pool2d(net, [3, 3], stride=2, scope='maxpool4')
net = fire_module(net, 32, 128, scope='fire5', data_format=data_format)
net = fire_module(net, 48, 192, scope='fire6', data_format=data_format)
net = fire_module(net, 48, 192, scope='fire7', data_format=data_format)
net = fire_module(net, 64, 256, scope='fire8', data_format=data_format)
net = max_pool2d(net, [3, 3], stride=2, scope='maxpool8')
net = fire_module(net, 64, 256, scope='fire9', data_format=data_format)
net = conv2d(net, num_classes, [1, 1], stride=1, scope='conv10')
net = avg_pool2d(net, [13, 13], stride=1, scope='avgpool10')
squeeze_axes = [2, 3] if data_format == 'NCHW' else [1, 2]
logits = tf.squeeze(net, squeeze_axes, name='logits')
return logits
示例5: _squeezenet
# 需要导入模块: from tensorflow.contrib import layers [as 别名]
# 或者: from tensorflow.contrib.layers import avg_pool2d [as 别名]
def _squeezenet(images, num_classes=1000):
net = conv2d(images, 96, [7, 7], stride=2, scope='conv1')
net = max_pool2d(net, [3, 3], stride=2, scope='maxpool1')
net = fire_module(net, 16, 64, scope='fire2')
net = fire_module(net, 16, 64, scope='fire3')
net = fire_module(net, 32, 128, scope='fire4')
net = max_pool2d(net, [3, 3], stride=2, scope='maxpool4')
net = fire_module(net, 32, 128, scope='fire5')
net = fire_module(net, 48, 192, scope='fire6')
net = fire_module(net, 48, 192, scope='fire7')
net = fire_module(net, 64, 256, scope='fire8')
net = max_pool2d(net, [3, 3], stride=2, scope='maxpool8')
net = fire_module(net, 64, 256, scope='fire9')
net = conv2d(net, num_classes, [1, 1], stride=1, scope='conv10')
net = avg_pool2d(net, [13, 13], stride=1, scope='avgpool10')
logits = tf.squeeze(net, [2], name='logits')
return logits
示例6: avg_pool2d
# 需要导入模块: from tensorflow.contrib import layers [as 别名]
# 或者: from tensorflow.contrib.layers import avg_pool2d [as 别名]
def avg_pool2d(self, *args, **kwargs):
return self._pass_through_mask(
self._function_dict['avg_pool2d'], *args, **kwargs)
示例7: _block_a_reduce
# 需要导入模块: from tensorflow.contrib import layers [as 别名]
# 或者: from tensorflow.contrib.layers import avg_pool2d [as 别名]
def _block_a_reduce(net, endpoints, k=192, l=224, m=256, n=384, scope='BlockReduceA'):
# 35 x 35 -> 17 x 17 reduce
# inception-v4: k=192, l=224, m=256, n=384
# inception-resnet-v1: k=192, l=192, m=256, n=384
# inception-resnet-v2: k=256, l=256, m=384, n=384
# default padding = VALID
# default stride = 1
with arg_scope([layers.conv2d, layers.max_pool2d, layers.avg_pool2d], padding='VALID'):
with tf.variable_scope(scope):
with tf.variable_scope('Br1_Pool'):
br1 = layers.max_pool2d(net, [3, 3], stride=2, scope='Pool1_3x3/2')
# 17 x 17 x input
with tf.variable_scope('Br2_3x3'):
br2 = layers.conv2d(net, n, [3, 3], stride=2, scope='Conv1_3x3/2')
# 17 x 17 x n
with tf.variable_scope('Br3_3x3Dbl'):
br3 = layers.conv2d(net, k, [1, 1], padding='SAME', scope='Conv1_1x1')
br3 = layers.conv2d(br3, l, [3, 3], padding='SAME', scope='Conv2_3x3')
br3 = layers.conv2d(br3, m, [3, 3], stride=2, scope='Conv3_3x3/2')
# 17 x 17 x m
net = tf.concat(3, [br1, br2, br3], name='Concat1')
# 17 x 17 x input + n + m
# 1024 for v4 (384 + 384 + 256)
# 896 for res-v1 (256 + 384 +256)
# 1152 for res-v2 (384 + 384 + 384)
endpoints[scope] = net
print('%s output shape: %s' % (scope, net.get_shape()))
return net
示例8: _block_stem_res
# 需要导入模块: from tensorflow.contrib import layers [as 别名]
# 或者: from tensorflow.contrib.layers import avg_pool2d [as 别名]
def _block_stem_res(net, endpoints, scope='Stem'):
# Simpler _stem for inception-resnet-v1 network
# NOTE observe endpoints of first 3 layers
# default padding = VALID
# default stride = 1
with arg_scope([layers.conv2d, layers.max_pool2d, layers.avg_pool2d], padding='VALID'):
with tf.variable_scope(scope):
# 299 x 299 x 3
net = layers.conv2d(net, 32, [3, 3], stride=2, scope='Conv1_3x3/2')
endpoints[scope + '/Conv1'] = net
# 149 x 149 x 32
net = layers.conv2d(net, 32, [3, 3], scope='Conv2_3x3')
endpoints[scope + '/Conv2'] = net
# 147 x 147 x 32
net = layers.conv2d(net, 64, [3, 3], padding='SAME', scope='Conv3_3x3')
endpoints[scope + '/Conv3'] = net
# 147 x 147 x 64
net = layers.max_pool2d(net, [3, 3], stride=2, scope='Pool1_3x3/2')
# 73 x 73 x 64
net = layers.conv2d(net, 80, [1, 1], padding='SAME', scope='Conv4_1x1')
# 73 x 73 x 80
net = layers.conv2d(net, 192, [3, 3], scope='Conv5_3x3')
# 71 x 71 x 192
net = layers.conv2d(net, 256, [3, 3], stride=2, scope='Conv6_3x3/2')
# 35 x 35 x 256
endpoints[scope] = net
print('%s output shape: %s' % (scope, net.get_shape()))
return net
示例9: _block_b_reduce_res
# 需要导入模块: from tensorflow.contrib import layers [as 别名]
# 或者: from tensorflow.contrib.layers import avg_pool2d [as 别名]
def _block_b_reduce_res(net, endpoints, ver=2, scope='BlockReduceB'):
# 17 x 17 -> 8 x 8 reduce
# configure branch filter numbers
br3_num = 256
br4_num = 256
if ver == 1:
br3_inc = 0
br4_inc = 0
else:
br3_inc = 32
br4_inc = 32
with arg_scope([layers.conv2d, layers.max_pool2d, layers.avg_pool2d], padding='VALID'):
with tf.variable_scope(scope):
with tf.variable_scope('Br1_Pool'):
br1 = layers.max_pool2d(net, [3, 3], stride=2, scope='Pool1_3x3/2')
with tf.variable_scope('Br2_3x3'):
br2 = layers.conv2d(net, 256, [1, 1], padding='SAME', scope='Conv1_1x1')
br2 = layers.conv2d(br2, 384, [3, 3], stride=2, scope='Conv2_3x3/2')
with tf.variable_scope('Br3_3x3'):
br3 = layers.conv2d(net, br3_num, [1, 1], padding='SAME', scope='Conv1_1x1')
br3 = layers.conv2d(br3, br3_num + br3_inc, [3, 3], stride=2, scope='Conv2_3x3/2')
with tf.variable_scope('Br4_3x3Dbl'):
br4 = layers.conv2d(net, br4_num, [1, 1], padding='SAME', scope='Conv1_1x1')
br4 = layers.conv2d(br4, br4_num + 1*br4_inc, [3, 3], padding='SAME', scope='Conv2_3x3')
br4 = layers.conv2d(br4, br4_num + 2*br4_inc, [3, 3], stride=2, scope='Conv3_3x3/2')
net = tf.concat(3, [br1, br2, br3, br4], name='Concat1')
# 8 x 8 x 1792 v1, 2144 v2 (paper indicates 2048 but only get this if we use a v1 config for this block)
endpoints[scope] = net
print('%s output shape: %s' % (scope, net.get_shape()))
return net
示例10: _block_output
# 需要导入模块: from tensorflow.contrib import layers [as 别名]
# 或者: from tensorflow.contrib.layers import avg_pool2d [as 别名]
def _block_output(net, endpoints, num_classes=1000, dropout_keep_prob=0.5, scope='Output'):
with tf.variable_scope(scope):
# 8 x 8 x 1536
shape = net.get_shape()
net = layers.avg_pool2d(net, shape[1:3], padding='VALID', scope='Pool1_Global')
endpoints['Output/Pool1'] = net
# 1 x 1 x 1536
net = layers.dropout(net, dropout_keep_prob)
net = layers.flatten(net)
# 1536
net = layers.fully_connected(net, num_classes, activation_fn=None, scope='Logits')
# num classes
endpoints['Logits'] = net
return net
示例11: _output
# 需要导入模块: from tensorflow.contrib import layers [as 别名]
# 或者: from tensorflow.contrib.layers import avg_pool2d [as 别名]
def _output(net, endpoints, num_classes, pre_act=False):
with tf.variable_scope('Output'):
if pre_act:
net = layers.batch_norm(net, activation_fn=tf.nn.relu)
shape = net.get_shape()
net = layers.avg_pool2d(net, shape[1:3], scope='Pool1_Global')
endpoints['OutputPool1'] = net
net = layers.flatten(net)
net = layers.fully_connected(net, num_classes, activation_fn=None, scope='Logits')
endpoints['Logits'] = net
# num_classes
return net
示例12: inception_v3_figure5_downsample
# 需要导入模块: from tensorflow.contrib import layers [as 别名]
# 或者: from tensorflow.contrib.layers import avg_pool2d [as 别名]
def inception_v3_figure5_downsample(
name, x, end_points,
act_fn, norm_fn, norm_params, winit_fn,
filters=[[64,96,96,], [384,],],
is_avg_pooling=True):
with tf.variable_scope(name):
with tf.variable_scope('branch0'):
branch_0 = tcl.conv2d(x, filters[0][0], 1,
stride=1, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params,
padding='SAME', weights_initializer=winit_fn, scope='conv2d_0a_1x1')
branch_0 = tcl.conv2d(branch_0, filters[0][1], 3,
stride=1, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params,
padding='SAME', weights_initializer=winit_fn, scope='conv2d_0b_3x3')
branch_0 = tcl.conv2d(branch_0, filters[0][2], 3,
stride=2, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params,
padding='VALID', weights_initializer=winit_fn, scope='conv2d_0c_3x3')
with tf.variable_scope('branch1'):
branch_1 = tcl.conv2d(x, filters[1][0], 3,
stride=2, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params,
padding='VALID', weights_initializer=winit_fn, scope='conv2d_1a_3x3')
with tf.variable_scope('branch2'):
if is_avg_pooling:
branch_2 = tcl.avg_pool2d(x, 3, stride=2,
padding='VALID', scope='avgpool_2a_3x3')
else:
branch_2 = tcl.max_pool2d(x, 3, stride=2,
padding='VALID', scope='maxpool_2a_3x3')
x = tf.concat(axis=3, values=[branch_0, branch_1, branch_2])
end_points[name] = x
return x, end_points
示例13: inception_v3_figure6_downsample
# 需要导入模块: from tensorflow.contrib import layers [as 别名]
# 或者: from tensorflow.contrib.layers import avg_pool2d [as 别名]
def inception_v3_figure6_downsample(
name, x, end_points, n,
act_fn, norm_fn, norm_params, winit_fn,
filters=[[192,192,192,192,], [192,320], [192], [192]],
is_avg_pooling=True):
with tf.variable_scope(name):
with tf.variable_scope('branch0'):
branch_0 = tcl.conv2d(x, filters[0][0], 1,
stride=1, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params,
padding='SAME', weights_initializer=winit_fn, scope='conv2d_0a_1x1')
branch_0 = tcl.conv2d(branch_0, filters[0][1], [1, n],
stride=1, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params,
padding='SAME', weights_initializer=winit_fn, scope='conv2d_0b_1xn')
branch_0 = tcl.conv2d(branch_0, filters[0][2], [n, 1],
stride=1, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params,
padding='SAME', weights_initializer=winit_fn, scope='conv2d_0c_nx1')
branch_0 = tcl.conv2d(branch_0, filters[0][3], [3, 3],
stride=2, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params,
padding='VALID', weights_initializer=winit_fn, scope='conv2d_0d_3x3')
with tf.variable_scope('branch1'):
branch_1 = tcl.conv2d(x, filters[1][0], 1,
stride=1, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params,
padding='SAME', weights_initializer=winit_fn, scope='conv2d_1a_1x1')
branch_1 = tcl.conv2d(branch_1, filters[1][1], [3, 3],
stride=2, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params,
padding='VALID', weights_initializer=winit_fn, scope='conv2d_1b_3x3')
with tf.variable_scope('branch2'):
if is_avg_pooling:
branch_2 = tcl.avg_pool2d(x, 3,
padding='VALID', stride=2, scope='avgpool_2a_3x3')
else:
branch_2 = tcl.max_pool2d(x, 3,
padding='VALID', stride=2, scope='maxpool_2a_3x3')
x = tf.concat(axis=3, values=[branch_0, branch_1, branch_2])
end_points[name] = x
return x, end_points
示例14: avg_pool
# 需要导入模块: from tensorflow.contrib import layers [as 别名]
# 或者: from tensorflow.contrib.layers import avg_pool2d [as 别名]
def avg_pool(_input, k=2, s=2):
padding = 'VALID'
output = avg_pool2d(
_input, kernel_size=[
k, k], stride=[
s, s], padding=padding, data_format='NHWC')
return output
示例15: _arg_scope
# 需要导入模块: from tensorflow.contrib import layers [as 别名]
# 或者: from tensorflow.contrib.layers import avg_pool2d [as 别名]
def _arg_scope(is_training, weight_decay, bn_decay, data_format):
with arg_scope([conv2d],
weights_regularizer=l2_regularizer(weight_decay),
normalizer_fn=batch_norm,
normalizer_params={'is_training': is_training,
'fused': True,
'decay': bn_decay}):
with arg_scope([conv2d, avg_pool2d, max_pool2d, batch_norm],
data_format=data_format) as sc:
return sc