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


Python layers.AveragePooling2D方法代码示例

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


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

示例1: d_block

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling2D [as 别名]
def d_block(inp, fil, p = True):

    skip = Conv2D(fil, 1, padding = 'same', kernel_initializer = 'he_normal')(inp)

    out = Conv2D(filters = fil, kernel_size = 3, padding = 'same', kernel_initializer = 'he_normal')(inp)
    out = LeakyReLU(0.2)(out)

    out = Conv2D(filters = fil, kernel_size = 3, padding = 'same', kernel_initializer = 'he_normal')(out)
    out = LeakyReLU(0.2)(out)

    out = Conv2D(fil, 1, padding = 'same', kernel_initializer = 'he_normal')(out)

    out = add([out, skip])
    out = LeakyReLU(0.2)(out)

    if p:
        out = AveragePooling2D()(out)

    return out 
开发者ID:manicman1999,项目名称:Keras-BiGAN,代码行数:21,代码来源:bigan.py

示例2: avg_pool2d

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling2D [as 别名]
def avg_pool2d(h_kernel_size, h_stride):

    def compile_fn(di, dh):
        layer = layers.AveragePooling2D(pool_size=dh['kernel_size'],
                                        strides=(dh['stride'], dh['stride']),
                                        padding='same')

        def fn(di):
            return {'out': layer(di['in'])}

        return fn

    return siso_keras_module('AvgPool', compile_fn, {
        'kernel_size': h_kernel_size,
        'stride': h_stride,
    }) 
开发者ID:negrinho,项目名称:deep_architect,代码行数:18,代码来源:keras_ops.py

示例3: add_new_last_layer

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling2D [as 别名]
def add_new_last_layer(base_model, nb_classes):
    """Add last layer to the convnet
    
    Args:
        base_model: keras model excluding top
        nb_classes: # of classes
        
    Returns:
        new keras model with last layer
    """
    x = base_model.output
    x = AveragePooling2D((8, 8), border_mode='valid', name='avg_pool')(x)
    x = Dropout(0.4)(x)
    x = Flatten()(x)
    predictions = Dense(2, activation='softmax')(x)
    model = Model(input=base_model.input, output=predictions)
    return model 
开发者ID:DhavalThkkar,项目名称:Transfer-Learning,代码行数:19,代码来源:transfer.py

示例4: transition_block

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling2D [as 别名]
def transition_block(x, reduction, name):
    """A transition block.

    # Arguments
        x: input tensor.
        reduction: float, compression rate at transition layers.
        name: string, block label.

    # Returns
        output tensor for the block.
    """
    bn_axis = 3 if K.image_data_format() == 'channels_last' else 1
    x = BatchNormalization(axis=bn_axis, epsilon=1.001e-5,
                           name=name + '_bn')(x)
    x = Activation('relu', name=name + '_relu')(x)
    x = Conv2D(int(K.int_shape(x)[bn_axis] * reduction), 1, use_bias=False,
               name=name + '_conv')(x)
    x = AveragePooling2D(2, strides=2, name=name + '_pool')(x)
    return x 
开发者ID:i-pan,项目名称:kaggle-rsna18,代码行数:21,代码来源:densenet_gray.py

示例5: transition_layer

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling2D [as 别名]
def transition_layer(input_tensor, numFilters, compressionFactor=1.0):

    numOutPutFilters = int(numFilters*compressionFactor)

    if K.image_data_format() == 'channels_last':
        bn_axis = -1
    else:
        bn_axis = 1

    x = BatchNormalization(axis=bn_axis)(input_tensor)
    x = Activation('relu')(x)

    x = Conv2D(numOutPutFilters, (1, 1), strides=(1, 1), padding='same', kernel_initializer='he_normal')(x)

    # downsampling
    x = AveragePooling2D((2, 2), strides=(2, 2), padding='valid', data_format='channels_last', name='')(x)

    return x, numOutPutFilters 
开发者ID:thomaskuestner,项目名称:CNNArt,代码行数:20,代码来源:densely_connected_cnn_blocks.py

示例6: transition_SE_layer

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling2D [as 别名]
def transition_SE_layer(input_tensor, numFilters, compressionFactor=1.0, se_ratio=16):

    numOutPutFilters = int(numFilters*compressionFactor)

    if K.image_data_format() == 'channels_last':
        bn_axis = -1
    else:
        bn_axis = 1

    x = BatchNormalization(axis=bn_axis)(input_tensor)
    x = Activation('relu')(x)

    x = Conv2D(numOutPutFilters, (1, 1), strides=(1, 1), padding='same', kernel_initializer='he_normal')(x)

    # SE Block
    x = squeeze_excitation_block(x, ratio=se_ratio)
    #x = BatchNormalization(axis=bn_axis)(x)

    # downsampling
    x = AveragePooling2D((2, 2), strides=(2, 2), padding='valid', data_format='channels_last', name='')(x)

    #x = squeeze_excitation_block(x, ratio=se_ratio)

    return x, numOutPutFilters 
开发者ID:thomaskuestner,项目名称:CNNArt,代码行数:26,代码来源:densely_connected_cnn_blocks.py

示例7: model_base_test_CNN

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling2D [as 别名]
def model_base_test_CNN(input_shape):
    model = Sequential()

    model.add(Conv2D(32, (3, 3), input_shape=input_shape, padding='same'))
    model.add(Activation('relu'))
    model.add(AveragePooling2D(pool_size=(5, 5), strides=(3, 3), padding='same'))

    model.add(Conv2D(64, (3, 3), padding='same'))
    model.add(Activation('relu'))
    model.add(AveragePooling2D(pool_size=(5, 5), strides=(3, 3), padding='same'))

    model.add(Conv2D(64, (3, 3), padding='same'))
    model.add(Activation('relu'))
    model.add(AveragePooling2D(pool_size=(5, 5), strides=(3, 3), padding='same'))

    model.add(Conv2D(128, (3, 3), padding='same'))
    model.add(Activation('relu'))
    model.add(AveragePooling2D(pool_size=(3, 3), strides=(2, 2), padding='same'))

    model.add(Flatten())

    return model.input, model.output

# 64x3 model 
开发者ID:Sentdex,项目名称:Carla-RL,代码行数:26,代码来源:models.py

示例8: model_base_64x3_CNN

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling2D [as 别名]
def model_base_64x3_CNN(input_shape):
    model = Sequential()

    model.add(Conv2D(64, (3, 3), input_shape=input_shape, padding='same'))
    model.add(Activation('relu'))
    model.add(AveragePooling2D(pool_size=(5, 5), strides=(3, 3), padding='same'))

    model.add(Conv2D(64, (3, 3), padding='same'))
    model.add(Activation('relu'))
    model.add(AveragePooling2D(pool_size=(5, 5), strides=(3, 3), padding='same'))

    model.add(Conv2D(64, (3, 3), padding='same'))
    model.add(Activation('relu'))
    model.add(AveragePooling2D(pool_size=(5, 5), strides=(3, 3), padding='same'))

    model.add(Flatten())

    return model.input, model.output

# 4 CNN layer model 
开发者ID:Sentdex,项目名称:Carla-RL,代码行数:22,代码来源:models.py

示例9: model_base_4_CNN

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling2D [as 别名]
def model_base_4_CNN(input_shape):
    model = Sequential()

    model.add(Conv2D(64, (5, 5), input_shape=input_shape, padding='same'))
    model.add(Activation('relu'))
    model.add(AveragePooling2D(pool_size=(5, 5), strides=(3, 3), padding='same'))

    model.add(Conv2D(64, (5, 5), padding='same'))
    model.add(Activation('relu'))
    model.add(AveragePooling2D(pool_size=(5, 5), strides=(3, 3), padding='same'))

    model.add(Conv2D(128, (5, 5), padding='same'))
    model.add(Activation('relu'))
    model.add(AveragePooling2D(pool_size=(3, 3), strides=(2, 2), padding='same'))

    model.add(Conv2D(256, (3, 3), padding='same'))
    model.add(Activation('relu'))
    model.add(AveragePooling2D(pool_size=(3, 3), strides=(2, 2), padding='same'))

    model.add(Flatten())

    return model.input, model.output

# 5 CNN layer with residual connections model 
开发者ID:Sentdex,项目名称:Carla-RL,代码行数:26,代码来源:models.py

示例10: One_vs_One_Inception

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling2D [as 别名]
def One_vs_One_Inception(self, nOutput=2, input=[224, 224, 3]):
        """
            Builds a simple One_vs_One_Inception network with 2 inception layers (useful for ECOC models).
        """
        if len(input) == 3:
            input_shape = tuple([input[2]] + input[0:2])
        else:
            input_shape = tuple(input)

        self.model = Graph()
        # Input
        self.model.add_input(name='input', input_shape=input_shape)
        # Inception Ea
        out_Ea = self.__addInception('inceptionEa', 'input', 4, 2, 8, 2, 2, 2)
        # Inception Eb
        out_Eb = self.__addInception('inceptionEb', out_Ea, 2, 2, 4, 2, 1, 1)
        # Average Pooling    pool_size=(7,7)
        self.model.add_node(AveragePooling2D(pool_size=input_shape[1:], strides=(1, 1)), name='ave_pool/ECOC',
                            input=out_Eb)
        # Softmax
        self.model.add_node(Flatten(), name='loss_OnevsOne/classifier_flatten', input='ave_pool/ECOC')
        self.model.add_node(Dropout(0.5), name='loss_OnevsOne/drop', input='loss_OnevsOne/classifier_flatten')
        self.model.add_node(Dense(nOutput, activation='softmax'), name='loss_OnevsOne', input='loss_OnevsOne/drop')
        # Output
        self.model.add_output(name='loss_OnevsOne/output', input='loss_OnevsOne') 
开发者ID:sheffieldnlp,项目名称:deepQuest,代码行数:27,代码来源:cnn_model-predictor.py

示例11: add_One_vs_One_Inception

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling2D [as 别名]
def add_One_vs_One_Inception(self, input, input_shape, id_branch, nOutput=2, activation='softmax'):
        """
            Builds a simple One_vs_One_Inception network with 2 inception layers on the top of the current model (useful for ECOC_loss models).
        """

        # Inception Ea
        out_Ea = self.__addInception('inceptionEa_' + str(id_branch), input, 4, 2, 8, 2, 2, 2)
        # Inception Eb
        out_Eb = self.__addInception('inceptionEb_' + str(id_branch), out_Ea, 2, 2, 4, 2, 1, 1)
        # Average Pooling    pool_size=(7,7)
        self.model.add_node(AveragePooling2D(pool_size=input_shape[1:], strides=(1, 1)),
                            name='ave_pool/ECOC_' + str(id_branch), input=out_Eb)
        # Softmax
        self.model.add_node(Flatten(),
                            name='fc_OnevsOne_' + str(id_branch) + '/flatten', input='ave_pool/ECOC_' + str(id_branch))
        self.model.add_node(Dropout(0.5),
                            name='fc_OnevsOne_' + str(id_branch) + '/drop',
                            input='fc_OnevsOne_' + str(id_branch) + '/flatten')
        output_name = 'fc_OnevsOne_' + str(id_branch)
        self.model.add_node(Dense(nOutput, activation=activation),
                            name=output_name, input='fc_OnevsOne_' + str(id_branch) + '/drop')

        return output_name 
开发者ID:sheffieldnlp,项目名称:deepQuest,代码行数:25,代码来源:cnn_model-predictor.py

示例12: add_One_vs_One_Inception_Functional

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling2D [as 别名]
def add_One_vs_One_Inception_Functional(self, input, input_shape, id_branch, nOutput=2, activation='softmax'):
        """
            Builds a simple One_vs_One_Inception network with 2 inception layers on the top of the current model (useful for ECOC_loss models).
        """

        in_node = self.model.get_layer(input).output

        # Inception Ea
        [out_Ea, out_Ea_name] = self.__addInception_Functional('inceptionEa_' + str(id_branch), in_node, 4, 2, 8, 2, 2,
                                                               2)
        # Inception Eb
        [out_Eb, out_Eb_name] = self.__addInception_Functional('inceptionEb_' + str(id_branch), out_Ea, 2, 2, 4, 2, 1,
                                                               1)
        # Average Pooling    pool_size=(7,7)
        x = AveragePooling2D(pool_size=input_shape, strides=(1, 1), name='ave_pool/ECOC_' + str(id_branch))(out_Eb)

        # Softmax
        output_name = 'fc_OnevsOne_' + str(id_branch)
        x = Flatten(name='fc_OnevsOne_' + str(id_branch) + '/flatten')(x)
        x = Dropout(0.5, name='fc_OnevsOne_' + str(id_branch) + '/drop')(x)
        out_node = Dense(nOutput, activation=activation, name=output_name)(x)

        return out_node 
开发者ID:sheffieldnlp,项目名称:deepQuest,代码行数:25,代码来源:cnn_model-predictor.py

示例13: One_vs_One_Inception_v2

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling2D [as 别名]
def One_vs_One_Inception_v2(self, nOutput=2, input=[224, 224, 3]):
        """
            Builds a simple One_vs_One_Inception_v2 network with 2 inception layers (useful for ECOC models).
        """
        if len(input) == 3:
            input_shape = tuple([input[2]] + input[0:2])
        else:
            input_shape = tuple(input)

        self.model = Graph()
        # Input
        self.model.add_input(name='input', input_shape=input_shape)
        # Inception Ea
        out_Ea = self.__addInception('inceptionEa', 'input', 16, 8, 32, 8, 8, 8)
        # Inception Eb
        out_Eb = self.__addInception('inceptionEb', out_Ea, 8, 8, 16, 8, 4, 4)
        # Average Pooling    pool_size=(7,7)
        self.model.add_node(AveragePooling2D(pool_size=input_shape[1:], strides=(1, 1)), name='ave_pool/ECOC',
                            input=out_Eb)
        # Softmax
        self.model.add_node(Flatten(), name='loss_OnevsOne/classifier_flatten', input='ave_pool/ECOC')
        self.model.add_node(Dropout(0.5), name='loss_OnevsOne/drop', input='loss_OnevsOne/classifier_flatten')
        self.model.add_node(Dense(nOutput, activation='softmax'), name='loss_OnevsOne', input='loss_OnevsOne/drop')
        # Output
        self.model.add_output(name='loss_OnevsOne/output', input='loss_OnevsOne') 
开发者ID:sheffieldnlp,项目名称:deepQuest,代码行数:27,代码来源:cnn_model-predictor.py

示例14: add_One_vs_One_Inception_v2

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling2D [as 别名]
def add_One_vs_One_Inception_v2(self, input, input_shape, id_branch, nOutput=2, activation='softmax'):
        """
            Builds a simple One_vs_One_Inception_v2 network with 2 inception layers on the top of the current model (useful for ECOC_loss models).
        """

        # Inception Ea
        out_Ea = self.__addInception('inceptionEa_' + str(id_branch), input, 16, 8, 32, 8, 8, 8)
        # Inception Eb
        out_Eb = self.__addInception('inceptionEb_' + str(id_branch), out_Ea, 8, 8, 16, 8, 4, 4)
        # Average Pooling    pool_size=(7,7)
        self.model.add_node(AveragePooling2D(pool_size=input_shape[1:], strides=(1, 1)),
                            name='ave_pool/ECOC_' + str(id_branch), input=out_Eb)
        # Softmax
        self.model.add_node(Flatten(),
                            name='fc_OnevsOne_' + str(id_branch) + '/flatten', input='ave_pool/ECOC_' + str(id_branch))
        self.model.add_node(Dropout(0.5),
                            name='fc_OnevsOne_' + str(id_branch) + '/drop',
                            input='fc_OnevsOne_' + str(id_branch) + '/flatten')
        output_name = 'fc_OnevsOne_' + str(id_branch)
        self.model.add_node(Dense(nOutput, activation=activation),
                            name=output_name, input='fc_OnevsOne_' + str(id_branch) + '/drop')

        return output_name 
开发者ID:sheffieldnlp,项目名称:deepQuest,代码行数:25,代码来源:cnn_model.py

示例15: apn_module

# 需要导入模块: from keras import layers [as 别名]
# 或者: from keras.layers import AveragePooling2D [as 别名]
def apn_module(self, x):

        def right(x):
            x = layers.AveragePooling2D()(x)
            x = layers.Conv2D(self.classes, kernel_size=1, padding='same')(x)
            x = layers.BatchNormalization()(x)
            x = layers.Activation('relu')(x)
            x = layers.UpSampling2D(interpolation='bilinear')(x)
            return x

        def conv(x, filters, kernel_size, stride):
            x = layers.Conv2D(filters, kernel_size=kernel_size, strides=(stride, stride), padding='same')(x)
            x = layers.BatchNormalization()(x)
            x = layers.Activation('relu')(x)
            return x

        x_7 = conv(x, int(x.shape[-1]), 7, stride=2)
        x_5 = conv(x_7, int(x.shape[-1]), 5, stride=2)
        x_3 = conv(x_5, int(x.shape[-1]), 3, stride=2)

        x_3_1 = conv(x_3, self.classes, 3, stride=1)
        x_3_1_up = layers.UpSampling2D(interpolation='bilinear')(x_3_1)
        x_5_1 = conv(x_5, self.classes, 5, stride=1)
        x_3_5 = layers.add([x_5_1, x_3_1_up])
        x_3_5_up = layers.UpSampling2D(interpolation='bilinear')(x_3_5)
        x_7_1 = conv(x_7, self.classes, 3, stride=1)
        x_3_5_7 = layers.add([x_7_1, x_3_5_up])
        x_3_5_7_up = layers.UpSampling2D(interpolation='bilinear')(x_3_5_7)

        x_middle = conv(x, self.classes, 1, stride=1)
        x_middle = layers.multiply([x_3_5_7_up, x_middle])

        x_right = right(x)
        x_middle = layers.add([x_middle, x_right])
        return x_middle 
开发者ID:JACKYLUO1991,项目名称:Face-skin-hair-segmentaiton-and-skin-color-evaluation,代码行数:37,代码来源:lednet.py


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