您当前的位置:首页 > IT编程 > Keras
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:Python layers.MaxPooling2D方法代码示例

51自学网 2020-12-01 11:08:45
  Keras
这篇教程Python layers.MaxPooling2D方法代码示例写得很实用,希望能帮到您。

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

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

示例1: build_cae_model

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def build_cae_model(height=32, width=32, channel=3):    """    build convolutional autoencoder model    """    input_img = Input(shape=(height, width, channel))    # encoder    net = Conv2D(16, (3, 3), activation='relu', padding='same')(input_img)    net = MaxPooling2D((2, 2), padding='same')(net)    net = Conv2D(8, (3, 3), activation='relu', padding='same')(net)    net = MaxPooling2D((2, 2), padding='same')(net)    net = Conv2D(4, (3, 3), activation='relu', padding='same')(net)    encoded = MaxPooling2D((2, 2), padding='same', name='enc')(net)    # decoder    net = Conv2D(4, (3, 3), activation='relu', padding='same')(encoded)    net = UpSampling2D((2, 2))(net)    net = Conv2D(8, (3, 3), activation='relu', padding='same')(net)    net = UpSampling2D((2, 2))(net)    net = Conv2D(16, (3, 3), activation='relu', padding='same')(net)    net = UpSampling2D((2, 2))(net)    decoded = Conv2D(channel, (3, 3), activation='sigmoid', padding='same')(net)    return Model(input_img, decoded) 
开发者ID:hiram64,项目名称:ocsvm-anomaly-detection,代码行数:26,代码来源:model.py


示例2: build_model

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def build_model(x_train, num_classes):        # Reset default graph. Keras leaves old ops in the graph,        # which are ignored for execution but clutter graph        # visualization in TensorBoard.        tf.reset_default_graph()        inputs = KL.Input(shape=x_train.shape[1:], name="input_image")        x = KL.Conv2D(32, (3, 3), activation='relu', padding="same",                      name="conv1")(inputs)        x = KL.Conv2D(64, (3, 3), activation='relu', padding="same",                      name="conv2")(x)        x = KL.MaxPooling2D(pool_size=(2, 2), name="pool1")(x)        x = KL.Flatten(name="flat1")(x)        x = KL.Dense(128, activation='relu', name="dense1")(x)        x = KL.Dense(num_classes, activation='softmax', name="dense2")(x)        return KM.Model(inputs, x, "digit_classifier_model")    # Load MNIST Data 
开发者ID:dataiku,项目名称:dataiku-contrib,代码行数:21,代码来源:parallel_model.py


示例3: max_pool2d

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def max_pool2d(h_kernel_size, h_stride):    def compile_fn(di, dh):        layer = layers.MaxPooling2D(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('MaxPool2D', compile_fn, {        'kernel_size': h_kernel_size,        'stride': h_stride,    }) 
开发者ID:negrinho,项目名称:deep_architect,代码行数:18,代码来源:keras_ops.py


示例4: modelF

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def modelF():    model = Sequential()    model.add(Convolution2D(32, 3, 3,                            border_mode='valid',                            input_shape=(FLAGS.IMAGE_ROWS,                                         FLAGS.IMAGE_COLS,                                         FLAGS.NUM_CHANNELS)))    model.add(Activation('relu'))    model.add(MaxPooling2D(pool_size=(2, 2)))    model.add(Convolution2D(64, 3, 3))    model.add(Activation('relu'))    model.add(MaxPooling2D(pool_size=(2, 2)))    model.add(Flatten())    model.add(Dense(1024))    model.add(Activation('relu'))    model.add(Dense(FLAGS.NUM_CLASSES))    return model 
开发者ID:sunblaze-ucb,项目名称:blackbox-attacks,代码行数:26,代码来源:mnist.py


示例5: _initial_conv_block_inception

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def _initial_conv_block_inception(input, initial_conv_filters, weight_decay=5e-4):    ''' Adds an initial conv block, with batch norm and relu for the DPN    Args:        input: input tensor        initial_conv_filters: number of filters for initial conv block        weight_decay: weight decay factor    Returns: a keras tensor    '''    channel_axis = 1 if K.image_data_format() == 'channels_first' else -1    x = Conv2D(initial_conv_filters, (7, 7), padding='same', use_bias=False, kernel_initializer='he_normal',               kernel_regularizer=l2(weight_decay), strides=(2, 2))(input)    x = BatchNormalization(axis=channel_axis)(x)    x = Activation('relu')(x)    x = MaxPooling2D((3, 3), strides=(2, 2), padding='same')(x)    return x 
开发者ID:titu1994,项目名称:Keras-DualPathNetworks,代码行数:20,代码来源:dual_path_network.py


示例6: cnn_2D

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def cnn_2D(self, input_shape, modual=''):        #建立Sequential模型            model_in = Input(input_shape)         model = Conv2D(                filters = 6,                kernel_size = (3, 3),                input_shape = input_shape,                activation='relu',                kernel_initializer='he_normal',                name = modual+'conv1'            )(model_in)# now 30x30x6        model = MaxPooling2D(pool_size=(2,2))(model)# now 15x15x6        model = Conv2D(                filters = 8,                kernel_size = (4, 4),                activation='relu',                kernel_initializer='he_normal',                name = modual+'conv2'            )(model)# now 12x12x8        model = MaxPooling2D(pool_size=(2,2))(model)# now 6x6x8        model = Flatten()(model)        model = Dropout(0.5)(model)        model_out = Dense(100, activation='relu', name = modual+'fc1')(model)              return model_in, model_out 
开发者ID:xyj77,项目名称:MCF-3D-CNN,代码行数:27,代码来源:liver_model.py


示例7: get_Shared_Model

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def get_Shared_Model(input_dim):    sharedNet = Sequential()    sharedNet.add(Dense(128, input_shape=(input_dim,), activation='relu'))    sharedNet.add(Dropout(0.1))    sharedNet.add(Dense(128, activation='relu'))    sharedNet.add(Dropout(0.1))    sharedNet.add(Dense(128, activation='relu'))    # sharedNet.add(Dropout(0.1))    # sharedNet.add(Dense(3, activation='relu'))    # sharedNet = Sequential()    # sharedNet.add(Dense(4096, activation="tanh", kernel_regularizer=l2(2e-3)))    # sharedNet.add(Reshape(target_shape=(64, 64, 1)))    # sharedNet.add(Conv2D(filters=64, kernel_size=3, strides=(2, 2), padding="same", activation="relu", kernel_regularizer=l2(1e-3)))    # sharedNet.add(MaxPooling2D())    # sharedNet.add(Conv2D(filters=128, kernel_size=3, strides=(2, 2), padding="same", activation="relu", kernel_regularizer=l2(1e-3)))    # sharedNet.add(MaxPooling2D())    # sharedNet.add(Conv2D(filters=64, kernel_size=3, strides=(1, 1), padding="same", activation="relu", kernel_regularizer=l2(1e-3)))    # sharedNet.add(Flatten())    # sharedNet.add(Dense(1024, activation="sigmoid", kernel_regularizer=l2(1e-3)))    return sharedNet 
开发者ID:liuguiyangnwpu,项目名称:MassImageRetrieval,代码行数:22,代码来源:SiameseModel.py


示例8: build_model

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def build_model(self):        self.model = Sequential()        self.model.add(Conv2D(32, kernel_size=(3, 3),                         activation='relu', input_shape=(28, 28, 1)))        self.model.add(Conv2D(64, (3, 3), activation='relu'))        self.model.add(MaxPooling2D(pool_size=(2, 2)))        self.model.add(Dropout(0.25))        self.model.add(Flatten())        self.model.add(Dense(128, activation='relu'))        self.model.add(Dropout(0.5))        self.model.add(Dense(10, activation='softmax'))        self.model.compile(              loss='sparse_categorical_crossentropy',              optimizer=self.config.model.optimizer,              metrics=['accuracy']) 
开发者ID:Ahmkel,项目名称:Keras-Project-Template,代码行数:18,代码来源:conv_mnist_model.py


示例9: VGG_16

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def VGG_16():    '''Model definition'''    model = Sequential()    model.add(Conv2D(64, (11, 11,), padding='valid', strides=(4,4), input_shape=(img_height,img_width,num_channels), name='conv1'))    model.add(Activation('relu', name='relu1'))    model.add(LocalResponseNormalization(name='norm1'))    model.add(MaxPooling2D((2,2), padding='same', name='pool1'))    model.add(Conv2D(256, (5,5), padding='same', name='conv2'))    model.add(Activation('relu', name='relu2'))    model.add(LocalResponseNormalization(name='norm2'))    model.add(MaxPooling2D((2,2), padding='same', name='pool2'))    model.add(Conv2D(256, (3, 3), padding='same', name='conv3'))    model.add(Activation('relu', name='relu3'))    model.add(Conv2D(256, (3, 3), padding='same', name='conv4'))    model.add(Activation('relu', name='relu4'))    model.add(Conv2D(256, (3, 3), padding='same', name='conv5'))    model.add(Activation('relu', name='relu5'))    model.add(MaxPooling2D((2,2), padding='same', name='pool5'))    return model 
开发者ID:dalmia,项目名称:WannaPark,代码行数:25,代码来源:train_detection.py


示例10: get_model

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def get_model():    model = models.Sequential()    model.add(layers.Conv2D(16,(3,3),activation='relu',input_shape=(135,240,3),padding = 'same'))    model.add(layers.MaxPooling2D((2,2)))    model.add(layers.Conv2D(32,(3,3),activation='relu',padding = 'same'))    model.add(layers.MaxPooling2D((2,2)))    model.add(layers.Conv2D(64,(3,3),activation='relu',padding = 'same'))    model.add(layers.MaxPooling2D((2,2)))    model.add(layers.Conv2D(64,(3,3),activation='relu',padding = 'same'))    model.add(layers.MaxPooling2D((2,2)))    model.add(layers.Conv2D(128,(3,3),activation='relu',padding = 'same'))    model.add(layers.MaxPooling2D((2,2)))    model.add(layers.Flatten())    model.add(layers.Dropout(0.5))    model.add(layers.Dense(128,activation="relu"))    model.add(layers.Dropout(0.5))    model.add(layers.Dense(27,activation="softmax"))    return model#model.summary()#plot_model(model, to_file='model.png') 
开发者ID:lyffly,项目名称:AI_for_Wechat_tiaoyitiao,代码行数:24,代码来源:mymodel.py


示例11: create_vgglike_network

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def create_vgglike_network(input_shape, weights):    input = Input(shape=input_shape)    # input: 192x256 images with 3 channels -> (192, 256, 3) tensors.    # this applies 32 convolution filters of size 3x3 each.    x = Conv2D(32, (3, 3), activation='relu')(input)    x = Conv2D(32, (3, 3), activation='relu')(x)    x = MaxPooling2D(pool_size=(2, 2))(x)    x = Dropout(0.25)(x)    x = Conv2D(64, (3, 3), activation='relu')(x)    x = Conv2D(64, (3, 3), activation='relu')(x)    x = MaxPooling2D(pool_size=(2, 2))(x)    x = Dropout(0.25)(x)    x = Flatten()(x)    x = Dense(256, activation='relu')(x)    x = Dropout(0.5)(x)    # x = Dense(2, activation='softmax')(x)    x = Dense(128, activation='relu')(x)    return Model(input, x) 
开发者ID:marco-c,项目名称:autowebcompat,代码行数:24,代码来源:network.py


示例12: build

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def build(width, height, depth, total_classes, Saved_Weights_Path=None):        # Initialize the Model        model = Sequential()        # First CONV => RELU => POOL Layer        model.add(Conv2D(20, 5, 5, border_mode="same", input_shape=(depth, height, width)))        model.add(Activation("relu"))        model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2), dim_ordering="th"))        # Second CONV => RELU => POOL Layer        model.add(Conv2D(50, 5, 5, border_mode="same"))        model.add(Activation("relu"))        model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2), dim_ordering="th"))        # Third CONV => RELU => POOL Layer        # Convolution -> ReLU Activation Function -> Pooling Layer        model.add(Conv2D(100, 5, 5, border_mode="same"))        model.add(Activation("relu"))        model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2), dim_ordering="th"))        # FC => RELU layers        #  Fully Connected Layer -> ReLU Activation Function        model.add(Flatten())        model.add(Dense(500))        model.add(Activation("relu"))        # Using Softmax Classifier for Linear Classification        model.add(Dense(total_classes))        model.add(Activation("softmax"))        # If the saved_weights file is already present i.e model is pre-trained, load that weights        if Saved_Weights_Path is not None:            model.load_weights(Saved_Weights_Path)        return model# --------------------------------- EOC ------------------------------------ 
开发者ID:anujdutt9,项目名称:Handwritten-Digit-Recognition-using-Deep-Learning,代码行数:37,代码来源:neural_network.py


示例13: load_model

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def load_model():    from keras.models import Model    from keras.layers import Input, Dense, Dropout, Flatten, Conv2D, MaxPooling2D        tensor_in = Input((60, 200, 3))    out = tensor_in    out = Conv2D(filters=32, kernel_size=(3, 3), padding='same', activation='relu')(out)    out = Conv2D(filters=32, kernel_size=(3, 3), activation='relu')(out)    out = MaxPooling2D(pool_size=(2, 2))(out)    out = Conv2D(filters=64, kernel_size=(3, 3), padding='same', activation='relu')(out)    out = Conv2D(filters=64, kernel_size=(3, 3), activation='relu')(out)    out = MaxPooling2D(pool_size=(2, 2))(out)    out = Conv2D(filters=128, kernel_size=(3, 3), padding='same', activation='relu')(out)    out = Conv2D(filters=128, kernel_size=(3, 3), activation='relu')(out)    out = MaxPooling2D(pool_size=(2, 2))(out)    out = Conv2D(filters=256, kernel_size=(3, 3), activation='relu')(out)    out = MaxPooling2D(pool_size=(2, 2))(out)    out = Flatten()(out)    out = Dropout(0.5)(out)    out = [Dense(37, name='digit1', activation='softmax')(out),/        Dense(37, name='digit2', activation='softmax')(out),/        Dense(37, name='digit3', activation='softmax')(out),/        Dense(37, name='digit4', activation='softmax')(out),/        Dense(37, name='digit5', activation='softmax')(out),/        Dense(37, name='digit6', activation='softmax')(out)]        model = Model(inputs=tensor_in, outputs=out)        # Define the optimizer    model.compile(loss='categorical_crossentropy', optimizer='Adamax', metrics=['accuracy'])    if 'Windows' in platform.platform():        model.load_weights('{}//cnn_weight//verificatioin_code.h5'.format(PATH))     else:        model.load_weights('{}/cnn_weight/verificatioin_code.h5'.format(PATH))         return model 
开发者ID:linsamtw,项目名称:TaiwanTrainVerificationCode2text,代码行数:39,代码来源:load_model.py


示例14: build_model

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def build_model(n_classes):    if K.image_dim_ordering() == 'th':        input_shape = (1, N_MEL_BANDS, SEGMENT_DUR)        channel_axis = 1    else:        input_shape = (N_MEL_BANDS, SEGMENT_DUR, 1)        channel_axis = 3    melgram_input = Input(shape=input_shape)    m_sizes = [50, 70]    n_sizes = [1, 3, 5]    n_filters = [128, 64, 32]    maxpool_const = 4    layers = list()    for m_i in m_sizes:        for i, n_i in enumerate(n_sizes):            x = Convolution2D(n_filters[i], m_i, n_i,                              border_mode='same',                              init='he_normal',                              W_regularizer=l2(1e-5),                              name=str(n_i)+'_'+str(m_i)+'_'+'conv')(melgram_input)            x = BatchNormalization(axis=channel_axis, mode=0, name=str(n_i)+'_'+str(m_i)+'_'+'bn')(x)            x = ELU()(x)            x = MaxPooling2D(pool_size=(N_MEL_BANDS, SEGMENT_DUR/maxpool_const), name=str(n_i)+'_'+str(m_i)+'_'+'pool')(x)            x = Flatten(name=str(n_i)+'_'+str(m_i)+'_'+'flatten')(x)            layers.append(x)    x = merge(layers, mode='concat', concat_axis=channel_axis)    x = Dropout(0.5)(x)    x = Dense(n_classes, init='he_normal', W_regularizer=l2(1e-5), activation='softmax', name='prediction')(x)    model = Model(melgram_input, x)    return model 
开发者ID:Veleslavia,项目名称:EUSIPCO2017,代码行数:38,代码来源:singlelayer.py


示例15: resnet_graph

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def resnet_graph(input_image, architecture, stage5=False, train_bn=True):    """Build a ResNet graph.        architecture: Can be resnet50 or resnet101        stage5: Boolean. If False, stage5 of the network is not created        train_bn: Boolean. Train or freeze Batch Norm layers    """    assert architecture in ["resnet50", "resnet101"]    # Stage 1    x = KL.ZeroPadding2D((3, 3))(input_image)    x = KL.Conv2D(64, (7, 7), strides=(2, 2), name='conv1', use_bias=True)(x)    x = BatchNorm(name='bn_conv1')(x, training=train_bn)    x = KL.Activation('relu')(x)    C1 = x = KL.MaxPooling2D((3, 3), strides=(2, 2), padding="same")(x)    # Stage 2    x = conv_block(x, 3, [64, 64, 256], stage=2, block='a', strides=(1, 1), train_bn=train_bn)    x = identity_block(x, 3, [64, 64, 256], stage=2, block='b', train_bn=train_bn)    C2 = x = identity_block(x, 3, [64, 64, 256], stage=2, block='c', train_bn=train_bn)    # Stage 3    x = conv_block(x, 3, [128, 128, 512], stage=3, block='a', train_bn=train_bn)    x = identity_block(x, 3, [128, 128, 512], stage=3, block='b', train_bn=train_bn)    x = identity_block(x, 3, [128, 128, 512], stage=3, block='c', train_bn=train_bn)    C3 = x = identity_block(x, 3, [128, 128, 512], stage=3, block='d', train_bn=train_bn)    # Stage 4    x = conv_block(x, 3, [256, 256, 1024], stage=4, block='a', train_bn=train_bn)    block_count = {"resnet50": 5, "resnet101": 22}[architecture]    for i in range(block_count):        x = identity_block(x, 3, [256, 256, 1024], stage=4, block=chr(98 + i), train_bn=train_bn)    C4 = x    # Stage 5    if stage5:        x = conv_block(x, 3, [512, 512, 2048], stage=5, block='a', train_bn=train_bn)        x = identity_block(x, 3, [512, 512, 2048], stage=5, block='b', train_bn=train_bn)        C5 = x = identity_block(x, 3, [512, 512, 2048], stage=5, block='c', train_bn=train_bn)    else:        C5 = None    return [C1, C2, C3, C4, C5]#############################################################  Proposal Layer############################################################ 
开发者ID:dataiku,项目名称:dataiku-contrib,代码行数:43,代码来源:model.py


示例16: init_model

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def init_model(self, dl_rate):        x = Input(shape = (IMGWIDTH, IMGWIDTH, 3))                x1 = Conv2D(16, (3, 3), dilation_rate = dl_rate, strides = 1, padding='same', activation = 'relu')(x)        x1 = Conv2D(4, (1, 1), padding='same', activation = 'relu')(x1)        x1 = BatchNormalization()(x1)        x1 = MaxPooling2D(pool_size=(8, 8), padding='same')(x1)        y = Flatten()(x1)        y = Dropout(0.5)(y)        y = Dense(1, activation = 'sigmoid')(y)        return KerasModel(inputs = x, outputs = y) 
开发者ID:DariusAf,项目名称:MesoNet,代码行数:14,代码来源:classifiers.py


示例17: get_unet_model

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def get_unet_model(input_channel_num=3, out_ch=3, start_ch=64, depth=4, inc_rate=2., activation='relu',         dropout=0.5, batchnorm=False, maxpool=True, upconv=True, residual=False):    def _conv_block(m, dim, acti, bn, res, do=0):        n = Conv2D(dim, 3, activation=acti, padding='same')(m)        n = BatchNormalization()(n) if bn else n        n = Dropout(do)(n) if do else n        n = Conv2D(dim, 3, activation=acti, padding='same')(n)        n = BatchNormalization()(n) if bn else n        return Concatenate()([m, n]) if res else n    def _level_block(m, dim, depth, inc, acti, do, bn, mp, up, res):        if depth > 0:            n = _conv_block(m, dim, acti, bn, res)            m = MaxPooling2D()(n) if mp else Conv2D(dim, 3, strides=2, padding='same')(n)            m = _level_block(m, int(inc * dim), depth - 1, inc, acti, do, bn, mp, up, res)            if up:                m = UpSampling2D()(m)                m = Conv2D(dim, 2, activation=acti, padding='same')(m)            else:                m = Conv2DTranspose(dim, 3, strides=2, activation=acti, padding='same')(m)            n = Concatenate()([n, m])            m = _conv_block(n, dim, acti, bn, res)        else:            m = _conv_block(m, dim, acti, bn, res, do)        return m    i = Input(shape=(None, None, input_channel_num))    o = _level_block(i, start_ch, depth, inc_rate, activation, dropout, batchnorm, maxpool, upconv, residual)    o = Conv2D(out_ch, 1)(o)    model = Model(inputs=i, outputs=o)    return model 
开发者ID:zxq2233,项目名称:n2n-watermark-remove,代码行数:36,代码来源:model.py


示例18: create_model

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def create_model():    model = Sequential()    model.add(Convolution2D(32, 3, 3,                            border_mode='valid',                             input_shape=(100, 100, 3)))      model.add(Activation('relu'))      model.add(Convolution2D(32, 3, 3))      model.add(Activation('relu'))      model.add(MaxPooling2D(pool_size=(2, 2)))      model.add(Dropout(0.25))            model.add(Convolution2D(64, 3, 3,                             border_mode='valid'))      model.add(Activation('relu'))      model.add(Convolution2D(64, 3, 3))      model.add(Activation('relu'))      model.add(MaxPooling2D(pool_size=(2, 2)))      model.add(Dropout(0.25))            model.add(Flatten())      model.add(Dense(256))      model.add(Activation('relu'))      model.add(Dropout(0.5))    model.add(Dense(2))      model.add(Activation('softmax'))      return model 
开发者ID:JasonDoingGreat,项目名称:Convolutional-Networks-for-Stock-Predicting,代码行数:31,代码来源:cnn_main.py


示例19: load_traffic_sign_model

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def load_traffic_sign_model(base=32, dense=512, num_classes=43):    input_shape = (32, 32, 3)    model = Sequential()    model.add(Conv2D(base, (3, 3), padding='same',                     input_shape=input_shape,                     activation='relu'))    model.add(Conv2D(base, (3, 3), activation='relu'))    model.add(MaxPooling2D(pool_size=(2, 2)))    model.add(Dropout(0.2))    model.add(Conv2D(base * 2, (3, 3), padding='same',                     activation='relu'))    model.add(Conv2D(base * 2, (3, 3), activation='relu'))    model.add(MaxPooling2D(pool_size=(2, 2)))    model.add(Dropout(0.2))    model.add(Conv2D(base * 4, (3, 3), padding='same',                     activation='relu'))    model.add(Conv2D(base * 4, (3, 3), activation='relu'))    model.add(MaxPooling2D(pool_size=(2, 2)))    model.add(Dropout(0.2))    model.add(Flatten())    model.add(Dense(dense, activation='relu'))    model.add(Dropout(0.5))    model.add(Dense(num_classes, activation='softmax'))    opt = keras.optimizers.adam(lr=0.001, decay=1 * 10e-5)    model.compile(loss='categorical_crossentropy', optimizer=opt, metrics=['accuracy'])    return model 
开发者ID:bolunwang,项目名称:backdoor,代码行数:34,代码来源:gtsrb_injection_example.py


示例20: create_model

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def create_model(self) -> Sequential:        """ model structure. you can overwrite this method to build your own model """        logger.info(f"creating keras sequential model")        if K.image_data_format() == "channels_first":            input_shape = (1, *self.data_size)        else:            input_shape = (*self.data_size, 1)        model = Sequential()        model.add(Conv2D(32, (3, 3), input_shape=input_shape))        model.add(Activation("relu"))        model.add(MaxPooling2D(pool_size=(2, 2)))        model.add(Conv2D(32, (3, 3)))        model.add(Activation("relu"))        model.add(MaxPooling2D(pool_size=(2, 2)))        model.add(Conv2D(64, (3, 3)))        model.add(Activation("relu"))        model.add(MaxPooling2D(pool_size=(2, 2)))        model.add(Flatten())        model.add(Dense(64))        model.add(Activation("relu"))        model.add(Dropout(0.5))        model.add(Dense(6))        model.add(Activation("softmax"))        model.compile(            loss="sparse_categorical_crossentropy",            optimizer="rmsprop",            metrics=["accuracy"],        )        logger.info("model created")        return model 
开发者ID:williamfzc,项目名称:stagesepx,代码行数:36,代码来源:keras.py


示例21: get_logit_cnn_layers

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def get_logit_cnn_layers(nb_units, p, wd, nb_classes, layers = [], dropout = False):    # number of convolutional filters to use    nb_filters = 32    # size of pooling area for max pooling    pool_size = (2, 2)    # convolution kernel size    kernel_size = (3, 3)    if dropout == 'MC':        D = Dropout_mc    if dropout == 'pW':        D = pW    if dropout == 'none':        D = Identity    layers.append(Convolution2D(nb_filters, kernel_size[0], kernel_size[1],                                border_mode='valid', W_regularizer=l2(wd)))    layers.append(Activation('relu'))    layers.append(Convolution2D(nb_filters, kernel_size[0], kernel_size[1],                                W_regularizer=l2(wd)))    layers.append(Activation('relu'))    layers.append(MaxPooling2D(pool_size=pool_size))    layers.append(Flatten())    layers.append(D(p))    layers.append(Dense(nb_units, W_regularizer=l2(wd)))    layers.append(Activation('relu'))    layers.append(D(p))    layers.append(Dense(nb_classes, W_regularizer=l2(wd)))    return layers 
开发者ID:YingzhenLi,项目名称:Dropout_BBalpha,代码行数:32,代码来源:BBalpha_dropout.py


示例22: facial_landmark_cnn

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def facial_landmark_cnn(input_shape=INPUT_SHAPE, output_size=OUTPUT_SIZE):    # Stage 1 #    img_input = Input(shape=input_shape)        ## Block 1 ##    x = Conv2D(32, (3,3), strides=(1,1), name='S1_conv1')(img_input)    x = BatchNormalization()(x)    x = Activation('relu', name='S1_relu_conv1')(x)    x = MaxPooling2D(pool_size=(2,2), strides=(2,2), name='S1_pool1')(x)    ## Block 2 ##    x = Conv2D(64, (3,3), strides=(1,1), name='S1_conv2')(x)    x = BatchNormalization()(x)    x = Activation('relu', name='S1_relu_conv2')(x)    x = Conv2D(64, (3,3), strides=(1,1), name='S1_conv3')(x)    x = BatchNormalization()(x)    x = Activation('relu', name='S1_relu_conv3')(x)    x = MaxPooling2D(pool_size=(2,2), strides=(2,2), name='S1_pool2')(x)    ## Block 3 ##    x = Conv2D(64, (3,3), strides=(1,1), name='S1_conv4')(x)    x = BatchNormalization()(x)    x = Activation('relu', name='S1_relu_conv4')(x)    x = Conv2D(64, (3,3), strides=(1,1), name='S1_conv5')(x)    x = BatchNormalization()(x)    x = Activation('relu', name='S1_relu_conv5')(x)    x = MaxPooling2D(pool_size=(2,2), strides=(2,2), name='S1_pool3')(x)            ## Block 4 ##    x = Conv2D(256, (3,3), strides=(1,1), name='S1_conv8')(x)    x = BatchNormalization()(x)    x = Activation('relu', name='S1_relu_conv8')(x)    x = Dropout(0.2)(x)        ## Block 5 ##    x = Flatten(name='S1_flatten')(x)    x = Dense(2048, activation='relu', name='S1_fc1')(x)    x = Dense(output_size, activation=None, name='S1_predictions')(x)    model = Model([img_input], x, name='facial_landmark_model')        return model 
开发者ID:junhwanjang,项目名称:face_landmark_dnn,代码行数:43,代码来源:train_basic_models.py


示例23: cunn_keras

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def cunn_keras(img_rows=FLAGS.img_rows, img_cols=FLAGS.img_cols, channels=FLAGS.nb_channels, nb_classes=FLAGS.nb_classes):    '''    Defines the VGG 16 model using the Keras Sequential model    :param img_rows: number of row in the image    :param img_cols: number of columns in the image    :param channels: number of color channels (e.g., 1 for MNIST)    :param nb_classes: the number of output classes    :return: a Keras model. Call with model(<input_tensor>)    '''    input = Input(shape=(img_rows, img_cols, channels))    conv1 = Convolution2D(32,5,5, border_mode='same', subsample=(1,1), activation='relu')(input)    pool1 = MaxPooling2D((2,2), strides=(2,2))(conv1)    conv2 = Convolution2D(64,5,5, border_mode='same', subsample=(1,1), activation='relu')(pool1)    pool2 = MaxPooling2D((2,2), strides=(2,2))(conv2)    conv3 = Convolution2D(128,5,5, border_mode='same', subsample=(1,1), activation='relu')(pool2)    pool3 = MaxPooling2D((2,2), strides=(2,2))(conv3)    flat1 = Flatten()(pool1)    flat2 = Flatten()(pool2)    flat3 = Flatten()(pool3)    flat_all = merge([flat1, flat2, flat3], mode='concat', concat_axis=1) #If this gives an error, update the keras tensorflow backend. It is likely that is making the call tf.concat(axis, [to_dense(x) for x in tensors]) in of tf.concat([to_dense(x) for x in tensors], axis)    fc = Dense(1024)(flat_all)    drop = Dropout(0.5)(fc)    fc2 = Dense(nb_classes)(drop)    output = Activation('softmax',name='prob')(fc2)    model = Model(input=input, output=output)    return model 
开发者ID:evtimovi,项目名称:robust_physical_perturbations,代码行数:37,代码来源:model.py


示例24: build_cnn

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def build_cnn(image_size=None):	image_size = image_size or (60, 80)	if K.image_dim_ordering() == 'th':	    input_shape = (3,) + image_size	else:	    input_shape = image_size + (3, )	img_input = Input(input_shape)	x = Convolution2D(64, 3, 3, activation='relu', border_mode='same')(img_input)	x = Dropout(0.5)(x)	x = Convolution2D(64, 3, 3, activation='relu', border_mode='same')(x)	x = Dropout(0.5)(x)	x = MaxPooling2D((2, 2), strides=(2, 2))(x)	x = Convolution2D(128, 3, 3, activation='relu', border_mode='same')(x)	x = Dropout(0.5)(x)	# it doesn't fit in my GPU	# x = Convolution2D(128, 3, 3, activation='relu', border_mode='same')(x)	# x = Dropout(0.5)(x)	x = MaxPooling2D((2, 2), strides=(2, 2))(x)	y = Flatten()(x)	y = Dense(1024, activation='relu')(y)	y = Dropout(.5)(y)	y = Dense(1024, activation='relu')(y)	y = Dropout(.5)(y)	y = Dense(1)(y)	model = Model(input=img_input, output=y)	model.compile(optimizer=Adam(lr=1e-4), loss = 'mse')	return model 
开发者ID:dolaameng,项目名称:udacity-SDC-baseline,代码行数:34,代码来源:model.py


示例25: encoder

# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import MaxPooling2D [as 别名]def encoder(self):        encoded = Conv2D(16, (3, 3), activation='relu', padding='same')(input_img_conv)        encoded = MaxPooling2D((2, 2), padding='same')(encoded)        encoded = Conv2D(8, (3, 3), activation='relu', padding='same')(encoded)        encoded = MaxPooling2D((2, 2), padding='same')(encoded)        encoded = Conv2D(8, (3, 3), activation='relu', padding='same')(encoded)        encoded = MaxPooling2D((2, 2), padding='same')(encoded)        return encoded 
开发者ID:akshaybahadur21,项目名称:DigiEncoder,代码行数:10,代码来源:Coder.py


万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。