Python tensorflow.contrib.slim.avg_pool2d() Examples
The following are 30
code examples of tensorflow.contrib.slim.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.slim
, or try the search function
.
Example #1
Source File: sphere_net_PFE.py From Probabilistic-Face-Embeddings with MIT License | 6 votes |
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
Example #2
Source File: model.py From g-tensorflow-models with Apache License 2.0 | 6 votes |
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
Example #3
Source File: discriminator.py From COCO-GAN with MIT License | 6 votes |
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
Example #4
Source File: AM3_protonet++.py From am3 with Apache License 2.0 | 6 votes |
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
Example #5
Source File: protonet++.py From am3 with Apache License 2.0 | 6 votes |
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
Example #6
Source File: model.py From models with Apache License 2.0 | 6 votes |
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
Example #7
Source File: inception_v4_model.py From class-balanced-loss with MIT License | 6 votes |
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])
Example #8
Source File: inception_v4_model.py From class-balanced-loss with MIT License | 6 votes |
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])
Example #9
Source File: nasnet_model.py From benchmarks with Apache License 2.0 | 6 votes |
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
Example #10
Source File: model.py From multilabel-image-classification-tensorflow with MIT License | 6 votes |
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
Example #11
Source File: deep_slam.py From DeepMatchVO with MIT License | 6 votes |
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
Example #12
Source File: model.py From yolo_v2 with Apache License 2.0 | 6 votes |
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
Example #13
Source File: geonet_model.py From GeoNet with MIT License | 6 votes |
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)
Example #14
Source File: inception_v4_model.py From training_results_v0.5 with Apache License 2.0 | 6 votes |
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])
Example #15
Source File: sibling_shared_res.py From DocFace with MIT License | 6 votes |
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
Example #16
Source File: face_resnet.py From DocFace with MIT License | 6 votes |
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
Example #17
Source File: BaseLearner.py From DF-Net with MIT License | 6 votes |
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)
Example #18
Source File: model.py From Gun-Detector with Apache License 2.0 | 6 votes |
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
Example #19
Source File: test_tf_converter.py From tf-coreml with Apache License 2.0 | 6 votes |
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)
Example #20
Source File: inception_v4_model.py From tpu_models with Apache License 2.0 | 6 votes |
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])
Example #21
Source File: model.py From object_detection_with_tensorflow with MIT License | 6 votes |
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
Example #22
Source File: inception_v4_model.py From tpu_models with Apache License 2.0 | 6 votes |
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])
Example #23
Source File: monodepth_model.py From Semantic-Mono-Depth with MIT License | 6 votes |
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)
Example #24
Source File: monodepth2_learner.py From tf-monodepth2 with MIT License | 6 votes |
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)
Example #25
Source File: inception_v4_model.py From training_results_v0.5 with Apache License 2.0 | 6 votes |
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])
Example #26
Source File: layer_utils.py From centernet_tensorflow_wilderface_voc with MIT License | 5 votes |
def avgpool(x,kernel_size,strides=2,padding='same'): x=slim.avg_pool2d(x,kernel_size,strides,padding=padding) return x
Example #27
Source File: squeezenet.py From uai-sdk with Apache License 2.0 | 5 votes |
def inference(images, keep_probability, phase_train=True, bottleneck_layer_size=128, weight_decay=0.0, reuse=None): batch_norm_params = { # Decay for the moving averages. 'decay': 0.995, # epsilon to prevent 0s in variance. 'epsilon': 0.001, # force in-place updates of mean and variance estimates 'updates_collections': None, # Moving averages ends up in the trainable variables collection 'variables_collections': [ tf.GraphKeys.TRAINABLE_VARIABLES ], } with slim.arg_scope([slim.conv2d, slim.fully_connected], weights_initializer=slim.xavier_initializer_conv2d(uniform=True), weights_regularizer=slim.l2_regularizer(weight_decay), normalizer_fn=slim.batch_norm, normalizer_params=batch_norm_params): with tf.variable_scope('squeezenet', [images], reuse=reuse): with slim.arg_scope([slim.batch_norm, slim.dropout], is_training=phase_train): net = slim.conv2d(images, 96, [7, 7], stride=2, scope='conv1') net = slim.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 = slim.max_pool2d(net, [2, 2], 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 = slim.max_pool2d(net, [3, 3], stride=2, scope='maxpool8') net = fire_module(net, 64, 256, scope='fire9') net = slim.dropout(net, keep_probability) net = slim.conv2d(net, 1000, [1, 1], activation_fn=None, normalizer_fn=None, scope='conv10') net = slim.avg_pool2d(net, net.get_shape()[1:3], scope='avgpool10') net = tf.squeeze(net, [1, 2], name='logits') net = slim.fully_connected(net, bottleneck_layer_size, activation_fn=None, scope='Bottleneck', reuse=False) return net, None
Example #28
Source File: inception_v4_model.py From class-balanced-loss with MIT License | 5 votes |
def block_inception_c(inputs, scope=None, reuse=None): """Builds Inception-C 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, 'BlockInceptionC', [inputs], reuse=reuse): with variable_scope.variable_scope('Branch_0'): branch_0 = slim.conv2d(inputs, 256, [1, 1], scope='Conv2d_0a_1x1') with variable_scope.variable_scope('Branch_1'): branch_1 = slim.conv2d(inputs, 384, [1, 1], scope='Conv2d_0a_1x1') branch_1 = array_ops.concat( axis=3, values=[ slim.conv2d(branch_1, 256, [1, 3], scope='Conv2d_0b_1x3'), slim.conv2d(branch_1, 256, [3, 1], scope='Conv2d_0c_3x1') ]) with variable_scope.variable_scope('Branch_2'): branch_2 = slim.conv2d(inputs, 384, [1, 1], scope='Conv2d_0a_1x1') branch_2 = slim.conv2d(branch_2, 448, [3, 1], scope='Conv2d_0b_3x1') branch_2 = slim.conv2d(branch_2, 512, [1, 3], scope='Conv2d_0c_1x3') branch_2 = array_ops.concat( axis=3, values=[ slim.conv2d(branch_2, 256, [1, 3], scope='Conv2d_0d_1x3'), slim.conv2d(branch_2, 256, [3, 1], scope='Conv2d_0e_3x1') ]) 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, 256, [1, 1], scope='Conv2d_0b_1x1') return array_ops.concat( axis=3, values=[branch_0, branch_1, branch_2, branch_3])
Example #29
Source File: squeezenet.py From facenet with MIT License | 5 votes |
def inference(images, keep_probability, phase_train=True, bottleneck_layer_size=128, weight_decay=0.0, reuse=None): batch_norm_params = { # Decay for the moving averages. 'decay': 0.995, # epsilon to prevent 0s in variance. 'epsilon': 0.001, # force in-place updates of mean and variance estimates 'updates_collections': None, # Moving averages ends up in the trainable variables collection 'variables_collections': [ tf.GraphKeys.TRAINABLE_VARIABLES ], } with slim.arg_scope([slim.conv2d, slim.fully_connected], weights_initializer=slim.xavier_initializer_conv2d(uniform=True), weights_regularizer=slim.l2_regularizer(weight_decay), normalizer_fn=slim.batch_norm, normalizer_params=batch_norm_params): with tf.variable_scope('squeezenet', [images], reuse=reuse): with slim.arg_scope([slim.batch_norm, slim.dropout], is_training=phase_train): net = slim.conv2d(images, 96, [7, 7], stride=2, scope='conv1') net = slim.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 = slim.max_pool2d(net, [2, 2], 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 = slim.max_pool2d(net, [3, 3], stride=2, scope='maxpool8') net = fire_module(net, 64, 256, scope='fire9') net = slim.dropout(net, keep_probability) net = slim.conv2d(net, 1000, [1, 1], activation_fn=None, normalizer_fn=None, scope='conv10') net = slim.avg_pool2d(net, net.get_shape()[1:3], scope='avgpool10') net = tf.squeeze(net, [1, 2], name='logits') net = slim.fully_connected(net, bottleneck_layer_size, activation_fn=None, scope='Bottleneck', reuse=False) return net, None
Example #30
Source File: layers.py From mayo with MIT License | 5 votes |
def instantiate_average_pool(self, node, tensor, params): self._reduce_kernel_size_for_small_input(params, tensor) if self._should_pool_nothing(params): return tensor return slim.avg_pool2d(tensor, **params)