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
def DepthwiseSeparableConvBlock(inputs, n_filters, kernel_size=[3, 3]): """ Builds the Depthwise Separable conv block for MobileNets Apply successivly a 2D separable convolution, BatchNormalization relu, conv, BatchNormalization, relu """ # Skip pointwise by setting num_outputs=None net = slim.separable_convolution2d(inputs, num_outputs=None, depth_multiplier=1, kernel_size=[3, 3], activation_fn=None) net = slim.batch_norm(net, fused=True) net = tf.nn.relu(net) net = slim.conv2d(net, n_filters, kernel_size=[1, 1], activation_fn=None) net = slim.batch_norm(net, fused=True) net = tf.nn.relu(net) return net