當前位置: 首頁>>代碼示例>>Python>>正文


Python pooling.AveragePooling2D方法代碼示例

本文整理匯總了Python中keras.layers.pooling.AveragePooling2D方法的典型用法代碼示例。如果您正苦於以下問題:Python pooling.AveragePooling2D方法的具體用法?Python pooling.AveragePooling2D怎麽用?Python pooling.AveragePooling2D使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在keras.layers.pooling的用法示例。


在下文中一共展示了pooling.AveragePooling2D方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __transition_block

# 需要導入模塊: from keras.layers import pooling [as 別名]
# 或者: from keras.layers.pooling import AveragePooling2D [as 別名]
def __transition_block(ip, nb_filter, compression=1.0, weight_decay=1e-4):
    ''' Apply BatchNorm, Relu 1x1, Conv2D, optional compression, dropout and Maxpooling2D
    Args:
        ip: keras tensor
        nb_filter: number of filters
        compression: calculated as 1 - reduction. Reduces the number of feature maps
                    in the transition block.
        dropout_rate: dropout rate
        weight_decay: weight decay factor
    Returns: keras tensor, after applying batch_norm, relu-conv, dropout, maxpool
    '''
    concat_axis = 1 if K.image_data_format() == 'channels_first' else -1

    x = BatchNormalization(axis=concat_axis, epsilon=1.1e-5)(ip)
    x = Activation('relu')(x)
    x = Conv2D(int(nb_filter * compression), (1, 1), kernel_initializer='he_normal', padding='same', use_bias=False,
               kernel_regularizer=l2(weight_decay))(x)
    x = AveragePooling2D((2, 2), strides=(2, 2))(x)

    # global context block
    x = global_context_block(x)

    return x 
開發者ID:titu1994,項目名稱:keras-global-context-networks,代碼行數:25,代碼來源:gc_densenet.py

示例2: __transition_block

# 需要導入模塊: from keras.layers import pooling [as 別名]
# 或者: from keras.layers.pooling import AveragePooling2D [as 別名]
def __transition_block(ip, nb_filter, compression=1.0, weight_decay=1e-4):
    ''' Apply BatchNorm, Relu 1x1, Conv2D, optional compression, dropout and Maxpooling2D
    Args:
        ip: keras tensor
        nb_filter: number of filters
        compression: calculated as 1 - reduction. Reduces the number of feature maps
                    in the transition block.
        dropout_rate: dropout rate
        weight_decay: weight decay factor
    Returns: keras tensor, after applying batch_norm, relu-conv, dropout, maxpool
    '''
    concat_axis = 1 if K.image_data_format() == 'channels_first' else -1

    x = BatchNormalization(axis=concat_axis, epsilon=1.1e-5)(ip)
    x = Activation('relu')(x)
    x = Conv2D(int(nb_filter * compression), (1, 1), kernel_initializer='he_normal', padding='same', use_bias=False,
               kernel_regularizer=l2(weight_decay))(x)
    x = AveragePooling2D((2, 2), strides=(2, 2))(x)

    return x 
開發者ID:OlafenwaMoses,項目名稱:Model-Playgrounds,代碼行數:22,代碼來源:densenet.py

示例3: transition_block

# 需要導入模塊: from keras.layers import pooling [as 別名]
# 或者: from keras.layers.pooling import AveragePooling2D [as 別名]
def transition_block(ip, nb_filter, dropout_rate=None, weight_decay=1E-4):
    ''' Apply BatchNorm, Relu 1x1, Conv2D, optional dropout and Maxpooling2D

    Args:
        ip: keras tensor
        nb_filter: number of filters
        dropout_rate: dropout rate
        weight_decay: weight decay factor

    Returns: keras tensor, after applying batch_norm, relu-conv, dropout, maxpool

    '''

    concat_axis = 1 if K.image_dim_ordering() == "th" else -1

    x = Convolution2D(nb_filter, 1, 1, init="he_uniform", border_mode="same", bias=False,
                      W_regularizer=l2(weight_decay))(ip)
    if dropout_rate:
        x = Dropout(dropout_rate)(x)
    x = AveragePooling2D((2, 2), strides=(2, 2))(x)

    x = BatchNormalization(mode=0, axis=concat_axis, gamma_regularizer=l2(weight_decay),
                           beta_regularizer=l2(weight_decay))(x)

    return x 
開發者ID:cvjena,項目名稱:semantic-embeddings,代碼行數:27,代碼來源:densenet_fast.py

示例4: transition_block

# 需要導入模塊: from keras.layers import pooling [as 別名]
# 或者: from keras.layers.pooling import AveragePooling2D [as 別名]
def transition_block(input, nb_filter, dropout_rate=None, weight_decay=1E-4):
    ''' Apply BatchNorm, Relu 1x1, Conv2D, optional dropout and Maxpooling2D
    Args:
        input: keras tensor
        nb_filter: number of filters
        dropout_rate: dropout rate
        weight_decay: weight decay factor
    Returns: keras tensor, after applying batch_norm, relu-conv, dropout, maxpool
    '''

    concat_axis = 1 if K.image_dim_ordering() == "th" else -1

    x = Convolution2D(nb_filter, (1, 1), kernel_initializer="he_uniform", padding="same", use_bias=False,
                      kernel_regularizer=l2(weight_decay))(input)
    if dropout_rate is not None:
        x = Dropout(dropout_rate)(x)
    x = AveragePooling2D((2, 2), strides=(2, 2))(x)

    x = BatchNormalization(axis=concat_axis, gamma_regularizer=l2(weight_decay),
                           beta_regularizer=l2(weight_decay))(x)

    return x 
開發者ID:Kexiii,項目名稱:DenseNet-Cifar10,代碼行數:24,代碼來源:DenseNet.py

示例5: __transition_block

# 需要導入模塊: from keras.layers import pooling [as 別名]
# 或者: from keras.layers.pooling import AveragePooling2D [as 別名]
def __transition_block(ip, nb_filter, compression=1.0, weight_decay=1e-4, attention_module=None):
    ''' Apply BatchNorm, Relu 1x1, Conv2D, optional compression, dropout and Maxpooling2D
    Args:
        ip: keras tensor
        nb_filter: number of filters
        compression: calculated as 1 - reduction. Reduces the number of feature maps
                    in the transition block.
        dropout_rate: dropout rate
        weight_decay: weight decay factor
    Returns: keras tensor, after applying batch_norm, relu-conv, dropout, maxpool
    '''
    concat_axis = 1 if K.image_data_format() == 'channels_first' else -1

    x = BatchNormalization(axis=concat_axis, epsilon=1.1e-5)(ip)
    x = Activation('relu')(x)
    x = Conv2D(int(nb_filter * compression), (1, 1), kernel_initializer='he_normal', padding='same', use_bias=False,
               kernel_regularizer=l2(weight_decay))(x)
    x = AveragePooling2D((2, 2), strides=(2, 2))(x)

    # attention_module
    if attention_module is not None:
        x = attach_attention_module(x, attention_module)

    return x 
開發者ID:kobiso,項目名稱:CBAM-keras,代碼行數:26,代碼來源:densenet.py

示例6: inception_block_3a

# 需要導入模塊: from keras.layers import pooling [as 別名]
# 或者: from keras.layers.pooling import AveragePooling2D [as 別名]
def inception_block_3a(X):
    X_3x3 = fr_utils.conv2d_bn(X,
                           layer='inception_5a_3x3',
                           cv1_out=96,
                           cv1_filter=(1, 1),
                           cv2_out=384,
                           cv2_filter=(3, 3),
                           cv2_strides=(1, 1),
                           padding=(1, 1))
    X_pool = AveragePooling2D(pool_size=(3, 3), strides=(3, 3), data_format='channels_first')(X)
    X_pool = fr_utils.conv2d_bn(X_pool,
                           layer='inception_5a_pool',
                           cv1_out=96,
                           cv1_filter=(1, 1),
                           padding=(1, 1))
    X_1x1 = fr_utils.conv2d_bn(X,
                           layer='inception_5a_1x1',
                           cv1_out=256,
                           cv1_filter=(1, 1))

    inception = concatenate([X_3x3, X_pool, X_1x1], axis=1)

    return inception 
開發者ID:akshaybahadur21,項目名稱:Facial-Recognition-using-Facenet,代碼行數:25,代碼來源:inception_blocks_v2.py

示例7: _transition_block

# 需要導入模塊: from keras.layers import pooling [as 別名]
# 或者: from keras.layers.pooling import AveragePooling2D [as 別名]
def _transition_block(ip, nb_filter, compression=1.0, weight_decay=1e-4):
    ''' Apply BatchNorm, Relu 1x1, Conv2D, optional compression, dropout and Maxpooling2D
    Args:
        ip: keras tensor
        nb_filter: number of filters
        compression: calculated as 1 - reduction. Reduces the number of feature maps
                    in the transition block.
        dropout_rate: dropout rate
        weight_decay: weight decay factor
    Returns: keras tensor, after applying batch_norm, relu-conv, dropout, maxpool
    '''
    concat_axis = 1 if K.image_data_format() == 'channels_first' else -1

    with K.name_scope('transition_block'):
        x = BatchNormalization(axis=concat_axis, epsilon=1e-5, momentum=0.1)(ip)
        x = Activation('relu')(x)
        x = Conv2D(int(nb_filter * compression), (1, 1), kernel_initializer='he_normal', padding='same', use_bias=False,
                   kernel_regularizer=l2(weight_decay))(x)
        x = AveragePooling2D((2, 2), strides=(2, 2))(x)

    return x 
開發者ID:titu1994,項目名稱:keras-SparseNet,代碼行數:23,代碼來源:sparsenet.py

示例8: downsample_block

# 需要導入模塊: from keras.layers import pooling [as 別名]
# 或者: from keras.layers.pooling import AveragePooling2D [as 別名]
def downsample_block(x, nb_channels, kernel_size=3, bottleneck=True,
                     l2_reg=1e-4):
    if bottleneck:
        out = bottleneck_layer(x, nb_channels, kernel_size=kernel_size,
                               stride=2, l2_reg=l2_reg)
        # The output channels is 4x bigger on this case
        nb_channels = nb_channels * 4
    else:
        out = two_conv_layer(x, nb_channels, kernel_size=kernel_size,
                             stride=2, l2_reg=l2_reg)
    # Projection on the shortcut
    proj = Convolution2D(nb_channels, 1, 1, subsample=(2, 2),
                         border_mode='valid', init='he_normal',
                         W_regularizer=l2(l2_reg), bias=False)(x)
    # proj = AveragePooling2D((1, 1), (2, 2))(x)
    out = merge([proj, out], mode='sum')
    return out 
開發者ID:robertomest,項目名稱:convnet-study,代碼行數:19,代碼來源:resnet.py

示例9: transition

# 需要導入模塊: from keras.layers import pooling [as 別名]
# 或者: from keras.layers.pooling import AveragePooling2D [as 別名]
def transition(x, nb_filter, dropout_rate=None, weight_decay=1E-4):
    """Apply BatchNorm, Relu 1x1Conv2D, optional dropout and Maxpooling2D
    :param x: keras model
    :param nb_filter: int -- number of filters
    :param dropout_rate: int -- dropout rate
    :param weight_decay: int -- weight decay factor
    :returns: model
    :rtype: keras model, after applying batch_norm, relu-conv, dropout, maxpool
    """

    x = Activation('relu')(x)
    x = Convolution2D(nb_filter, 1, 1,
                      init="he_uniform",
                      border_mode="same",
                      bias=False,
                      W_regularizer=l2(weight_decay))(x)
    if dropout_rate:
        x = Dropout(dropout_rate)(x)
    x = AveragePooling2D((2, 2), strides=(2, 2))(x)

    return x 
開發者ID:thomaskuestner,項目名稱:CNNArt,代碼行數:23,代碼來源:Densenet.py

示例10: transition_block

# 需要導入模塊: from keras.layers import pooling [as 別名]
# 或者: from keras.layers.pooling import AveragePooling2D [as 別名]
def transition_block(input,nb_filter,dropout_rate=None,pooltype=1,weight_decay=1e-4):
    x = BatchNormalization(axis=-1,epsilon=1.1e-5)(input)
    x = Activation('relu')(x)
    x = Conv2D(nb_filter,(1,1),kernel_initializer='he_normal', padding='same', use_bias=False,
               kernel_regularizer=l2(weight_decay))(x)

    if(dropout_rate):
        x = Dropout(dropout_rate)(x)

    if(pooltype==2):
        x = AveragePooling2D((2,2),strides=(2,2))(x)
    elif(pooltype==1):
        x = ZeroPadding2D(padding=(0,1))(x)
        x = AveragePooling2D((2,2),strides=(2,1))(x)
    elif(pooltype==3):
        x = AveragePooling2D((2,2),strides=(2,1))(x)
    return x,nb_filter 
開發者ID:jarvisqi,項目名稱:deep_learning,代碼行數:19,代碼來源:densenet.py

示例11: transition_block

# 需要導入模塊: from keras.layers import pooling [as 別名]
# 或者: from keras.layers.pooling import AveragePooling2D [as 別名]
def transition_block(input, nb_filter, dropout_rate=None, pooltype=1, weight_decay=1e-4):
    x = BatchNormalization(axis=-1, epsilon=1.1e-5)(input)
    x = Activation('relu')(x)
    x = Conv2D(nb_filter, (1, 1), kernel_initializer='he_normal', padding='same', use_bias=False,
               kernel_regularizer=l2(weight_decay))(x)

    if(dropout_rate):
        x = Dropout(dropout_rate)(x)

    if(pooltype == 2):
        x = AveragePooling2D((2, 2), strides=(2, 2))(x)
    elif(pooltype == 1):
        x = ZeroPadding2D(padding = (0, 1))(x)
        x = AveragePooling2D((2, 2), strides=(2, 1))(x)
    elif(pooltype == 3):
        x = AveragePooling2D((2, 2), strides=(2, 1))(x)
    return x, nb_filter 
開發者ID:YCG09,項目名稱:chinese_ocr,代碼行數:19,代碼來源:densenet.py

示例12: transition_block

# 需要導入模塊: from keras.layers import pooling [as 別名]
# 或者: from keras.layers.pooling import AveragePooling2D [as 別名]
def transition_block(input, nb_filter, dropout_rate=None, pooltype=1, weight_decay=1e-4):
    x = BatchNormalization(axis=-1, epsilon=1.1e-5)(input)
    x = Activation('relu')(x)
    x = Conv2D(nb_filter, (1, 1), kernel_initializer='he_normal', padding='same', use_bias=False,
               kernel_regularizer=l2(weight_decay))(x)

    if dropout_rate:
        x = Dropout(dropout_rate)(x)

    if pooltype == 2:
        x = AveragePooling2D((2, 2), strides=(2, 2))(x)
    elif pooltype == 1:
        x = ZeroPadding2D(padding=(0, 1))(x)
        x = AveragePooling2D((2, 2), strides=(2, 1))(x)
    elif pooltype == 3:
        x = AveragePooling2D((2, 2), strides=(2, 1))(x)
    return x, nb_filter 
開發者ID:bing1zhi2,項目名稱:chinese_ocr,代碼行數:19,代碼來源:densenet.py

示例13: pyramid_pooling_block

# 需要導入模塊: from keras.layers import pooling [as 別名]
# 或者: from keras.layers.pooling import AveragePooling2D [as 別名]
def pyramid_pooling_block(input_tensor, bin_sizes):
    concat_list = [input_tensor]
    h = input_tensor.shape[1].value
    w = input_tensor.shape[2].value

    for bin_size in bin_sizes:
        x = AveragePooling2D(pool_size=(h//bin_size, w//bin_size), strides=(h//bin_size, w//bin_size))(input_tensor)
        x = Conv2D(512, kernel_size=1)(x)
        x = Lambda(lambda x: tf.image.resize_images(x, (h, w)))(x)

        concat_list.append(x)

    return concatenate(concat_list) 
開發者ID:dhkim0225,項目名稱:keras-image-segmentation,代碼行數:15,代碼來源:psp_temp.py

示例14: get_features

# 需要導入模塊: from keras.layers import pooling [as 別名]
# 或者: from keras.layers.pooling import AveragePooling2D [as 別名]
def get_features(image, model):
    '''
    get the feature map of all activation layer for given
    image and given model
    :param image: input image path
    :param model: given model
    :return: all activation layers features
    '''

   # image = load_image(image_src)
    feature_maps = np.zeros((10, 10, 15104))
    activation_layers = ['activation_' + str(i) for i in range(4, 50, 3)]
    start_index = 0

    for i, layer_name in enumerate(activation_layers):
        layer = model.get_layer(layer_name)
        nchannel = layer.output_shape[-1]
        conv_output = layer.output
	# Adujusting pooling size with respect to input layers` size
        if layer.output_shape[-2] == 74:
            conv_output = AveragePooling2D(pool_size=(7, 7))(conv_output)
        if layer.output_shape[-2] == 37:
            conv_output = AveragePooling2D(pool_size=(4, 4), border_mode='same')(conv_output)
        if layer.output_shape[-2] == 19:
            conv_output = AveragePooling2D(pool_size=(2, 2), border_mode='same')(conv_output)

        featuremap_function = K.function([model.input, K.learning_phase()], [conv_output])

        output = featuremap_function([image, 0])
        feature_maps[:, :, start_index:start_index+nchannel] = output[0][0, :, :, :]

        start_index = start_index + nchannel

    return feature_maps 
開發者ID:gautamMalu,項目名稱:Aesthetic_attributes_maps,代碼行數:36,代碼來源:visualization.py

示例15: __transition_block

# 需要導入模塊: from keras.layers import pooling [as 別名]
# 或者: from keras.layers.pooling import AveragePooling2D [as 別名]
def __transition_block(ip, nb_filter, compression=1.0, weight_decay=1e-4, attention_module=None):
    ''' Apply BatchNorm, Relu 1x1, Conv2D, optional compression, dropout and Maxpooling2D
    Args:
        ip: keras tensor
        nb_filter: number of filters
        compression: calculated as 1 - reduction. Reduces the number of feature maps
                    in the transition block.
        dropout_rate: dropout rate
        weight_decay: weight decay factor
    Returns: keras tensor, after applying batch_norm, relu-conv, dropout, maxpool
    '''
    concat_axis = 1 if K.image_data_format() == 'channels_first' else -1

    x = BatchNormalization(axis=concat_axis, epsilon=1.1e-5)(ip)
    x = Activation('relu')(x)
    x = Conv2D(int(nb_filter * compression), (1, 1), kernel_initializer='he_normal', padding='same', use_bias=False,
               kernel_regularizer=l2(weight_decay))(x)
    x = AveragePooling2D((2, 2), strides=(2, 2))(x)

	# attention_module
    if attention_module == 'se_block':
        x = se_block(x)
    if attention_module == 'cbam_block':
        x = cbam_block(x)

    return x 
開發者ID:kobiso,項目名稱:CBAM-keras,代碼行數:28,代碼來源:densenet-checkpoint.py


注:本文中的keras.layers.pooling.AveragePooling2D方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。