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


Python convolutional.MaxPooling2D方法代码示例

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


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

示例1: model_create

# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import MaxPooling2D [as 别名]
def model_create(input_shape, num_classes):
        logging.debug('input_shape {}'.format(input_shape))

        model = Sequential()

        model.add(Conv2D(32, (3, 3), border_mode='same', input_shape=input_shape))
        model.add(Activation('relu'))

        model.add(Conv2D(32, (3, 3)))
        model.add(Activation('relu'))
        model.add(MaxPooling2D(pool_size=(2, 2)))
        model.add(Dropout(0.5))

        model.add(Flatten())
        model.add(Dense(128))
        model.add(Activation('relu'))
        model.add(Dropout(0.5))

        model.add(Dense(num_classes))
        model.add(Activation('softmax'))

        # use binary_crossentropy if has just 2 prediction yes or no
        model.compile(loss='categorical_crossentropy', optimizer='adadelta', metrics=['accuracy'])

        return model 
开发者ID:abhishekrana,项目名称:DeepFashion,代码行数:27,代码来源:cnn.py

示例2: cnn_model

# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import MaxPooling2D [as 别名]
def cnn_model():
	num_of_classes = get_num_of_classes()
	model = Sequential()
	model.add(Conv2D(16, (2,2), input_shape=(image_x, image_y, 1), activation='relu'))
	model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2), padding='same'))
	model.add(Conv2D(32, (3,3), activation='relu'))
	model.add(MaxPooling2D(pool_size=(3, 3), strides=(3, 3), padding='same'))
	model.add(Conv2D(64, (5,5), activation='relu'))
	model.add(MaxPooling2D(pool_size=(5, 5), strides=(5, 5), padding='same'))
	model.add(Flatten())
	model.add(Dense(128, activation='relu'))
	model.add(Dropout(0.2))
	model.add(Dense(num_of_classes, activation='softmax'))
	sgd = optimizers.SGD(lr=1e-2)
	model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
	filepath="cnn_model_keras2.h5"
	checkpoint1 = ModelCheckpoint(filepath, monitor='val_acc', verbose=1, save_best_only=True, mode='max')
	callbacks_list = [checkpoint1]
	#from keras.utils import plot_model
	#plot_model(model, to_file='model.png', show_shapes=True)
	return model, callbacks_list 
开发者ID:harshbg,项目名称:Sign-Language-Interpreter-using-Deep-Learning,代码行数:23,代码来源:cnn_model_train.py

示例3: block_reduction_a

# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import MaxPooling2D [as 别名]
def block_reduction_a(input):
    if K.image_dim_ordering() == "th":
        channel_axis = 1
    else:
        channel_axis = -1

    branch_0 = conv2d_bn(input, 384, 3, 3, subsample=(2,2), border_mode='valid')

    branch_1 = conv2d_bn(input, 192, 1, 1)
    branch_1 = conv2d_bn(branch_1, 224, 3, 3)
    branch_1 = conv2d_bn(branch_1, 256, 3, 3, subsample=(2,2), border_mode='valid')

    branch_2 = MaxPooling2D((3,3), strides=(2,2), border_mode='valid')(input)

    x = merge([branch_0, branch_1, branch_2], mode='concat', concat_axis=channel_axis)
    return x 
开发者ID:filonenkoa,项目名称:cnn_evaluation_smoke,代码行数:18,代码来源:inception_v4.py

示例4: block_reduction_b

# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import MaxPooling2D [as 别名]
def block_reduction_b(input):
    if K.image_dim_ordering() == "th":
        channel_axis = 1
    else:
        channel_axis = -1

    branch_0 = conv2d_bn(input, 192, 1, 1)
    branch_0 = conv2d_bn(branch_0, 192, 3, 3, subsample=(2, 2), border_mode='valid')

    branch_1 = conv2d_bn(input, 256, 1, 1)
    branch_1 = conv2d_bn(branch_1, 256, 1, 7)
    branch_1 = conv2d_bn(branch_1, 320, 7, 1)
    branch_1 = conv2d_bn(branch_1, 320, 3, 3, subsample=(2,2), border_mode='valid')

    branch_2 = MaxPooling2D((3, 3), strides=(2, 2), border_mode='valid')(input)

    x = merge([branch_0, branch_1, branch_2], mode='concat', concat_axis=channel_axis)
    return x 
开发者ID:filonenkoa,项目名称:cnn_evaluation_smoke,代码行数:20,代码来源:inception_v4.py

示例5: cnn

# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import MaxPooling2D [as 别名]
def cnn(trn_set, tst_set):
    trn_x, trn_y = trn_set
    trn_y = np.squeeze(trn_y, axis=2)
    tst_x, tst_y = tst_set
    tst_y = np.squeeze(tst_y, axis=2)

    model = Sequential()

    model.add(Convolution2D(2, 5, 5, activation='sigmoid', input_shape=(1, 28, 28)))
    model.add(MaxPooling2D(pool_size=(3, 3)))
    model.add(Flatten())
    model.add(Dense(10, activation='softmax'))

    model.compile(loss='categorical_crossentropy', optimizer=SGD(lr=0.1))
    return model, trn_x, trn_y, tst_x, tst_y

################################################################################ 
开发者ID:integeruser,项目名称:MNIST-cnn,代码行数:19,代码来源:train_and_save.py

示例6: build

# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import MaxPooling2D [as 别名]
def build(input_shape, classes):
        model = Sequential()
        # CONV => RELU => POOL
        model.add(Conv2D(20, kernel_size=5, padding="same", input_shape=input_shape))
        model.add(Activation("relu"))
        model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
        # CONV => RELU => POOL
        model.add(Conv2D(50, kernel_size=5, border_mode="same"))
        model.add(Activation("relu"))
        model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
        # Flatten层到RELU层
        model.add(Flatten())
        model.add(Dense(500))
        model.add(Activation("relu"))
        # softmax分类器
        model.add(Dense(classes))
        model.add(Activation("softmax"))

        return model 
开发者ID:mogoweb,项目名称:aiexamples,代码行数:21,代码来源:lenet.py

示例7: block_reduction_a

# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import MaxPooling2D [as 别名]
def block_reduction_a(input):
    if K.image_data_format() == 'channels_first':
        channel_axis = 1
    else:
        channel_axis = -1

    branch_0 = conv2d_bn(input, 384, 3, 3, strides=(2,2), padding='valid')

    branch_1 = conv2d_bn(input, 192, 1, 1)
    branch_1 = conv2d_bn(branch_1, 224, 3, 3)
    branch_1 = conv2d_bn(branch_1, 256, 3, 3, strides=(2,2), padding='valid')

    branch_2 = MaxPooling2D((3,3), strides=(2,2), padding='valid')(input)

    x = concatenate([branch_0, branch_1, branch_2], axis=channel_axis)
    return x 
开发者ID:Jeremyczhj,项目名称:FashionAI_Tianchi_2018,代码行数:18,代码来源:inception_v4.py

示例8: block_reduction_b

# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import MaxPooling2D [as 别名]
def block_reduction_b(input):
    if K.image_data_format() == 'channels_first':
        channel_axis = 1
    else:
        channel_axis = -1

    branch_0 = conv2d_bn(input, 192, 1, 1)
    branch_0 = conv2d_bn(branch_0, 192, 3, 3, strides=(2, 2), padding='valid')

    branch_1 = conv2d_bn(input, 256, 1, 1)
    branch_1 = conv2d_bn(branch_1, 256, 1, 7)
    branch_1 = conv2d_bn(branch_1, 320, 7, 1)
    branch_1 = conv2d_bn(branch_1, 320, 3, 3, strides=(2,2), padding='valid')

    branch_2 = MaxPooling2D((3, 3), strides=(2, 2), padding='valid')(input)

    x = concatenate([branch_0, branch_1, branch_2], axis=channel_axis)
    return x 
开发者ID:Jeremyczhj,项目名称:FashionAI_Tianchi_2018,代码行数:20,代码来源:inception_v4.py

示例9: init_model

# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import MaxPooling2D [as 别名]
def init_model():
    """
    """
    start_time = time.time()
    print 'Compiling model...'
    model = Sequential()

    model.add(Convolution2D(64, 3,3, border_mode='valid', input_shape=INPUT_SHAPE))
    model.add(Activation('relu'))
    model.add(MaxPooling2D(pool_size=(2,2)))
    model.add(Dropout(.25))

    model.add(Flatten())

    model.add(Dense(10))
    model.add(Activation('softmax'))

    rms = RMSprop()
    model.compile(loss='categorical_crossentropy', optimizer=rms,
      metrics=['accuracy'])
    print 'Model compiled in {0} seconds'.format(time.time() - start_time)

    model.summary()
    return model 
开发者ID:zatonovo,项目名称:deep_learning_ex,代码行数:26,代码来源:cnn_mnist.py

示例10: Block

# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import MaxPooling2D [as 别名]
def Block(input, num_filters, with_shortcut):
    out1 = Conv2D(filters=int(num_filters / 2), kernel_size=(1, 1), kernel_initializer='he_normal', weights=None,
                  padding='same',
                  strides=(1, 1), kernel_regularizer=l2(1e-6), activation='relu')(input)
    out2 = Conv2D(filters=int(num_filters), kernel_size=(3, 3), kernel_initializer='he_normal', weights=None,
                  padding='same',
                  strides=(1, 1), kernel_regularizer=l2(1e-6), activation='relu')(out1)
    out3 = Conv2D(filters=int(num_filters), kernel_size=(1, 1), kernel_initializer='he_normal', weights=None,
                  padding='same',
                  strides=(1, 1), kernel_regularizer=l2(1e-6), activation='relu')(out2)
    # out4 = pool2(pool_size=(3, 3), strides=(2, 2), data_format="channel_first")(out3)

    if with_shortcut:
        input = Conv2D(filters=num_filters, kernel_size=(3, 3), kernel_initializer='he_normal', weights=None,
                       padding='same', strides=(1, 1), kernel_regularizer=l2(1e-6), activation='relu')(input)
        return add([input, out3])
    else:
        input = Conv2D(filters=num_filters, kernel_size=(1, 1), kernel_initializer='he_normal', weights=None,
                       padding='same', strides=(1, 1), kernel_regularizer=l2(1e-6), activation='relu')(input)
        return add([input, out3])


# DenseResNet 4040 
开发者ID:thomaskuestner,项目名称:CNNArt,代码行数:25,代码来源:multiclass_DenseResNet.py

示例11: Block

# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import MaxPooling2D [as 别名]
def Block(input,num_filters,with_shortcut):
	out1 = Conv2D(filters=num_filters/2, kernel_size=(1, 1), kernel_initializer='he_normal', weights=None, padding='same',
	              strides=(1, 1), kernel_regularizer=l2(1e-6), activation='relu')(input)
	out2 = Conv2D(filters=num_filters, kernel_size=(3, 3), kernel_initializer='he_normal', weights=None, padding='same',
	              strides=(1, 1), kernel_regularizer=l2(1e-6), activation='relu')(out1)
	out3 = Conv2D(filters=num_filters, kernel_size=(1, 1), kernel_initializer='he_normal', weights=None, padding='same',
	              strides=(1, 1), kernel_regularizer=l2(1e-6), activation='relu')(out2)
	# out4 = pool2(pool_size=(3, 3), strides=(2, 2), data_format="channel_first")(out3)

	if with_shortcut:
		input = Conv2D(filters=num_filters, kernel_size=(3, 3), kernel_initializer='he_normal', weights=None,
		              padding='same',strides=(1, 1), kernel_regularizer=l2(1e-6), activation='relu')(input)
		return add([input,out3])
	else:
		input = Conv2D(filters=num_filters, kernel_size=(1, 1), kernel_initializer='he_normal', weights=None,
		              padding='same',strides=(1, 1), kernel_regularizer=l2(1e-6), activation='relu')(input)
		return add([input,out3])

# DenseResNet 4040 
开发者ID:thomaskuestner,项目名称:CNNArt,代码行数:21,代码来源:multiclass_DenseResNet.py

示例12: build_model

# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import MaxPooling2D [as 别名]
def build_model():
    inp = Input(shape=(FRAME_H, FRAME_W, 3))
    x = Conv2D(filters=8, kernel_size=(5, 5), activation='relu')(inp)
    x = MaxPooling2D((2, 2))(x)

    x = Conv2D(filters=16, kernel_size=(5, 5), activation='relu')(x)
    x = MaxPooling2D((2, 2))(x)

    x = Conv2D(filters=32, kernel_size=(5, 5), activation='relu')(x)
    x = MaxPooling2D((2, 2))(x)

    x = Flatten()(x)
    x = Dropout(0.5)(x)
    x = Dense(128, activation='relu')(x)
    x = Dropout(0.5)(x)
    x = Dense(1, activation='tanh')(x)
    return Model(inputs=[inp], outputs=[x]) 
开发者ID:raghakot,项目名称:keras-vis,代码行数:19,代码来源:model.py

示例13: reduction_A

# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import MaxPooling2D [as 别名]
def reduction_A(input, k=192, l=224, m=256, n=384):
    if K.image_dim_ordering() == "th":
        channel_axis = 1
    else:
        channel_axis = -1

    r1 = MaxPooling2D((3,3), strides=(2,2))(input)

    r2 = Convolution2D(n, 3, 3, activation='relu', subsample=(2,2))(input)

    r3 = Convolution2D(k, 1, 1, activation='relu', border_mode='same')(input)
    r3 = Convolution2D(l, 3, 3, activation='relu', border_mode='same')(r3)
    r3 = Convolution2D(m, 3, 3, activation='relu', subsample=(2,2))(r3)

    m = merge([r1, r2, r3], mode='concat', concat_axis=channel_axis)
    m = BatchNormalization(axis=1)(m)
    m = Activation('relu')(m)
    return m 
开发者ID:titu1994,项目名称:Inception-v4,代码行数:20,代码来源:inception_resnet_v2.py

示例14: reduction_resnet_v2_B

# 需要导入模块: from keras.layers import convolutional [as 别名]
# 或者: from keras.layers.convolutional import MaxPooling2D [as 别名]
def reduction_resnet_v2_B(input):
    if K.image_dim_ordering() == "th":
        channel_axis = 1
    else:
        channel_axis = -1

    r1 = MaxPooling2D((3,3), strides=(2,2), border_mode='valid')(input)

    r2 = Convolution2D(256, 1, 1, activation='relu', border_mode='same')(input)
    r2 = Convolution2D(384, 3, 3, activation='relu', subsample=(2,2))(r2)

    r3 = Convolution2D(256, 1, 1, activation='relu', border_mode='same')(input)
    r3 = Convolution2D(288, 3, 3, activation='relu', subsample=(2, 2))(r3)

    r4 = Convolution2D(256, 1, 1, activation='relu', border_mode='same')(input)
    r4 = Convolution2D(288, 3, 3, activation='relu', border_mode='same')(r4)
    r4 = Convolution2D(320, 3, 3, activation='relu', subsample=(2, 2))(r4)

    m = merge([r1, r2, r3, r4], concat_axis=channel_axis, mode='concat')
    m = BatchNormalization(axis=channel_axis)(m)
    m = Activation('relu')(m)
    return m 
开发者ID:titu1994,项目名称:Inception-v4,代码行数:24,代码来源:inception_resnet_v2.py

示例15: cnn_model

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

    # A Convolution2D sera a nossa camada de entrada. Podemos observar que ela possui 
    # 32 mapas de features com tamanho de 5 × 5 e 'relu' como funcao de ativacao. 
    model.add(Conv2D(32, (5, 5), input_shape=(1, 28, 28), activation='relu'))

    # A camada MaxPooling2D sera nossa segunda camada onde teremos um amostragem de 
    # dimensoes 2 × 2.
    model.add(MaxPooling2D(pool_size=(2, 2)))

    # Durante a regularizacao usamos o metodo de Dropout
    # excluindo 30% dos neuronios na camada, diminuindo nossa chance de overfitting.
    model.add(Dropout(0.3))

    # Usamos a Flatten para converter nossa matriz 2D
    # numa representacao a ser processada pela fully connected.
    model.add(Flatten())

    # Camada fully connected com 128 neuronios e funcao de ativacao 'relu'.
    model.add(Dense(128, activation='relu'))
    
    # Nossa camada de saida possui o numero de neuronios compativel com o 
    # numero de classes a serem classificadas, com uma funcao de ativacao
    # do tipo 'softmax'.
    model.add(Dense(num_classes, activation='softmax', name='preds'))

    model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
    return model 
开发者ID:drschilling,项目名称:keras-mnist-workshop,代码行数:31,代码来源:keras-CNN-mnist.py


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