Python tensorflow.contrib.layers.avg_pool2d() Examples
The following are 24
code examples of tensorflow.contrib.layers.avg_pool2d().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tensorflow.contrib.layers
, or try the search function
.
Example #1
Source File: squeezenet.py From DirectML with MIT License | 6 votes |
def _squeezenet(images, num_classes=200, data_format='NCHW'): net = conv2d(images, 96, [2, 2], scope='conv1') net = max_pool2d(net, [2, 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, [2, 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, [2, 2], scope='maxpool8') net = fire_module(net, 64, 256, scope='fire9', data_format=data_format) net = avg_pool2d(net, [7, 7], scope='avgpool10') net = conv2d(net, num_classes, [1, 1], activation_fn=None, normalizer_fn=None, scope='conv10') squeeze_axes = [2, 3] if data_format == 'NCHW' else [1, 2] logits = tf.squeeze(net, squeeze_axes, name='logits') return logits
Example #2
Source File: build_inception_v4.py From tensorflow-litterbox with Apache License 2.0 | 6 votes |
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
Example #3
Source File: squeezenet.py From DirectML with MIT License | 6 votes |
def _squeezenet(images, num_classes=10, data_format='NCHW'): net = conv2d(images, 96, [2, 2], scope='conv1') net = max_pool2d(net, [2, 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, [2, 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, [2, 2], scope='maxpool8') net = fire_module(net, 64, 256, scope='fire9', data_format=data_format) net = avg_pool2d(net, [4, 4], scope='avgpool10') net = conv2d(net, num_classes, [1, 1], activation_fn=None, normalizer_fn=None, scope='conv10') squeeze_axes = [2, 3] if data_format == 'NCHW' else [1, 2] logits = tf.squeeze(net, squeeze_axes, name='logits') return logits
Example #4
Source File: build_inception_v4.py From tensorflow-litterbox with Apache License 2.0 | 6 votes |
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
Example #5
Source File: build_inception_v4.py From tensorflow-litterbox with Apache License 2.0 | 6 votes |
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
Example #6
Source File: squeezenet.py From DirectML with MIT License | 6 votes |
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
Example #7
Source File: squeezenet.py From squeezenet with MIT License | 6 votes |
def _squeezenet(images, num_classes=10): net = conv2d(images, 96, [2, 2], scope='conv1') net = max_pool2d(net, [2, 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, [2, 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, [2, 2], scope='maxpool8') net = fire_module(net, 64, 256, scope='fire9') net = avg_pool2d(net, [4, 4], scope='avgpool10') net = conv2d(net, num_classes, [1, 1], activation_fn=None, normalizer_fn=None, scope='conv10') logits = tf.squeeze(net, [2], name='logits') return logits
Example #8
Source File: squeezenet.py From squeezenet with MIT License | 6 votes |
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
Example #9
Source File: build_resnet.py From tensorflow-litterbox with Apache License 2.0 | 5 votes |
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
Example #10
Source File: tf_layers.py From proxylessnas with Apache License 2.0 | 5 votes |
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
Example #11
Source File: inception_block.py From VAE-GAN with MIT License | 5 votes |
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
Example #12
Source File: squeezenet.py From DirectML with MIT License | 5 votes |
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
Example #13
Source File: inception_block.py From VAE-GAN with MIT License | 5 votes |
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
Example #14
Source File: configurable_ops.py From morph-net with Apache License 2.0 | 5 votes |
def avg_pool2d(self, *args, **kwargs): return self._pass_through_mask( self._function_dict['avg_pool2d'], *args, **kwargs)
Example #15
Source File: build_inception_v4.py From tensorflow-litterbox with Apache License 2.0 | 5 votes |
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
Example #16
Source File: build_inception_v4.py From tensorflow-litterbox with Apache License 2.0 | 5 votes |
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
Example #17
Source File: build_inception_v4.py From tensorflow-litterbox with Apache License 2.0 | 5 votes |
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
Example #18
Source File: build_inception_v4.py From tensorflow-litterbox with Apache License 2.0 | 5 votes |
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
Example #19
Source File: squeezenet.py From squeezenet with MIT License | 5 votes |
def _arg_scope(is_training, weight_decay, bn_decay): 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='NCHW') as sc: return sc
Example #20
Source File: inception_block.py From VAE-GAN with MIT License | 4 votes |
def inception_v3_figure5( name, x, end_points, act_fn, norm_fn, norm_params, winit_fn, filters=[[64,96,96,], [48,64,], [64], [64]], 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=1, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params, padding='SAME', weights_initializer=winit_fn, scope='conv2d_0c_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, stride=1, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params, padding='SAME', weights_initializer=winit_fn, scope='conv2d_1b_3x3') with tf.variable_scope('branch2'): if is_avg_pooling: branch_2 = tcl.avg_pool2d(x, 3, stride=1, padding='SAME', scope='avgpool_2a_3x3') else: branch_2 = tcl.max_pool2d(x, 3, stride=1, padding='SAME', scope='maxpool_2a_3x3') if not downsample: branch_2 = tcl.conv2d(branch_2, filters[2][0], 1, stride=1, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params, padding='SAME', weights_initializer=winit_fn, scope='conv2d_2b_1x1') with tf.variable_scope('branch3'): branch_3 = tcl.conv2d(x, filters[3][0], 1, stride=1, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params, padding='SAME', weights_initializer=winit_fn, scope='conv2d_3a_1x1') x = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3]) end_points[name] = x return x, end_points
Example #21
Source File: inception_block.py From VAE-GAN with MIT License | 4 votes |
def inception_v3_figure6( name, x, end_points, n, act_fn, norm_fn, norm_params, winit_fn, filters=[[128,128,128,128,192,], [128,128,192,], [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], [1, n], stride=1, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params, padding='SAME', weights_initializer=winit_fn, scope='conv2d_0d_1xn') branch_0 = tcl.conv2d(branch_0, filters[0][4], [n, 1], stride=1, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params, padding='SAME', weights_initializer=winit_fn, scope='conv2d_0e_nx1') 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], [1, n], stride=1, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params, padding='SAME', weights_initializer=winit_fn, scope='conv2d_1b_1xn') branch_1 = tcl.conv2d(branch_1, filters[1][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_1c_nx1') with tf.variable_scope('branch2'): if is_avg_pooling: branch_2 = tcl.avg_pool2d(x, 3, padding='SAME', stride=1, scope='avgpool_2a_3x3') else: branch_2 = tcl.max_pool2d(x, 3, padding='SAME', stride=1, scope='maxpool_2a_3x3') branch_2 = tcl.conv2d(branch_2, filters[2][0], 1, stride=1, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params, padding='SAME', weights_initializer=winit_fn, scope='conv2d_2b_1x1') with tf.variable_scope('branch3'): branch_3 = tcl.conv2d(x, filters[3][0], 1, stride=1, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params, padding='SAME', weights_initializer=winit_fn, scope='conv2d_3a_1x1') x = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3]) end_points[name] = x return x, end_points
Example #22
Source File: inception_block.py From VAE-GAN with MIT License | 4 votes |
def inception_v3_figure4( name, x, end_points, act_fn, norm_fn, norm_params, winit_fn, filters=[[48,64], [64,96,], [32], [64]], is_avg_pooling=True, downsample=False): if downsample: ds=2 else: ds=1 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], 5, stride=ds, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params, padding='SAME', weights_initializer=winit_fn, scope='conv2d_0b_5x5') 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, stride=ds, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params, padding='SAME', weights_initializer=winit_fn, scope='conv2d_1b_3x3') with tf.variable_scope('branch2'): if is_avg_pooling: branch_2 = tcl.avg_pool2d(x, 3, stride=ds, scope='avgpool_2a_3x3') else: branch_2 = tcl.max_pool2d(x, 3, stride=ds, scope='maxpool_2a_3x3') branch_2 = tcl.conv2d(branch_2, filters[2][0], 1, stride=1, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params, padding='SAME', weights_initializer=winit_fn, scope='conv2d_2b_1x1') with tf.variable_scope('branch3'): branch_3 = tcl.conv2d(x, filters[3][0], 1, stride=ds, activation_fn=act_fn, normalizer_fn=norm_fn, normalizer_params=norm_params, padding='SAME', weights_initializer=winit_fn, scope='conv2d_3a_1x1') x = tf.concat(axis=3, values=[branch_0, branch_1, branch_2, branch_3]) end_points[name] = x return x, end_points
Example #23
Source File: build_inception_v4.py From tensorflow-litterbox with Apache License 2.0 | 4 votes |
def _build_inception_v4( inputs, stack_counts=[4, 7, 3], dropout_keep_prob=0.8, num_classes=1000, is_training=True, scope=''): """Inception v4 from http://arxiv.org/abs/ Args: inputs: a tensor of size [batch_size, height, width, channels]. dropout_keep_prob: dropout keep_prob. num_classes: number of predicted classes. is_training: whether is training or not. scope: Optional scope for op_scope. Returns: a list containing 'logits' Tensors and a dict of Endpoints. """ # endpoints will collect relevant activations for external use, for example, summaries or losses. endpoints = {} name_scope_net = tf.name_scope(scope, 'Inception_v4', [inputs]) arg_scope_train = arg_scope([layers.batch_norm, layers.dropout], is_training=is_training) arg_scope_conv = arg_scope([layers.conv2d, layers.max_pool2d, layers.avg_pool2d], stride=1, padding='SAME') with name_scope_net, arg_scope_train, arg_scope_conv: net = _block_stem(inputs, endpoints) # 35 x 35 x 384 with tf.variable_scope('Scale1'): net = _stack(net, endpoints, fn=_block_a, count=stack_counts[0], scope='BlockA') # 35 x 35 x 384 with tf.variable_scope('Scale2'): net = _block_a_reduce(net, endpoints) # 17 x 17 x 1024 net = _stack(net, endpoints, fn=_block_b, count=stack_counts[1], scope='BlockB') # 17 x 17 x 1024 with tf.variable_scope('Scale3'): net = _block_b_reduce(net, endpoints) # 8 x 8 x 1536 net = _stack(net, endpoints, fn=_block_c, count=stack_counts[2], scope='BlockC') # 8 x 8 x 1536 logits = _block_output(net, endpoints, num_classes, dropout_keep_prob, scope='Output') endpoints['Predictions'] = tf.nn.softmax(logits, name='Predictions') return logits, endpoints
Example #24
Source File: build_inception_v4.py From tensorflow-litterbox with Apache License 2.0 | 4 votes |
def _block_stem(net, endpoints, scope='Stem'): # Stem shared by inception-v4 and inception-resnet-v2 (resnet-v1 uses simpler _stem below) # NOTE observe endpoints of first 3 layers 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 with tf.variable_scope('Br1A_Pool'): br1a = layers.max_pool2d(net, [3, 3], stride=2, scope='Pool1_3x3/2') with tf.variable_scope('Br1B_3x3'): br1b = layers.conv2d(net, 96, [3, 3], stride=2, scope='Conv4_3x3/2') net = tf.concat(3, [br1a, br1b], name='Concat1') endpoints[scope + '/Concat1'] = net # 73 x 73 x 160 with tf.variable_scope('Br2A_3x3'): br2a = layers.conv2d(net, 64, [1, 1], padding='SAME', scope='Conv5_1x1') br2a = layers.conv2d(br2a, 96, [3, 3], scope='Conv6_3x3') with tf.variable_scope('Br2B_7x7x3'): br2b = layers.conv2d(net, 64, [1, 1], padding='SAME', scope='Conv5_1x1') br2b = layers.conv2d(br2b, 64, [7, 1], padding='SAME', scope='Conv6_7x1') br2b = layers.conv2d(br2b, 64, [1, 7], padding='SAME', scope='Conv7_1x7') br2b = layers.conv2d(br2b, 96, [3, 3], scope='Conv8_3x3') net = tf.concat(3, [br2a, br2b], name='Concat2') endpoints[scope + '/Concat2'] = net # 71 x 71 x 192 with tf.variable_scope('Br3A_3x3'): br3a = layers.conv2d(net, 192, [3, 3], stride=2, scope='Conv9_3x3/2') with tf.variable_scope('Br3B_Pool'): br3b = layers.max_pool2d(net, [3, 3], stride=2, scope='Pool2_3x3/2') net = tf.concat(3, [br3a, br3b], name='Concat3') endpoints[scope + '/Concat3'] = net print('%s output shape: %s' % (scope, net.get_shape())) # 35x35x384 return net