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


Python layers.GlobalAveragePooling2D方法代碼示例

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


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

示例1: get_model

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import GlobalAveragePooling2D [as 別名]
def get_model(session):

    # create the base pre-trained model
    base_model = Xception(weights=None, include_top=False, input_shape=(270, 480, 3))

    # add a global spatial average pooling layer
    x = base_model.output
    x = GlobalAveragePooling2D()(x)
    # add a fully-connected layer
    x = Dense(1024, activation='relu')(x)
    # putput layer
    predictions = Dense(session.training_dataset_info['number_of_labels'], activation='softmax')(x)
    # model
    model = Model(inputs=base_model.input, outputs=predictions)

    learning_rate = 0.001
    opt = keras.optimizers.adam(lr=learning_rate, decay=1e-5)

    model.compile(loss='categorical_crossentropy',
                  optimizer=opt,
                  metrics=['accuracy'])

    return model 
開發者ID:Sentdex,項目名稱:pygta5,代碼行數:25,代碼來源:xception.py

示例2: inception_pseudo

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import GlobalAveragePooling2D [as 別名]
def inception_pseudo(self,dim=224,freeze_layers=30,full_freeze='N'):
		model = InceptionV3(weights='imagenet',include_top=False)
		x = model.output
		x = GlobalAveragePooling2D()(x)
		x = Dense(512, activation='relu')(x)
		x = Dropout(0.5)(x)
		x = Dense(512, activation='relu')(x)
		x = Dropout(0.5)(x)
		out = Dense(5,activation='softmax')(x)
		model_final = Model(input = model.input,outputs=out)
		if full_freeze != 'N':
			for layer in model.layers[0:freeze_layers]:
				layer.trainable = False
		return model_final

	# ResNet50 Model for transfer Learning 
開發者ID:PacktPublishing,項目名稱:Intelligent-Projects-Using-Python,代碼行數:18,代碼來源:TransferLearning.py

示例3: resnet_pseudo

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import GlobalAveragePooling2D [as 別名]
def resnet_pseudo(self,dim=224,freeze_layers=10,full_freeze='N'):
		model = ResNet50(weights='imagenet',include_top=False)
		x = model.output
		x = GlobalAveragePooling2D()(x)
		x = Dense(512, activation='relu')(x)
		x = Dropout(0.5)(x)
		x = Dense(512, activation='relu')(x)
		x = Dropout(0.5)(x)
		out = Dense(5,activation='softmax')(x)
		model_final = Model(input = model.input,outputs=out)
		if full_freeze != 'N':
			for layer in model.layers[0:freeze_layers]:
				layer.trainable = False
		return model_final

	# VGG16 Model for transfer Learning 
開發者ID:PacktPublishing,項目名稱:Intelligent-Projects-Using-Python,代碼行數:18,代碼來源:TransferLearning.py

示例4: inception_pseudo

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import GlobalAveragePooling2D [as 別名]
def inception_pseudo(self,dim=224,freeze_layers=30,full_freeze='N'):
		model = InceptionV3(weights='imagenet',include_top=False)
		x = model.output
		x = GlobalAveragePooling2D()(x)
		x = Dense(512, activation='relu')(x)
		x = Dropout(0.5)(x)
		x = Dense(512, activation='relu')(x)
		x = Dropout(0.5)(x)
		out = Dense(1)(x)
		model_final = Model(input = model.input,outputs=out)
		if full_freeze != 'N':
			for layer in model.layers[0:freeze_layers]:
				layer.trainable = False
		return model_final

	# ResNet50 Model for transfer Learning 
開發者ID:PacktPublishing,項目名稱:Intelligent-Projects-Using-Python,代碼行數:18,代碼來源:TransferLearning_reg.py

示例5: resnet_pseudo

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import GlobalAveragePooling2D [as 別名]
def resnet_pseudo(self,dim=224,freeze_layers=10,full_freeze='N'):
		model = ResNet50(weights='imagenet',include_top=False)
		x = model.output
		x = GlobalAveragePooling2D()(x)
		x = Dense(512, activation='relu')(x)
		x = Dropout(0.5)(x)
		x = Dense(512, activation='relu')(x)
		x = Dropout(0.5)(x)
		out = Dense(1)(x)
		model_final = Model(input = model.input,outputs=out)
		if full_freeze != 'N':
			for layer in model.layers[0:freeze_layers]:
				layer.trainable = False
		return model_final

	# VGG16 Model for transfer Learning 
開發者ID:PacktPublishing,項目名稱:Intelligent-Projects-Using-Python,代碼行數:18,代碼來源:TransferLearning_reg.py

示例6: inception_pseudo

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import GlobalAveragePooling2D [as 別名]
def inception_pseudo(self,dim=224,freeze_layers=10,full_freeze='N'):
        model = InceptionV3(weights='imagenet',include_top=False)
        x = model.output
        x = GlobalAveragePooling2D()(x)
        x = Dense(512, activation='relu')(x)
        x = Dropout(0.5)(x)
        x = Dense(512, activation='relu')(x)
        x = Dropout(0.5)(x)
        out = Dense(5,activation='softmax')(x)
        model_final = Model(input = model.input,outputs=out)
        if full_freeze != 'N':
            for layer in model.layers[0:freeze_layers]:
                layer.trainable = False
        return model_final

# ResNet50 Model for transfer Learning 
開發者ID:PacktPublishing,項目名稱:Intelligent-Projects-Using-Python,代碼行數:18,代碼來源:TransferLearning_ffd.py

示例7: resnet_pseudo

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import GlobalAveragePooling2D [as 別名]
def resnet_pseudo(self,dim=224,freeze_layers=10,full_freeze='N'):
        model = ResNet50(weights='imagenet',include_top=False)
        x = model.output
        x = GlobalAveragePooling2D()(x)
        x = Dense(512, activation='relu')(x)
        x = Dropout(0.5)(x)
        x = Dense(512, activation='relu')(x)
        x = Dropout(0.5)(x)
        out = Dense(5,activation='softmax')(x)
        model_final = Model(input = model.input,outputs=out)
        if full_freeze != 'N':
            for layer in model.layers[0:freeze_layers]:
                layer.trainable = False
        return model_final

# VGG16 Model for transfer Learning 
開發者ID:PacktPublishing,項目名稱:Intelligent-Projects-Using-Python,代碼行數:18,代碼來源:TransferLearning_ffd.py

示例8: classifier_layers

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import GlobalAveragePooling2D [as 別名]
def classifier_layers(x, input_shape, trainable=False):

    # compile times on theano tend to be very high, so we use smaller ROI pooling regions to workaround
    # (hence a smaller stride in the region that follows the ROI pool)
    x = TimeDistributed(SeparableConv2D(1536, (3, 3),
                                        padding='same',
                                        use_bias=False),
                        name='block14_sepconv1')(x)
    x = TimeDistributed(BatchNormalization(), name='block14_sepconv1_bn')(x)
    x = Activation('relu', name='block14_sepconv1_act')(x)

    x = TimeDistributed(SeparableConv2D(2048, (3, 3),
                                        padding='same',
                                        use_bias=False),
                        name='block14_sepconv2')(x)
    x = TimeDistributed(BatchNormalization(), name='block14_sepconv2_bn')(x)
    x = Activation('relu', name='block14_sepconv2_act')(x)

    TimeDistributed(GlobalAveragePooling2D(), name='avg_pool')(x)

    return x 
開發者ID:you359,項目名稱:Keras-FasterRCNN,代碼行數:23,代碼來源:xception.py

示例9: _squeeze

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import GlobalAveragePooling2D [as 別名]
def _squeeze(self, inputs):
        """Squeeze and Excitation.
        This function defines a squeeze structure.

        # Arguments
            inputs: Tensor, input tensor of conv layer.
        """
        input_channels = int(inputs.shape[-1])

        x = GlobalAveragePooling2D()(inputs)
        x = Dense(input_channels, activation='relu')(x)
        x = Dense(input_channels, activation='hard_sigmoid')(x)
        x = Reshape((1, 1, input_channels))(x)
        x = Multiply()([inputs, x])

        return x 
開發者ID:xiaochus,項目名稱:MobileNetV3,代碼行數:18,代碼來源:mobilenet_base.py

示例10: global_pool2d

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import GlobalAveragePooling2D [as 別名]
def global_pool2d():

    def compile_fn(di, dh):
        layer = layers.GlobalAveragePooling2D()

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

        return fn

    return siso_keras_module('GlobalAveragePool', compile_fn, {}) 
開發者ID:negrinho,項目名稱:deep_architect,代碼行數:13,代碼來源:keras_ops.py

示例11: learn

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import GlobalAveragePooling2D [as 別名]
def learn():
    (train_x, train_y, sample_weight), (test_x, test_y) = load_data()
    datagen = ImageDataGenerator(horizontal_flip=True,
                                 vertical_flip=True)
    train_generator = datagen.flow(train_x, train_y, sample_weight=sample_weight)
    base = VGG16(weights='imagenet', include_top=False, input_shape=(None, None, 3))
    for layer in base.layers[:-4]:
        layer.trainable = False
    model = models.Sequential([
        base,
        layers.BatchNormalization(),
        layers.Conv2D(64, (3, 3), activation='relu', padding='same'),
        layers.GlobalAveragePooling2D(),
        layers.BatchNormalization(),
        layers.Dense(64, activation='relu'),
        layers.BatchNormalization(),
        layers.Dropout(0.20),
        layers.Dense(80, activation='softmax')
    ])
    model.compile(optimizer=optimizers.RMSprop(lr=1e-5),
                  loss='sparse_categorical_crossentropy',
                  metrics=['accuracy'])
    model.summary()
    reduce_lr = ReduceLROnPlateau(verbose=1)
    model.fit_generator(train_generator, epochs=400,
                        steps_per_epoch=100,
                        validation_data=(test_x[:800], test_y[:800]),
                        callbacks=[reduce_lr])
    result = model.evaluate(test_x, test_y)
    print(result)
    model.save('12306.image.model.h5', include_optimizer=False) 
開發者ID:testerSunshine,項目名稱:12306,代碼行數:33,代碼來源:mlearn_for_image.py

示例12: _squeeze_excite_block

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import GlobalAveragePooling2D [as 別名]
def _squeeze_excite_block(input, filters, k=1, name=None):
    init = input
    se_shape = (1, 1, filters * k) if K.image_data_format() == 'channels_last' else (filters * k, 1, 1)

    se = GlobalAveragePooling2D()(init)
    se = Reshape(se_shape)(se)
    se = Dense((filters * k) // 16, activation='relu', kernel_initializer='he_normal', use_bias=False,name=name+'_fc1')(se)
    se = Dense(filters * k, activation='sigmoid', kernel_initializer='he_normal', use_bias=False,name=name+'_fc2')(se)
    return se


# pyramid pooling function 
開發者ID:dhkim0225,項目名稱:keras-image-segmentation,代碼行數:14,代碼來源:pspnet.py

示例13: squeeze_excite_block

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import GlobalAveragePooling2D [as 別名]
def squeeze_excite_block(input, ratio=16):
    ''' Create a channel-wise squeeze-excite block

    Args:
        input: input tensor
        filters: number of output filters

    Returns: a keras tensor

    References
    -   [Squeeze and Excitation Networks](https://arxiv.org/abs/1709.01507)
    '''
    init = input
    channel_axis = 1 if K.image_data_format() == "channels_first" else -1
    filters = init._keras_shape[channel_axis]
    se_shape = (1, 1, filters)

    se = GlobalAveragePooling2D()(init)
    se = Reshape(se_shape)(se)
    se = Dense(filters // ratio, activation='relu', kernel_initializer='he_normal', use_bias=False)(se)
    se = Dense(filters, activation='sigmoid', kernel_initializer='he_normal', use_bias=False)(se)

    if K.image_data_format() == 'channels_first':
        se = Permute((3, 1, 2))(se)

    x = multiply([init, se])
    return x 
開發者ID:titu1994,項目名稱:keras-squeeze-excite-network,代碼行數:29,代碼來源:se.py

示例14: squeeze_excite_block

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import GlobalAveragePooling2D [as 別名]
def squeeze_excite_block(input_tensor, ratio=16):
    """ Create a channel-wise squeeze-excite block

    Args:
        input_tensor: input Keras tensor
        ratio: number of output filters

    Returns: a Keras tensor

    References
    -   [Squeeze and Excitation Networks](https://arxiv.org/abs/1709.01507)
    """
    init = input_tensor
    channel_axis = 1 if K.image_data_format() == "channels_first" else -1
    filters = _tensor_shape(init)[channel_axis]
    se_shape = (1, 1, filters)

    se = GlobalAveragePooling2D()(init)
    se = Reshape(se_shape)(se)
    se = Dense(filters // ratio, activation='relu', kernel_initializer='he_normal', use_bias=False)(se)
    se = Dense(filters, activation='sigmoid', kernel_initializer='he_normal', use_bias=False)(se)

    if K.image_data_format() == 'channels_first':
        se = Permute((3, 1, 2))(se)

    x = multiply([init, se])
    return x 
開發者ID:titu1994,項目名稱:keras-squeeze-excite-network,代碼行數:29,代碼來源:se.py

示例15: model_fn

# 需要導入模塊: from keras import layers [as 別名]
# 或者: from keras.layers import GlobalAveragePooling2D [as 別名]
def model_fn(actions):
    # unpack the actions from the list
    kernel_1, filters_1, kernel_2, filters_2, kernel_3, filters_3, kernel_4, filters_4 = actions

    ip = Input(shape=(32, 32, 3))
    x = Conv2D(filters_1, (kernel_1, kernel_1), strides=(2, 2), padding='same', activation='relu')(ip)
    x = Conv2D(filters_2, (kernel_2, kernel_2), strides=(1, 1), padding='same', activation='relu')(x)
    x = Conv2D(filters_3, (kernel_3, kernel_3), strides=(2, 2), padding='same', activation='relu')(x)
    x = Conv2D(filters_4, (kernel_4, kernel_4), strides=(1, 1), padding='same', activation='relu')(x)
    x = GlobalAveragePooling2D()(x)
    x = Dense(10, activation='softmax')(x)

    model = Model(ip, x)
    return model 
開發者ID:titu1994,項目名稱:neural-architecture-search,代碼行數:16,代碼來源:model.py


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