这篇教程Python layers.GlobalMaxPool1D方法代码示例写得很实用,希望能帮到您。
本文整理汇总了Python中keras.layers.GlobalMaxPool1D方法的典型用法代码示例。如果您正苦于以下问题:Python layers.GlobalMaxPool1D方法的具体用法?Python layers.GlobalMaxPool1D怎么用?Python layers.GlobalMaxPool1D使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块keras.layers 的用法示例。 在下文中一共展示了layers.GlobalMaxPool1D方法的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。 示例1: bidLstm_simple# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import GlobalMaxPool1D [as 别名]def bidLstm_simple(maxlen, embed_size, recurrent_units, dropout_rate, recurrent_dropout_rate, dense_size, nb_classes): #inp = Input(shape=(maxlen, )) input_layer = Input(shape=(maxlen, embed_size), ) #x = Embedding(max_features, embed_size, weights=[embedding_matrix], trainable=False)(inp) x = Bidirectional(LSTM(recurrent_units, return_sequences=True, dropout=dropout_rate, recurrent_dropout=dropout_rate))(input_layer) x = Dropout(dropout_rate)(x) x_a = GlobalMaxPool1D()(x) x_b = GlobalAveragePooling1D()(x) #x_c = AttentionWeightedAverage()(x) #x_a = MaxPooling1D(pool_size=2)(x) #x_b = AveragePooling1D(pool_size=2)(x) x = concatenate([x_a,x_b]) x = Dense(dense_size, activation="relu")(x) x = Dropout(dropout_rate)(x) x = Dense(nb_classes, activation="sigmoid")(x) model = Model(inputs=input_layer, outputs=x) model.summary() model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) return model# bidirectional LSTM with attention layer
开发者ID:kermitt2,项目名称:delft,代码行数:27,代码来源:models.py
示例2: conv# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import GlobalMaxPool1D [as 别名]def conv(maxlen, embed_size, recurrent_units, dropout_rate, recurrent_dropout_rate, dense_size, nb_classes): filter_kernels = [7, 7, 5, 5, 3, 3] #inp = Input(shape=(maxlen, )) input_layer = Input(shape=(maxlen, embed_size), ) #x = Embedding(max_features, embed_size, weights=[embedding_matrix], trainable=False)(inp) conv = Conv1D(nb_filter=recurrent_units, filter_length=filter_kernels[0], border_mode='valid', activation='relu')(input_layer) conv = MaxPooling1D(pool_length=3)(conv) conv1 = Conv1D(nb_filter=recurrent_units, filter_length=filter_kernels[1], border_mode='valid', activation='relu')(conv) conv1 = MaxPooling1D(pool_length=3)(conv1) conv2 = Conv1D(nb_filter=recurrent_units, filter_length=filter_kernels[2], border_mode='valid', activation='relu')(conv1) conv3 = Conv1D(nb_filter=recurrent_units, filter_length=filter_kernels[3], border_mode='valid', activation='relu')(conv2) conv4 = Conv1D(nb_filter=recurrent_units, filter_length=filter_kernels[4], border_mode='valid', activation='relu')(conv3) conv5 = Conv1D(nb_filter=recurrent_units, filter_length=filter_kernels[5], border_mode='valid', activation='relu')(conv4) conv5 = MaxPooling1D(pool_length=3)(conv5) conv5 = Flatten()(conv5) z = Dropout(0.5)(Dense(dense_size, activation='relu')(conv5)) #x = GlobalMaxPool1D()(x) x = Dense(nb_classes, activation="sigmoid")(z) model = Model(inputs=input_layer, outputs=x) model.summary() model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) return model# LSTM + conv
开发者ID:kermitt2,项目名称:delft,代码行数:27,代码来源:models.py
示例3: byte_block# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import GlobalMaxPool1D [as 别名]def byte_block(in_layer, nb_filter=(64, 100), filter_length=(3, 3), subsample=(2, 1), pool_length=(2, 2)): block = in_layer for i in range(len(nb_filter)): block = Conv1D(filters=nb_filter[i], kernel_size=filter_length[i], padding='valid', activation='tanh', strides=subsample[i])(block) # block = BatchNormalization()(block) # block = Dropout(0.1)(block) if pool_length[i]: block = MaxPooling1D(pool_size=pool_length[i])(block) # block = Lambda(max_1d, output_shape=(nb_filter[-1],))(block) block = GlobalMaxPool1D()(block) block = Dense(128, activation='relu')(block) return block
示例4: create_model# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import GlobalMaxPool1D [as 别名]def create_model(time_window_size, metric): model = Sequential() model.add(Conv1D(filters=256, kernel_size=5, padding='same', activation='relu', input_shape=(time_window_size, 1))) model.add(GlobalMaxPool1D()) model.add(Dense(units=time_window_size, activation='linear')) model.compile(optimizer='adam', loss='mean_squared_error', metrics=[metric]) print(model.summary()) return model
示例5: Malconv# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import GlobalMaxPool1D [as 别名]def Malconv(max_len=200000, win_size=500, vocab_size=256): inp = Input((max_len,)) emb = Embedding(vocab_size, 8)(inp) conv1 = Conv1D(kernel_size=(win_size), filters=128, strides=(win_size), padding='same')(emb) conv2 = Conv1D(kernel_size=(win_size), filters=128, strides=(win_size), padding='same')(emb) a = Activation('sigmoid', name='sigmoid')(conv2) mul = multiply([conv1, a]) a = Activation('relu', name='relu')(mul) p = GlobalMaxPool1D()(a) d = Dense(64)(p) out = Dense(1, activation='sigmoid')(d) return Model(inp, out)
开发者ID:j40903272,项目名称:MalConv-keras,代码行数:17,代码来源:malconv.py
示例6: lstm# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import GlobalMaxPool1D [as 别名]def lstm(maxlen, embed_size, recurrent_units, dropout_rate, recurrent_dropout_rate, dense_size, nb_classes): #inp = Input(shape=(maxlen, )) input_layer = Input(shape=(maxlen, embed_size), ) #x = Embedding(max_features, embed_size, weights=[embedding_matrix], # trainable=False)(inp) x = LSTM(recurrent_units, return_sequences=True, dropout=dropout_rate, recurrent_dropout=dropout_rate)(input_layer) #x = CuDNNLSTM(recurrent_units, return_sequences=True)(x) x = Dropout(dropout_rate)(x) x_a = GlobalMaxPool1D()(x) x_b = GlobalAveragePooling1D()(x) #x_c = AttentionWeightedAverage()(x) #x_a = MaxPooling1D(pool_size=2)(x) #x_b = AveragePooling1D(pool_size=2)(x) x = concatenate([x_a,x_b]) x = Dense(dense_size, activation="relu")(x) x = Dropout(dropout_rate)(x) x = Dense(nb_classes, activation="sigmoid")(x) model = Model(inputs=input_layer, outputs=x) model.summary() model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) return model# bidirectional LSTM
开发者ID:kermitt2,项目名称:delft,代码行数:29,代码来源:models.py
示例7: cnn3# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import GlobalMaxPool1D [as 别名]def cnn3(maxlen, embed_size, recurrent_units, dropout_rate, recurrent_dropout_rate, dense_size, nb_classes): #inp = Input(shape=(maxlen, )) input_layer = Input(shape=(maxlen, embed_size), ) #x = Embedding(max_features, embed_size, weights=[embedding_matrix], trainable=False)(inp) x = GRU(recurrent_units, return_sequences=True, dropout=dropout_rate, recurrent_dropout=dropout_rate)(input_layer) #x = Dropout(dropout_rate)(x) x = Conv1D(filters=recurrent_units, kernel_size=2, padding='same', activation='relu')(x) x = MaxPooling1D(pool_size=2)(x) x = Conv1D(filters=recurrent_units, kernel_size=2, padding='same', activation='relu')(x) x = MaxPooling1D(pool_size=2)(x) x = Conv1D(filters=recurrent_units, kernel_size=2, padding='same', activation='relu')(x) x = MaxPooling1D(pool_size=2)(x) x_a = GlobalMaxPool1D()(x) x_b = GlobalAveragePooling1D()(x) #x_c = AttentionWeightedAverage()(x) #x_a = MaxPooling1D(pool_size=2)(x) #x_b = AveragePooling1D(pool_size=2)(x) x = concatenate([x_a,x_b]) #x = Dropout(dropout_rate)(x) x = Dense(dense_size, activation="relu")(x) x = Dense(nb_classes, activation="sigmoid")(x) model = Model(inputs=input_layer, outputs=x) model.summary() model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) return model
开发者ID:kermitt2,项目名称:delft,代码行数:29,代码来源:models.py
示例8: gru_best# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import GlobalMaxPool1D [as 别名]def gru_best(maxlen, embed_size, recurrent_units, dropout_rate, recurrent_dropout_rate, dense_size, nb_classes): #input_layer = Input(shape=(maxlen,)) input_layer = Input(shape=(maxlen, embed_size), ) #embedding_layer = Embedding(max_features, embed_size, # weights=[embedding_matrix], trainable=False)(input_layer) x = Bidirectional(GRU(recurrent_units, return_sequences=True, dropout=dropout_rate, recurrent_dropout=dropout_rate))(input_layer) x = Dropout(dropout_rate)(x) x = Bidirectional(GRU(recurrent_units, return_sequences=True, dropout=dropout_rate, recurrent_dropout=dropout_rate))(x) #x = AttentionWeightedAverage(maxlen)(x) x_a = GlobalMaxPool1D()(x) x_b = GlobalAveragePooling1D()(x) #x_c = AttentionWeightedAverage()(x) #x_a = MaxPooling1D(pool_size=2)(x) #x_b = AveragePooling1D(pool_size=2)(x) x = concatenate([x_a,x_b], axis=1) #x = Dense(dense_size, activation="relu")(x) #x = Dropout(dropout_rate)(x) x = Dense(dense_size, activation="relu")(x) output_layer = Dense(nb_classes, activation="sigmoid")(x) model = Model(inputs=input_layer, outputs=output_layer) model.summary() model.compile(loss='binary_crossentropy', #optimizer=RMSprop(clipvalue=1, clipnorm=1), optimizer='adam', metrics=['accuracy']) return model# 1 layer bid GRU
开发者ID:kermitt2,项目名称:delft,代码行数:34,代码来源:models.py
示例9: gru_simple# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import GlobalMaxPool1D [as 别名]def gru_simple(maxlen, embed_size, recurrent_units, dropout_rate, recurrent_dropout_rate, dense_size, nb_classes): #input_layer = Input(shape=(maxlen,)) input_layer = Input(shape=(maxlen, embed_size), ) #embedding_layer = Embedding(max_features, embed_size, # weights=[embedding_matrix], trainable=False)(input_layer) x = Bidirectional(GRU(recurrent_units, return_sequences=True, dropout=dropout_rate, recurrent_dropout=dropout_rate))(input_layer) #x = AttentionWeightedAverage(maxlen)(x) x_a = GlobalMaxPool1D()(x) x_b = GlobalAveragePooling1D()(x) #x_c = AttentionWeightedAverage()(x) #x_a = MaxPooling1D(pool_size=2)(x) #x_b = AveragePooling1D(pool_size=2)(x) x = concatenate([x_a,x_b], axis=1) #x = Dense(dense_size, activation="relu")(x) #x = Dropout(dropout_rate)(x) x = Dense(dense_size, activation="relu")(x) output_layer = Dense(nb_classes, activation="sigmoid")(x) model = Model(inputs=input_layer, outputs=output_layer) model.summary() model.compile(loss='binary_crossentropy', optimizer=RMSprop(clipvalue=1, clipnorm=1), #optimizer='adam', metrics=['accuracy']) return model# bid GRU + bid LSTM
开发者ID:kermitt2,项目名称:delft,代码行数:31,代码来源:models.py
示例10: mix1# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import GlobalMaxPool1D [as 别名]def mix1(maxlen, embed_size, recurrent_units, dropout_rate, recurrent_dropout_rate, dense_size, nb_classes): #input_layer = Input(shape=(maxlen,)) input_layer = Input(shape=(maxlen, embed_size), ) #embedding_layer = Embedding(max_features, embed_size, # weights=[embedding_matrix], trainable=False)(input_layer) x = Bidirectional(GRU(recurrent_units, return_sequences=True, dropout=dropout_rate, recurrent_dropout=recurrent_dropout_rate))(input_layer) x = Dropout(dropout_rate)(x) x = Bidirectional(LSTM(recurrent_units, return_sequences=True, dropout=dropout_rate, recurrent_dropout=recurrent_dropout_rate))(x) x_a = GlobalMaxPool1D()(x) x_b = GlobalAveragePooling1D()(x) x = concatenate([x_a,x_b]) x = Dense(dense_size, activation="relu")(x) output_layer = Dense(nb_classes, activation="sigmoid")(x) model = Model(inputs=input_layer, outputs=output_layer) model.summary() model.compile(loss='binary_crossentropy', optimizer=RMSprop(clipvalue=1, clipnorm=1), #optimizer='adam', metrics=['accuracy']) return model# DPCNN
开发者ID:kermitt2,项目名称:delft,代码行数:30,代码来源:models.py
示例11: build_model_bilstm_attention# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import GlobalMaxPool1D [as 别名]def build_model_bilstm_attention(self): if args.use_lstm: if args.use_cudnn_cell: layer_cell = CuDNNLSTM else: layer_cell = LSTM else: if args.use_cudnn_cell: layer_cell = CuDNNGRU else: layer_cell = GRU # bert embedding bert_inputs, bert_output = KerasBertEmbedding().bert_encode() # Bi-LSTM x = Bidirectional(layer_cell(units=args.units, return_sequences=args.return_sequences, kernel_regularizer=regularizers.l2(args.l2 * 0.1), recurrent_regularizer=regularizers.l2(args.l2) ))(bert_output) x = TimeDistributed(Dropout(args.keep_prob))(x) # 这个用不了,好像是输入不对, dims<3吧 x = attention(x) x = Flatten()(x) x = Dropout(args.keep_prob)(x) # # 平均池化、最大池化拼接 # avg_pool = GlobalAvgPool1D()(x) # max_pool = GlobalMaxPool1D()(x) # print(max_pool.shape) # print(avg_pool.shape) # concat = concatenate([avg_pool, max_pool]) # x = Dense(int(args.units/4), activation="relu")(concat) # x = Dropout(args.keep_prob)(x) # 最后就是softmax dense_layer = Dense(args.label, activation=args.activation)(x) output_layers = [dense_layer] self.model = Model(bert_inputs, output_layers)
示例12: create# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import GlobalMaxPool1D [as 别名]def create(inputtokens, vocabsize, denseunits=8, densedrop=0.1, embedding=32): model = Sequential() # Embedding layer model.add(Embedding(input_dim=vocabsize, output_dim=embedding, input_length=inputtokens)) model.add(GlobalMaxPool1D()) # Hidden layer model.add(Dense(denseunits, activation='relu')) model.add(Dropout(densedrop)) # Output layer model.add(Dense(vocabsize, activation='softmax')) return model
开发者ID:albarji,项目名称:neurowriter,代码行数:14,代码来源:models.py
示例13: create_model# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import GlobalMaxPool1D [as 别名]def create_model(self): embedding_size = 100 self.model = Sequential() self.model.add(Embedding(input_dim=self.vocab_size, input_length=self.max_len, output_dim=embedding_size)) self.model.add(SpatialDropout1D(0.2)) self.model.add(Conv1D(filters=256, kernel_size=5, padding='same', activation='relu')) self.model.add(GlobalMaxPool1D()) self.model.add(Dense(units=len(self.labels), activation='softmax')) self.model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
开发者ID:chen0040,项目名称:keras-english-resume-parser-and-analyzer,代码行数:12,代码来源:cnn.py
示例14: RnnVersion2# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import GlobalMaxPool1D [as 别名]def RnnVersion2(n_recurrent=50, n_dense=50, word_embedding_matrix= None, n_filters=50,dropout_rate=0.2, l2_penalty=0.0001, n_capsule = 10, n_routings = 5, capsule_dim = 16,max_len = 170, emb_size = 21099): K.clear_session() def conv_block(x, n, kernel_size): x = Conv1D(n, kernel_size, activation='relu') (x) x = Conv1D(n_filters, kernel_size, activation='relu') (x) x_att = AttentionWithContext()(x) x_avg = GlobalAvgPool1D()(x) x_max = GlobalMaxPool1D()(x) return concatenate([x_att, x_avg, x_max]) def att_max_avg_pooling(x): x_att = AttentionWithContext()(x) x_avg = GlobalAvgPool1D()(x) x_max = GlobalMaxPool1D()(x) return concatenate([x_att, x_avg, x_max]) inputs = Input(shape=(max_len,)) emb = Embedding(emb_size, 300,trainable=True)(inputs) # model 0 x0 = SpatialDropout1D(dropout_rate)(emb) s0 = Bidirectional( CuDNNGRU(2*n_recurrent, return_sequences=True, kernel_regularizer=l2(l2_penalty), recurrent_regularizer=l2(l2_penalty)))(x0) x0 = att_max_avg_pooling(s0) # model 1 x1 = SpatialDropout1D(dropout_rate)(emb) s1 = Bidirectional( CuDNNGRU(2*n_recurrent, return_sequences=True, kernel_regularizer=l2(l2_penalty), recurrent_regularizer=l2(l2_penalty)))(x1) x1 = att_max_avg_pooling(s1) # combine sequence output x = concatenate([s0, s1])# x = att_max_avg_pooling(x) x = Bidirectional( CuDNNGRU(n_recurrent, return_sequences=True, kernel_regularizer=l2(l2_penalty), recurrent_regularizer=l2(l2_penalty)))(x) x = att_max_avg_pooling(x) # combine it all x = concatenate([x,x0, x1],name = 'concatenate') outputs = Dense(6, activation='softmax')(x) model = Model(inputs=inputs, outputs=outputs) model.compile(loss='categorical_crossentropy', optimizer='nadam',metrics =['accuracy']) return model
开发者ID:WeavingWong,项目名称:DigiX_HuaWei_Population_Age_Attribution_Predict,代码行数:56,代码来源:models.py
示例15: lstm_cnn# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import GlobalMaxPool1D [as 别名]def lstm_cnn(maxlen, embed_size, recurrent_units, dropout_rate, recurrent_dropout_rate, dense_size, nb_classes): #inp = Input(shape=(maxlen, )) input_layer = Input(shape=(maxlen, embed_size), ) #x = Embedding(max_features, embed_size, weights=[embedding_matrix], # trainable=False)(inp) x = LSTM(recurrent_units, return_sequences=True, dropout=dropout_rate, recurrent_dropout=dropout_rate)(input_layer) x = Dropout(dropout_rate)(x) x = Conv1D(filters=recurrent_units, kernel_size=2, padding='same', activation='relu')(x) x = Conv1D(filters=300, kernel_size=5, padding='valid', activation='tanh', strides=1)(x) #x = MaxPooling1D(pool_size=2)(x) #x = Conv1D(filters=300, # kernel_size=5, # padding='valid', # activation='tanh', # strides=1)(x) #x = MaxPooling1D(pool_size=2)(x) #x = Conv1D(filters=300, # kernel_size=3, # padding='valid', # activation='tanh', # strides=1)(x) x_a = GlobalMaxPool1D()(x) x_b = GlobalAveragePooling1D()(x) x = concatenate([x_a,x_b]) x = Dense(dense_size, activation="relu")(x) x = Dropout(dropout_rate)(x) x = Dense(nb_classes, activation="sigmoid")(x) model = Model(inputs=input_layer, outputs=x) model.summary() model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) return model# 2 bid. GRU
开发者ID:kermitt2,项目名称:delft,代码行数:48,代码来源:models.py
示例16: build_model_bilstm_layers# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import GlobalMaxPool1D [as 别名]def build_model_bilstm_layers(self): if args.use_lstm: if args.use_cudnn_cell: layer_cell = CuDNNLSTM else: layer_cell = LSTM else: if args.use_cudnn_cell: layer_cell = CuDNNGRU else: layer_cell = GRU # bert embedding bert_inputs, bert_output = KerasBertEmbedding().bert_encode() # bert_output = bert_output[:0:] # layer_get_cls = Lambda(lambda x: x[:, 0:1, :]) # bert_output = layer_get_cls(bert_output) # print("layer_get_cls:") # print(bert_output.shape) # Bi-LSTM x = Bidirectional(layer_cell(units=args.units, return_sequences=args.return_sequences, kernel_regularizer=regularizers.l2(args.l2 * 0.1), recurrent_regularizer=regularizers.l2(args.l2) ))(bert_output) # blstm_layer = TimeDistributed(Dropout(args.keep_prob))(blstm_layer) 这个用不了,好像是输入不对, dims<3吧 x = Dropout(args.keep_prob)(x) x = Bidirectional(layer_cell(units=args.units, return_sequences=args.return_sequences, kernel_regularizer=regularizers.l2(args.l2 * 0.1), recurrent_regularizer=regularizers.l2(args.l2)))(x) x = Dropout(args.keep_prob)(x) x = Bidirectional(layer_cell(units=args.units, return_sequences=args.return_sequences, kernel_regularizer=regularizers.l2(args.l2 * 0.1), recurrent_regularizer=regularizers.l2(args.l2)))(x) x = Dropout(args.keep_prob)(x) # 平均池化、最大池化拼接 avg_pool = GlobalAvgPool1D()(x) max_pool = GlobalMaxPool1D()(x) print(max_pool.shape) print(avg_pool.shape) concat = concatenate([avg_pool, max_pool]) x = Dense(int(args.units / 4), activation="relu")(concat) x = Dropout(args.keep_prob)(x) # 最后就是softmax dense_layer = Dense(args.label, activation=args.activation)(x) output_layers = [dense_layer] self.model = Model(bert_inputs, output_layers)
|