Python tensorflow.contrib.slim.convolution2d() Examples
The following are 9
code examples of tensorflow.contrib.slim.convolution2d().
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: network_base.py From tf-pose with Apache License 2.0 | 5 votes |
def separable_conv(self, input, k_h, k_w, c_o, stride, name, relu=True, set_bias=True): with slim.arg_scope([slim.batch_norm], decay=0.999, fused=common.batchnorm_fused, is_training=self.trainable): output = slim.separable_convolution2d(input, num_outputs=None, stride=stride, trainable=self.trainable, depth_multiplier=1.0, kernel_size=[k_h, k_w], # activation_fn=common.activation_fn if relu else None, activation_fn=None, # normalizer_fn=slim.batch_norm, weights_initializer=_init_xavier, # weights_initializer=_init_norm, weights_regularizer=_l2_regularizer_00004, biases_initializer=None, padding=DEFAULT_PADDING, scope=name + '_depthwise') output = slim.convolution2d(output, c_o, stride=1, kernel_size=[1, 1], activation_fn=common.activation_fn if relu else None, weights_initializer=_init_xavier, # weights_initializer=_init_norm, biases_initializer=_init_zero if set_bias else None, normalizer_fn=slim.batch_norm, trainable=self.trainable, weights_regularizer=None, scope=name + '_pointwise') return output
Example #2
Source File: network_base.py From tf-pose with Apache License 2.0 | 5 votes |
def convb(self, input, k_h, k_w, c_o, stride, name, relu=True, set_bias=True, set_tanh=False): with slim.arg_scope([slim.batch_norm], decay=0.999, fused=common.batchnorm_fused, is_training=self.trainable): output = slim.convolution2d(input, c_o, kernel_size=[k_h, k_w], stride=stride, normalizer_fn=slim.batch_norm, weights_regularizer=_l2_regularizer_convb, weights_initializer=_init_xavier, # weights_initializer=tf.truncated_normal_initializer(stddev=0.01), biases_initializer=_init_zero if set_bias else None, trainable=self.trainable, activation_fn=common.activation_fn if relu else None, scope=name) if set_tanh: output = tf.nn.sigmoid(output, name=name + '_extra_acv') return output
Example #3
Source File: network_base.py From MobileNetV2-PoseEstimation with MIT License | 5 votes |
def separable_conv(self, input, k_h, k_w, c_o, stride, name, relu=True, set_bias=True): with slim.arg_scope([slim.batch_norm], decay=0.999, fused=common.batchnorm_fused, is_training=self.trainable): output = slim.separable_convolution2d(input, num_outputs=None, stride=stride, trainable=self.trainable, depth_multiplier=1.0, kernel_size=[k_h, k_w], # activation_fn=common.activation_fn if relu else None, activation_fn=None, # normalizer_fn=slim.batch_norm, weights_initializer=_init_xavier, # weights_initializer=_init_norm, weights_regularizer=_l2_regularizer_00004, biases_initializer=None, padding=DEFAULT_PADDING, scope=name + '_depthwise') output = slim.convolution2d(output, c_o, stride=1, kernel_size=[1, 1], activation_fn=common.activation_fn if relu else None, weights_initializer=_init_xavier, # weights_initializer=_init_norm, biases_initializer=_init_zero if set_bias else None, normalizer_fn=slim.batch_norm, trainable=self.trainable, weights_regularizer=None, scope=name + '_pointwise') return output
Example #4
Source File: network_base.py From MobileNetV2-PoseEstimation with MIT License | 5 votes |
def convb(self, input, k_h, k_w, c_o, stride, name, relu=True, set_bias=True, set_tanh=False): with slim.arg_scope([slim.batch_norm], decay=0.999, fused=common.batchnorm_fused, is_training=self.trainable): output = slim.convolution2d(input, c_o, kernel_size=[k_h, k_w], stride=stride, normalizer_fn=slim.batch_norm, weights_regularizer=_l2_regularizer_convb, weights_initializer=_init_xavier, # weights_initializer=tf.truncated_normal_initializer(stddev=0.01), biases_initializer=_init_zero if set_bias else None, trainable=self.trainable, activation_fn=common.activation_fn if relu else None, scope=name) if set_tanh: output = tf.nn.sigmoid(output, name=name + '_extra_acv') return output
Example #5
Source File: mobilenetdet.py From MobileNet with Apache License 2.0 | 5 votes |
def mobilenet_arg_scope(weight_decay=0.0): """Defines the default mobilenet argument scope. Args: weight_decay: The weight decay to use for regularizing the model. Returns: An `arg_scope` to use for the MobileNet model. """ with slim.arg_scope( [slim.convolution2d, slim.separable_convolution2d], weights_initializer=slim.initializers.xavier_initializer(), biases_initializer=slim.init_ops.zeros_initializer(), weights_regularizer=slim.l2_regularizer(weight_decay)) as sc: return sc
Example #6
Source File: mobilenet.py From MobileNet with Apache License 2.0 | 5 votes |
def mobilenet_arg_scope(weight_decay=0.0): """Defines the default mobilenet argument scope. Args: weight_decay: The weight decay to use for regularizing the model. Returns: An `arg_scope` to use for the MobileNet model. """ with slim.arg_scope( [slim.convolution2d, slim.separable_convolution2d], weights_initializer=slim.initializers.xavier_initializer(), biases_initializer=slim.init_ops.zeros_initializer(), weights_regularizer=slim.l2_regularizer(weight_decay)) as sc: return sc
Example #7
Source File: network_base.py From tf-pose-estimation with Apache License 2.0 | 5 votes |
def separable_conv(self, input, k_h, k_w, c_o, stride, name, relu=True, set_bias=True): with slim.arg_scope([slim.batch_norm], decay=0.999, fused=common.batchnorm_fused, is_training=self.trainable): output = slim.separable_convolution2d(input, num_outputs=None, stride=stride, trainable=self.trainable, depth_multiplier=1.0, kernel_size=[k_h, k_w], # activation_fn=common.activation_fn if relu else None, activation_fn=None, # normalizer_fn=slim.batch_norm, weights_initializer=_init_xavier, # weights_initializer=_init_norm, weights_regularizer=_l2_regularizer_00004, biases_initializer=None, padding=DEFAULT_PADDING, scope=name + '_depthwise') output = slim.convolution2d(output, c_o, stride=1, kernel_size=[1, 1], activation_fn=common.activation_fn if relu else None, weights_initializer=_init_xavier, # weights_initializer=_init_norm, biases_initializer=_init_zero if set_bias else None, normalizer_fn=slim.batch_norm, trainable=self.trainable, weights_regularizer=None, scope=name + '_pointwise') return output
Example #8
Source File: network_base.py From tf-pose-estimation with Apache License 2.0 | 5 votes |
def convb(self, input, k_h, k_w, c_o, stride, name, relu=True, set_bias=True, set_tanh=False): with slim.arg_scope([slim.batch_norm], decay=0.999, fused=common.batchnorm_fused, is_training=self.trainable): output = slim.convolution2d(input, c_o, kernel_size=[k_h, k_w], stride=stride, normalizer_fn=slim.batch_norm, weights_regularizer=_l2_regularizer_convb, weights_initializer=_init_xavier, # weights_initializer=tf.truncated_normal_initializer(stddev=0.01), biases_initializer=_init_zero if set_bias else None, trainable=self.trainable, activation_fn=common.activation_fn if relu else None, scope=name) if set_tanh: output = tf.nn.sigmoid(output, name=name + '_extra_acv') return output
Example #9
Source File: mobilenetdet.py From MobileNet with Apache License 2.0 | 4 votes |
def mobilenet(inputs, is_training=True, width_multiplier=1, scope='MobileNet'): def _depthwise_separable_conv(inputs, num_pwc_filters, width_multiplier, sc, downsample=False): """ Helper function to build the depth-wise separable convolution layer. """ num_pwc_filters = round(num_pwc_filters * width_multiplier) _stride = 2 if downsample else 1 # skip pointwise by setting num_outputs=None depthwise_conv = slim.separable_convolution2d(inputs, num_outputs=None, stride=_stride, depth_multiplier=1, kernel_size=[3, 3], scope=sc+'/depthwise_conv') bn = slim.batch_norm(depthwise_conv, scope=sc+'/dw_batch_norm') pointwise_conv = slim.convolution2d(bn, num_pwc_filters, kernel_size=[1, 1], scope=sc+'/pointwise_conv') bn = slim.batch_norm(pointwise_conv, scope=sc+'/pw_batch_norm') return bn with tf.variable_scope(scope) as sc: end_points_collection = sc.name + '_end_points' with slim.arg_scope([slim.convolution2d, slim.separable_convolution2d], activation_fn=None, outputs_collections=[end_points_collection]): with slim.arg_scope([slim.batch_norm], is_training=is_training, activation_fn=tf.nn.relu): net = slim.convolution2d(inputs, round(32 * width_multiplier), [3, 3], stride=2, padding='SAME', scope='conv_1') net = slim.batch_norm(net, scope='conv_1/batch_norm') net = _depthwise_separable_conv(net, 64, width_multiplier, sc='conv_ds_2') net = _depthwise_separable_conv(net, 128, width_multiplier, downsample=True, sc='conv_ds_3') net = _depthwise_separable_conv(net, 128, width_multiplier, sc='conv_ds_4') net = _depthwise_separable_conv(net, 256, width_multiplier, downsample=True, sc='conv_ds_5') net = _depthwise_separable_conv(net, 256, width_multiplier, sc='conv_ds_6') net = _depthwise_separable_conv(net, 512, width_multiplier, downsample=True, sc='conv_ds_7') net = _depthwise_separable_conv(net, 512, width_multiplier, sc='conv_ds_8') net = _depthwise_separable_conv(net, 512, width_multiplier, sc='conv_ds_9') net = _depthwise_separable_conv(net, 512, width_multiplier, sc='conv_ds_10') net = _depthwise_separable_conv(net, 512, width_multiplier, sc='conv_ds_11') net = _depthwise_separable_conv(net, 512, width_multiplier, sc='conv_ds_12') net = _depthwise_separable_conv(net, 1024, width_multiplier, downsample=True, sc='conv_ds_13') net = _depthwise_separable_conv(net, 1024, width_multiplier, sc='conv_ds_14') end_points = slim.utils.convert_collection_to_dict(end_points_collection) return end_points