当前位置: 首页>>代码示例>>Python>>正文


Python layers.DepthwiseConv2D方法代码示例

本文整理汇总了Python中tensorflow.keras.layers.DepthwiseConv2D方法的典型用法代码示例。如果您正苦于以下问题:Python layers.DepthwiseConv2D方法的具体用法?Python layers.DepthwiseConv2D怎么用?Python layers.DepthwiseConv2D使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow.keras.layers的用法示例。


在下文中一共展示了layers.DepthwiseConv2D方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _keras_depthwise_conv2d_core

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import DepthwiseConv2D [as 别名]
def _keras_depthwise_conv2d_core(shape=None, data=None):
    assert shape is None or data is None
    if shape is None:
        shape = data.shape

    init = tf.keras.initializers.RandomNormal(seed=1)

    model = Sequential()
    c2d = DepthwiseConv2D(
        (3, 3),
        depthwise_initializer=init,
        data_format="channels_last",
        use_bias=False,
        input_shape=shape[1:],
    )
    model.add(c2d)

    if data is None:
        data = np.random.uniform(size=shape)
    out = model.predict(data)
    return model, out 
开发者ID:tf-encrypted,项目名称:tf-encrypted,代码行数:23,代码来源:convert_test.py

示例2: residual_block_id

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import DepthwiseConv2D [as 别名]
def residual_block_id(self,tensor, feature_n,name=None):
        if name != None:
            depconv_1  = DepthwiseConv2D(3,2,padding='same',name=name+"/dconv")(tensor)
            conv_2     = Conv2D(feature_n,1,name=name+"/conv")(depconv_1)
        else:
            depconv_1  = DepthwiseConv2D(3,2,padding='same')(tensor)
            conv_2     = Conv2D(feature_n,1)(depconv_1)


        maxpool_1  = MaxPool2D(pool_size=(2,2),strides=(2,2),padding='same')(tensor)
        conv_zeros = Conv2D(feature_n/2,2,strides=2,use_bias=False,kernel_initializer=tf.zeros_initializer())(tensor)

        padding_1  = Concatenate(axis=-1)([maxpool_1,conv_zeros])#self.feature_padding(maxpool_1)

        add = Add()([padding_1,conv_2])
        relu = ReLU()(add)

        return relu
    
    #def feature_padding(self,tensor,channels_n=0):
    #    #pad = tf.keras.layers.ZeroPadding2D(((0,0),(0,0),(0,tensor.shape[3])))(tensor)
    #    return Concatenate(axis=3)([tensor,pad]) 
开发者ID:SBoulanger,项目名称:blazepalm,代码行数:24,代码来源:palm_detector.py

示例3: _separable_conv

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import DepthwiseConv2D [as 别名]
def _separable_conv(name, kernel, stride, filters):
  def _separable_conv_layer(layer_input):
    output = layers.DepthwiseConv2D(name='{}/depthwise_conv'.format(name),
                                    kernel_size=kernel,
                                    strides=stride,
                                    depth_multiplier=1,
                                    padding=params.CONV_PADDING,
                                    use_bias=False,
                                    activation=None)(layer_input)
    output = _batch_norm(name='{}/depthwise_conv/bn'.format(name))(output)
    output = layers.ReLU(name='{}/depthwise_conv/relu'.format(name))(output)
    output = layers.Conv2D(name='{}/pointwise_conv'.format(name),
                           filters=filters,
                           kernel_size=(1, 1),
                           strides=1,
                           padding=params.CONV_PADDING,
                           use_bias=False,
                           activation=None)(output)
    output = _batch_norm(name='{}/pointwise_conv/bn'.format(name))(output)
    output = layers.ReLU(name='{}/pointwise_conv/relu'.format(name))(output)
    return output
  return _separable_conv_layer 
开发者ID:tensorflow,项目名称:models,代码行数:24,代码来源:yamnet.py

示例4: depthwiseConv_bn

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import DepthwiseConv2D [as 别名]
def depthwiseConv_bn(x, depth_multiplier, kernel_size,  strides=1):
	""" Depthwise convolution 
	The DepthwiseConv2D is just the first step of the Depthwise Separable convolution (without the pointwise step).
	Depthwise Separable convolutions consists in performing just the first step in a depthwise spatial convolution 
	(which acts on each input channel separately).
	
	This function defines a 2D Depthwise separable convolution operation with BN and relu6.
	# Arguments
		x: Tensor, input tensor of conv layer.
		filters: Integer, the dimensionality of the output space.
		kernel_size: An integer or tuple/list of 2 integers, specifying the
			width and height of the 2D convolution window.
		strides: An integer or tuple/list of 2 integers,
			specifying the strides of the convolution along the width and height.
			Can be a single integer to specify the same value for
			all spatial dimensions.
	# Returns
		Output tensor.
	"""

	x = layers.DepthwiseConv2D(kernel_size=kernel_size, strides=strides, depth_multiplier=depth_multiplier,
									padding='same', use_bias=False, kernel_regularizer=regularizers.l2(l=0.0003))(x)  
	x = layers.BatchNormalization(epsilon=1e-3, momentum=0.999)(x)  
	x = layers.ReLU(max_value=6)(x)
	return x 
开发者ID:1044197988,项目名称:TF.Keras-Commonly-used-models,代码行数:27,代码来源:MNasNet.py

示例5: xception_downsample_block

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import DepthwiseConv2D [as 别名]
def xception_downsample_block(x,channels,top_relu=False):
	##separable conv1
	if top_relu:
		x=Activation("relu")(x)
	x=DepthwiseConv2D((3,3),padding="same",use_bias=False)(x)
	x=BatchNormalization()(x)
	x=Conv2D(channels,(1,1),padding="same",use_bias=False)(x)
	x=BatchNormalization()(x)
	x=Activation("relu")(x)
	
	##separable conv2
	x=DepthwiseConv2D((3,3),padding="same",use_bias=False)(x)
	x=BatchNormalization()(x)
	x=Conv2D(channels,(1,1),padding="same",use_bias=False)(x)
	x=BatchNormalization()(x)
	x=Activation("relu")(x)
	
	##separable conv3
	x=DepthwiseConv2D((3,3),strides=(2,2),padding="same",use_bias=False)(x)
	x=BatchNormalization()(x)
	x=Conv2D(channels,(1,1),padding="same",use_bias=False)(x)
	x=BatchNormalization()(x)
	return x 
开发者ID:1044197988,项目名称:TF.Keras-Commonly-used-models,代码行数:25,代码来源:DeeplabV3+.py

示例6: xception_block

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import DepthwiseConv2D [as 别名]
def xception_block(x,channels):
	##separable conv1
	x=Activation("relu")(x)
	x=DepthwiseConv2D((3,3),padding="same",use_bias=False)(x)
	x=BatchNormalization()(x)
	x=Conv2D(channels,(1,1),padding="same",use_bias=False)(x)
	x=BatchNormalization()(x)
	
	##separable conv2
	x=Activation("relu")(x)
	x=DepthwiseConv2D((3,3),padding="same",use_bias=False)(x)
	x=BatchNormalization()(x)
	x=Conv2D(channels,(1,1),padding="same",use_bias=False)(x)
	x=BatchNormalization()(x)
	
	##separable conv3
	x=Activation("relu")(x)
	x=DepthwiseConv2D((3,3),padding="same",use_bias=False)(x)
	x=BatchNormalization()(x)
	x=Conv2D(channels,(1,1),padding="same",use_bias=False)(x)
	x=BatchNormalization()(x)
	return x 
开发者ID:1044197988,项目名称:TF.Keras-Commonly-used-models,代码行数:24,代码来源:DeeplabV3+.py

示例7: SepConv_BN

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import DepthwiseConv2D [as 别名]
def SepConv_BN(x, filters, prefix, stride=1, kernel_size=3, rate=1, depth_activation=False, epsilon=1e-3):
    if stride == 1:
        depth_padding = 'same'
    else:
        kernel_size_effective = kernel_size + (kernel_size - 1) * (rate - 1)
        pad_total = kernel_size_effective - 1
        pad_beg = pad_total // 2
        pad_end = pad_total - pad_beg
        x = ZeroPadding2D((pad_beg, pad_end))(x)
        depth_padding = 'valid'
    if not depth_activation:
        x = Activation('relu')(x)
    x = DepthwiseConv2D((kernel_size, kernel_size), strides=(stride, stride), dilation_rate=(rate, rate),
                        padding=depth_padding, use_bias=False, name=prefix + '_depthwise')(x)
    x = BatchNormalization(name=prefix + '_depthwise_BN', epsilon=epsilon)(x)
    if depth_activation:
        x = Activation('relu')(x)
    x = Conv2D(filters, (1, 1), padding='same',
               use_bias=False, name=prefix + '_pointwise')(x)
    x = BatchNormalization(name=prefix + '_pointwise_BN', epsilon=epsilon)(x)
    if depth_activation:
        x = Activation('relu')(x)
    return x 
开发者ID:1044197988,项目名称:TF.Keras-Commonly-used-models,代码行数:25,代码来源:ResUNet-a.py

示例8: __init__

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import DepthwiseConv2D [as 别名]
def __init__(self,
                 data_format="channels_last",
                 **kwargs):
        super(TF2Model, self).__init__(**kwargs)
        self.conv = nn.DepthwiseConv2D(
            # filters=channels,
            kernel_size=(7, 7),
            strides=2,
            padding="same",
            data_format=data_format,
            dilation_rate=1,
            use_bias=False,
            name="conv") 
开发者ID:osmr,项目名称:imgclsmob,代码行数:15,代码来源:convert_gl2tf2_dwconv2d.py

示例9: _inverted_bottleneck

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import DepthwiseConv2D [as 别名]
def _inverted_bottleneck(input, up_channel_rate, channels, is_subsample, kernel_size):
    if is_subsample:
        strides = (2, 2)
    else:
        strides = (1, 1)

    kernel_size = (kernel_size, kernel_size)

    # 1x1 conv2d
    x = layers.Conv2D(filters=up_channel_rate * input.shape[-1], kernel_size=(1, 1), strides=(1, 1), padding='SAME')(input)
    x = layers.BatchNormalization(momentum=0.999)(x)
    x = layers.ReLU(max_value=6)(x)

    # activation
    x = layers.ReLU()(x)

    # 3x3 separable_conv2d
    x = layers.DepthwiseConv2D(kernel_size=kernel_size, strides=strides, padding="SAME",
                               kernel_regularizer=l2_regularizer_00004)(x)
    # activation
    x = layers.ReLU()(x)

    # 1x1 conv2d
    x = layers.Conv2D(filters=channels, kernel_size=(1, 1), strides=(1, 1), padding='SAME')(x)
    x = layers.BatchNormalization(momentum=0.999)(x)
    x = layers.ReLU(max_value=6)(x)

    if input.shape[-1] == channels:
        x = input + x

    return x 
开发者ID:tucan9389,项目名称:tf2-mobile-pose-estimation,代码行数:33,代码来源:mv2_hourglass.py

示例10: _separable_conv

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import DepthwiseConv2D [as 别名]
def _separable_conv(input, channels, kernel_size, strides):
    # 3x3 separable_conv2d
    x = layers.DepthwiseConv2D(kernel_size=kernel_size, strides=strides, padding="SAME",
                               kernel_regularizer=l2_regularizer_00004)(input)
    # activation
    x = layers.ReLU()(x)

    # 1x1 conv2d
    x = layers.Conv2D(filters=channels, kernel_size=(1, 1), strides=(1, 1), padding='SAME')(x)
    x = layers.BatchNormalization(momentum=0.999)(x)
    x = layers.ReLU(max_value=6)(x)

    return x 
开发者ID:tucan9389,项目名称:tf2-mobile-pose-estimation,代码行数:15,代码来源:mv2_cpm.py

示例11: light_conv3x3_bn

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import DepthwiseConv2D [as 别名]
def light_conv3x3_bn(x,
                     filters):
    """Utility function of lightweight 3x3 convolution.

    lightweight 3x3 = 1x1 (linear) + dw 3x3 (nonlinear).

    # Arguments
        x: input tensor.
        filters: number of output filters.

    # Returns
        Output tensor.
    """
    bn_axis = 3
    x = layers.Conv2D(
        filters,
        (1, 1),
        strides=(1, 1),
        padding='same',
        use_bias=False)(x)
    x = layers.DepthwiseConv2D(
        (3, 3),
        strides=(1, 1),
        padding='same',
        use_bias=False)(x)
    x = layers.BatchNormalization(axis=bn_axis)(x)
    x = layers.Activation('relu')(x)
    return x 
开发者ID:jkjung-avt,项目名称:keras_imagenet,代码行数:30,代码来源:osnet.py

示例12: DarknetDepthwiseConv2D

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import DepthwiseConv2D [as 别名]
def DarknetDepthwiseConv2D(*args, **kwargs):
    """Wrapper to set Darknet parameters for Convolution2D."""
    darknet_conv_kwargs = {'kernel_regularizer': l2(5e-4)}
    darknet_conv_kwargs['padding'] = 'valid' if kwargs.get('strides')==(2,2) else 'same'
    darknet_conv_kwargs.update(kwargs)
    return DepthwiseConv2D(*args, **darknet_conv_kwargs) 
开发者ID:david8862,项目名称:keras-YOLOv3-model-set,代码行数:8,代码来源:layers.py

示例13: Depthwise_Separable_Conv2D_BN_Leaky

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import DepthwiseConv2D [as 别名]
def Depthwise_Separable_Conv2D_BN_Leaky(filters, kernel_size=(3, 3), block_id_str=None):
    """Depthwise Separable Convolution2D."""
    if not block_id_str:
        block_id_str = str(K.get_uid())
    return compose(
        DepthwiseConv2D(kernel_size, padding='same', name='conv_dw_' + block_id_str),
        BatchNormalization(name='conv_dw_%s_bn' % block_id_str),
        LeakyReLU(alpha=0.1, name='conv_dw_%s_leaky_relu' % block_id_str),
        Conv2D(filters, (1,1), padding='same', use_bias=False, strides=(1, 1), name='conv_pw_%s' % block_id_str),
        BatchNormalization(name='conv_pw_%s_bn' % block_id_str),
        LeakyReLU(alpha=0.1, name='conv_pw_%s_leaky_relu' % block_id_str)) 
开发者ID:david8862,项目名称:keras-YOLOv3-model-set,代码行数:13,代码来源:layers.py

示例14: _ep_block

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import DepthwiseConv2D [as 别名]
def _ep_block(inputs, filters, stride, expansion, block_id):
    #in_channels = backend.int_shape(inputs)[-1]
    in_channels = inputs.shape.as_list()[-1]

    pointwise_conv_filters = int(filters)
    x = inputs
    prefix = 'ep_block_{}_'.format(block_id)

    # Expand
    x = Conv2D(int(expansion * in_channels), kernel_size=1, padding='same', use_bias=False, activation=None, name=prefix + 'expand')(x)
    x = BatchNormalization(epsilon=1e-3, momentum=0.999, name=prefix + 'expand_BN')(x)
    x = ReLU(6., name=prefix + 'expand_relu')(x)

    # Depthwise
    if stride == 2:
        x = ZeroPadding2D(padding=correct_pad(K, x, 3), name=prefix + 'pad')(x)

    x = DepthwiseConv2D(kernel_size=3, strides=stride, activation=None, use_bias=False, padding='same' if stride == 1 else 'valid', name=prefix + 'depthwise')(x)
    x = BatchNormalization(epsilon=1e-3, momentum=0.999, name=prefix + 'depthwise_BN')(x)
    x = ReLU(6., name=prefix + 'depthwise_relu')(x)

    # Project
    x = Conv2D(pointwise_conv_filters, kernel_size=1, padding='same', use_bias=False, activation=None, name=prefix + 'project')(x)
    x = BatchNormalization(epsilon=1e-3, momentum=0.999, name=prefix + 'project_BN')(x)

    if in_channels == pointwise_conv_filters and stride == 1:
        return Add(name=prefix + 'add')([inputs, x])
    return x 
开发者ID:david8862,项目名称:keras-YOLOv3-model-set,代码行数:30,代码来源:yolo3_nano.py

示例15: shuffle_unit

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import DepthwiseConv2D [as 别名]
def shuffle_unit(inputs, out_channels, bottleneck_ratio,strides=2,stage=1,block=1):
    if K.image_data_format() == 'channels_last':
        bn_axis = -1
    else:
        raise ValueError('Only channels last supported')

    prefix = 'stage{}/block{}'.format(stage, block)
    bottleneck_channels = int(out_channels * bottleneck_ratio)
    if strides < 2:
        c_hat, c = channel_split(inputs, '{}/spl'.format(prefix))
        inputs = c

    x = Conv2D(bottleneck_channels, kernel_size=(1,1), strides=1, padding='same', name='{}/1x1conv_1'.format(prefix))(inputs)
    x = BatchNormalization(axis=bn_axis, name='{}/bn_1x1conv_1'.format(prefix))(x)
    x = Activation('relu', name='{}/relu_1x1conv_1'.format(prefix))(x)
    x = DepthwiseConv2D(kernel_size=3, strides=strides, padding='same', name='{}/3x3dwconv'.format(prefix))(x)
    x = BatchNormalization(axis=bn_axis, name='{}/bn_3x3dwconv'.format(prefix))(x)
    x = Conv2D(bottleneck_channels, kernel_size=1,strides=1,padding='same', name='{}/1x1conv_2'.format(prefix))(x)
    x = BatchNormalization(axis=bn_axis, name='{}/bn_1x1conv_2'.format(prefix))(x)
    x = Activation('relu', name='{}/relu_1x1conv_2'.format(prefix))(x)

    if strides < 2:
        ret = Concatenate(axis=bn_axis, name='{}/concat_1'.format(prefix))([x, c_hat])
    else:
        s2 = DepthwiseConv2D(kernel_size=3, strides=2, padding='same', name='{}/3x3dwconv_2'.format(prefix))(inputs)
        s2 = BatchNormalization(axis=bn_axis, name='{}/bn_3x3dwconv_2'.format(prefix))(s2)
        s2 = Conv2D(bottleneck_channels, kernel_size=1,strides=1,padding='same', name='{}/1x1_conv_3'.format(prefix))(s2)
        s2 = BatchNormalization(axis=bn_axis, name='{}/bn_1x1conv_3'.format(prefix))(s2)
        s2 = Activation('relu', name='{}/relu_1x1conv_3'.format(prefix))(s2)
        ret = Concatenate(axis=bn_axis, name='{}/concat_2'.format(prefix))([x, s2])

    ret = Lambda(channel_shuffle, name='{}/channel_shuffle'.format(prefix))(ret)

    return ret 
开发者ID:david8862,项目名称:keras-YOLOv3-model-set,代码行数:36,代码来源:shufflenet_v2.py


注:本文中的tensorflow.keras.layers.DepthwiseConv2D方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。