这篇教程Python layers.Dropout方法代码示例写得很实用,希望能帮到您。
本文整理汇总了Python中keras.layers.Dropout方法的典型用法代码示例。如果您正苦于以下问题:Python layers.Dropout方法的具体用法?Python layers.Dropout怎么用?Python layers.Dropout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块keras.layers 的用法示例。 在下文中一共展示了layers.Dropout方法的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。 示例1: _makenet# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def _makenet(x, num_layers, dropout, random_seed): from keras.layers import Dense, Dropout dropout_seeder = random.Random(random_seed) for i in range(num_layers - 1): # add intermediate layers if dropout: x = Dropout(dropout, seed=dropout_seeder.randint(0, 10000))(x) x = Dense(1024, activation="relu", name='dense_layer_{}'.format(i))(x) if dropout: # add the final dropout layer x = Dropout(dropout, seed=dropout_seeder.randint(0, 10000))(x) return x
示例2: RNNModel# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def RNNModel(vocab_size, max_len, rnnConfig, model_type): embedding_size = rnnConfig['embedding_size'] if model_type == 'inceptionv3': # InceptionV3 outputs a 2048 dimensional vector for each image, which we'll feed to RNN Model image_input = Input(shape=(2048,)) elif model_type == 'vgg16': # VGG16 outputs a 4096 dimensional vector for each image, which we'll feed to RNN Model image_input = Input(shape=(4096,)) image_model_1 = Dropout(rnnConfig['dropout'])(image_input) image_model = Dense(embedding_size, activation='relu')(image_model_1) caption_input = Input(shape=(max_len,)) # mask_zero: We zero pad inputs to the same length, the zero mask ignores those inputs. E.g. it is an efficiency. caption_model_1 = Embedding(vocab_size, embedding_size, mask_zero=True)(caption_input) caption_model_2 = Dropout(rnnConfig['dropout'])(caption_model_1) caption_model = LSTM(rnnConfig['LSTM_units'])(caption_model_2) # Merging the models and creating a softmax classifier final_model_1 = concatenate([image_model, caption_model]) final_model_2 = Dense(rnnConfig['dense_units'], activation='relu')(final_model_1) final_model = Dense(vocab_size, activation='softmax')(final_model_2) model = Model(inputs=[image_input, caption_input], outputs=final_model) model.compile(loss='categorical_crossentropy', optimizer='adam') return model
开发者ID:dabasajay,项目名称:Image-Caption-Generator,代码行数:27,代码来源:model.py
示例3: __init__# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def __init__(self, model_path=None): if model_path is not None: self.model = self.load_model(model_path) else: # VGG16 last conv features inputs = Input(shape=(7, 7, 512)) x = Convolution2D(128, 1, 1)(inputs) x = Flatten()(x) # Cls head h_cls = Dense(256, activation='relu', W_regularizer=l2(l=0.01))(x) h_cls = Dropout(p=0.5)(h_cls) cls_head = Dense(20, activation='softmax', name='cls')(h_cls) # Reg head h_reg = Dense(256, activation='relu', W_regularizer=l2(l=0.01))(x) h_reg = Dropout(p=0.5)(h_reg) reg_head = Dense(4, activation='linear', name='reg')(h_reg) # Joint model self.model = Model(input=inputs, output=[cls_head, reg_head])
示例4: build_discriminator# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def build_discriminator(self): z = Input(shape=(self.latent_dim, )) img = Input(shape=self.img_shape) d_in = concatenate([z, Flatten()(img)]) model = Dense(1024)(d_in) model = LeakyReLU(alpha=0.2)(model) model = Dropout(0.5)(model) model = Dense(1024)(model) model = LeakyReLU(alpha=0.2)(model) model = Dropout(0.5)(model) model = Dense(1024)(model) model = LeakyReLU(alpha=0.2)(model) model = Dropout(0.5)(model) validity = Dense(1, activation="sigmoid")(model) return Model([z, img], validity)
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:20,代码来源:bigan.py
示例5: build_generator# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def build_generator(self): X = Input(shape=(self.img_dim,)) model = Sequential() model.add(Dense(256, input_dim=self.img_dim)) model.add(LeakyReLU(alpha=0.2)) model.add(BatchNormalization(momentum=0.8)) model.add(Dropout(0.4)) model.add(Dense(512)) model.add(LeakyReLU(alpha=0.2)) model.add(BatchNormalization(momentum=0.8)) model.add(Dropout(0.4)) model.add(Dense(1024)) model.add(LeakyReLU(alpha=0.2)) model.add(BatchNormalization(momentum=0.8)) model.add(Dropout(0.4)) model.add(Dense(self.img_dim, activation='tanh')) X_translated = model(X) return Model(X, X_translated)
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:24,代码来源:dualgan.py
示例6: get_model_41# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def get_model_41(params): embedding_weights = pickle.load(open("../data/datasets/train_data/embedding_weights_w2v-google_MSD-AG.pk","rb")) # main sequential model model = Sequential() model.add(Embedding(len(embedding_weights[0]), params['embedding_dim'], input_length=params['sequence_length'], weights=embedding_weights)) #model.add(Dropout(params['dropout_prob'][0], input_shape=(params['sequence_length'], params['embedding_dim']))) model.add(LSTM(2048)) #model.add(Dropout(params['dropout_prob'][1])) model.add(Dense(output_dim=params["n_out"], init="uniform")) model.add(Activation(params['final_activation'])) logging.debug("Output CNN: %s" % str(model.output_shape)) if params['final_activation'] == 'linear': model.add(Lambda(lambda x :K.l2_normalize(x, axis=1))) return model# CRNN Arch for audio
开发者ID:sergiooramas,项目名称:tartarus,代码行数:22,代码来源:models.py
示例7: create_model# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def create_model(): inputs = Input(shape=(length,), dtype='int32', name='inputs') embedding_1 = Embedding(len(vocab), EMBED_DIM, input_length=length, mask_zero=True)(inputs) bilstm = Bidirectional(LSTM(EMBED_DIM // 2, return_sequences=True))(embedding_1) bilstm_dropout = Dropout(DROPOUT_RATE)(bilstm) embedding_2 = Embedding(len(vocab), EMBED_DIM, input_length=length)(inputs) con = Conv1D(filters=FILTERS, kernel_size=2 * HALF_WIN_SIZE + 1, padding='same')(embedding_2) con_d = Dropout(DROPOUT_RATE)(con) dense_con = TimeDistributed(Dense(DENSE_DIM))(con_d) rnn_cnn = concatenate([bilstm_dropout, dense_con], axis=2) dense = TimeDistributed(Dense(len(chunk_tags)))(rnn_cnn) crf = CRF(len(chunk_tags), sparse_target=True) crf_output = crf(dense) model = Model(input=[inputs], output=[crf_output]) model.compile(loss=crf.loss_function, optimizer=Adam(), metrics=[crf.accuracy]) return model
示例8: modelA# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def modelA(): model = Sequential() model.add(Conv2D(64, (5, 5), padding='valid')) model.add(Activation('relu')) model.add(Conv2D(64, (5, 5))) model.add(Activation('relu')) model.add(Dropout(0.25)) model.add(Flatten()) model.add(Dense(128)) model.add(Activation('relu')) model.add(Dropout(0.5)) model.add(Dense(FLAGS.NUM_CLASSES)) return model
开发者ID:sunblaze-ucb,项目名称:blackbox-attacks,代码行数:20,代码来源:mnist.py
示例9: modelB# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def modelB(): model = Sequential() model.add(Dropout(0.2, input_shape=(FLAGS.IMAGE_ROWS, FLAGS.IMAGE_COLS, FLAGS.NUM_CHANNELS))) model.add(Convolution2D(64, 8, 8, subsample=(2, 2), border_mode='same')) model.add(Activation('relu')) model.add(Convolution2D(128, 6, 6, subsample=(2, 2), border_mode='valid')) model.add(Activation('relu')) model.add(Convolution2D(128, 5, 5, subsample=(1, 1))) model.add(Activation('relu')) model.add(Dropout(0.5)) model.add(Flatten()) model.add(Dense(FLAGS.NUM_CLASSES)) return model
开发者ID:sunblaze-ucb,项目名称:blackbox-attacks,代码行数:26,代码来源:mnist.py
示例10: modelC# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def modelC(): model = Sequential() model.add(Convolution2D(128, 3, 3, border_mode='valid', input_shape=(FLAGS.IMAGE_ROWS, FLAGS.IMAGE_COLS, FLAGS.NUM_CHANNELS))) model.add(Activation('relu')) model.add(Convolution2D(64, 3, 3)) model.add(Activation('relu')) model.add(Dropout(0.25)) model.add(Flatten()) model.add(Dense(128)) model.add(Activation('relu')) model.add(Dropout(0.5)) model.add(Dense(FLAGS.NUM_CLASSES)) return model
开发者ID:sunblaze-ucb,项目名称:blackbox-attacks,代码行数:23,代码来源:mnist.py
示例11: modelD# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def modelD(): model = Sequential() model.add(Flatten(input_shape=(FLAGS.IMAGE_ROWS, FLAGS.IMAGE_COLS, FLAGS.NUM_CHANNELS))) model.add(Dense(300, init='he_normal', activation='relu')) model.add(Dropout(0.5)) model.add(Dense(300, init='he_normal', activation='relu')) model.add(Dropout(0.5)) model.add(Dense(300, init='he_normal', activation='relu')) model.add(Dropout(0.5)) model.add(Dense(300, init='he_normal', activation='relu')) model.add(Dropout(0.5)) model.add(Dense(FLAGS.NUM_CLASSES)) return model
开发者ID:sunblaze-ucb,项目名称:blackbox-attacks,代码行数:20,代码来源:mnist.py
示例12: ann_model# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def ann_model(input_shape): inp = Input(shape=input_shape, name='mfcc_in') model = inp model = Conv1D(filters=12, kernel_size=(3), activation='relu')(model) model = Conv1D(filters=12, kernel_size=(3), activation='relu')(model) model = Flatten()(model) model = Dense(56)(model) model = Activation('relu')(model) model = BatchNormalization()(model) model = Dropout(0.2)(model) model = Dense(28)(model) model = Activation('relu')(model) model = BatchNormalization()(model) model = Dense(1)(model) model = Activation('sigmoid')(model) model = Model(inp, model) return model
示例13: buildModel_DNN# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def buildModel_DNN(Shape, nClasses, nLayers=3,Number_Node=100, dropout=0.5): ''' buildModel_DNN(nFeatures, nClasses, nLayers=3,Numberof_NOde=100, dropout=0.5) Build Deep neural networks (Multi-layer perceptron) Model for text classification Shape is input feature space nClasses is number of classes nLayers is number of hidden Layer Number_Node is number of unit in each hidden layer dropout is dropout value for solving overfitting problem ''' model = Sequential() model.add(Dense(Number_Node, input_dim=Shape)) model.add(Dropout(dropout)) for i in range(0,nLayers): model.add(Dense(Number_Node, activation='relu')) model.add(Dropout(dropout)) model.add(Dense(nClasses, activation='softmax')) model.compile(loss='sparse_categorical_crossentropy', optimizer='RMSprop', metrics=['accuracy']) return model
示例14: weather_fnn# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def weather_fnn(layers, lr, decay, loss, seq_len, input_features, output_features): ori_inputs = Input(shape=(seq_len, input_features), name='input_layer') #print(seq_len*input_features) conv_ = Conv1D(11, kernel_size=13, strides=1, data_format='channels_last', padding='valid', activation='linear')(ori_inputs) conv_ = BatchNormalization(name='BN_conv')(conv_) conv_ = Activation('relu')(conv_) conv_ = Conv1D(5, kernel_size=7, strides=1, data_format='channels_last', padding='valid', activation='linear')(conv_) conv_ = BatchNormalization(name='BN_conv2')(conv_) conv_ = Activation('relu')(conv_) inputs = Reshape((-1,))(conv_) for i, hidden_nums in enumerate(layers): if i==0: hn = Dense(hidden_nums, activation='linear')(inputs) hn = BatchNormalization(name='BN_{}'.format(i))(hn) hn = Activation('relu')(hn) else: hn = Dense(hidden_nums, activation='linear')(hn) hn = BatchNormalization(name='BN_{}'.format(i))(hn) hn = Activation('relu')(hn) #hn = Dropout(0.1)(hn) #print(seq_len, output_features) #print(hn) outputs = Dense(seq_len*output_features, activation='sigmoid', name='output_layer')(hn) # 37*3 outputs = Reshape((seq_len, output_features))(outputs) weather_fnn = Model(ori_inputs, outputs=[outputs]) return weather_fnn
开发者ID:BruceBinBoxing,项目名称:Deep_Learning_Weather_Forecasting,代码行数:39,代码来源:weather_model.py
示例15: _get_model# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def _get_model(X, cat_cols, num_cols, n_uniq, n_emb, output_activation): inputs = [] num_inputs = [] embeddings = [] for i, col in enumerate(cat_cols): if not n_uniq[i]: n_uniq[i] = X[col].nunique() if not n_emb[i]: n_emb[i] = max(MIN_EMBEDDING, 2 * int(np.log2(n_uniq[i]))) _input = Input(shape=(1,), name=col) _embed = Embedding(input_dim=n_uniq[i], output_dim=n_emb[i], name=col + EMBEDDING_SUFFIX)(_input) _embed = Dropout(.2)(_embed) _embed = Reshape((n_emb[i],))(_embed) inputs.append(_input) embeddings.append(_embed) if num_cols: num_inputs = Input(shape=(len(num_cols),), name='num_inputs') merged_input = Concatenate(axis=1)(embeddings + [num_inputs]) inputs = inputs + [num_inputs] else: merged_input = Concatenate(axis=1)(embeddings) x = BatchNormalization()(merged_input) x = Dense(128, activation='relu')(x) x = Dropout(.5)(x) x = BatchNormalization()(x) x = Dense(64, activation='relu')(x) x = Dropout(.5)(x) x = BatchNormalization()(x) output = Dense(1, activation=output_activation)(x) model = Model(inputs=inputs, outputs=output) return model, n_emb, n_uniq
示例16: build_discriminator# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def build_discriminator(self): model = Sequential() model.add(Conv2D(32, kernel_size=3, strides=2, input_shape=self.img_shape, padding="same")) model.add(LeakyReLU(alpha=0.2)) model.add(Dropout(0.25)) model.add(Conv2D(64, kernel_size=3, strides=2, padding="same")) model.add(ZeroPadding2D(padding=((0,1),(0,1)))) model.add(LeakyReLU(alpha=0.2)) model.add(Dropout(0.25)) model.add(BatchNormalization(momentum=0.8)) model.add(Conv2D(128, kernel_size=3, strides=2, padding="same")) model.add(LeakyReLU(alpha=0.2)) model.add(Dropout(0.25)) model.add(BatchNormalization(momentum=0.8)) model.add(Conv2D(256, kernel_size=3, strides=1, padding="same")) model.add(LeakyReLU(alpha=0.2)) model.add(Dropout(0.25)) model.add(Flatten()) model.summary() img = Input(shape=self.img_shape) features = model(img) valid = Dense(1, activation="sigmoid")(features) label = Dense(self.num_classes+1, activation="softmax")(features) return Model(img, [valid, label])
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:32,代码来源:sgan.py
示例17: build_generator# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def build_generator(self): model = Sequential() # Encoder model.add(Conv2D(32, kernel_size=3, strides=2, input_shape=self.img_shape, padding="same")) model.add(LeakyReLU(alpha=0.2)) model.add(BatchNormalization(momentum=0.8)) model.add(Conv2D(64, kernel_size=3, strides=2, padding="same")) model.add(LeakyReLU(alpha=0.2)) model.add(BatchNormalization(momentum=0.8)) model.add(Conv2D(128, kernel_size=3, strides=2, padding="same")) model.add(LeakyReLU(alpha=0.2)) model.add(BatchNormalization(momentum=0.8)) model.add(Conv2D(512, kernel_size=1, strides=2, padding="same")) model.add(LeakyReLU(alpha=0.2)) model.add(Dropout(0.5)) # Decoder model.add(UpSampling2D()) model.add(Conv2D(128, kernel_size=3, padding="same")) model.add(Activation('relu')) model.add(BatchNormalization(momentum=0.8)) model.add(UpSampling2D()) model.add(Conv2D(64, kernel_size=3, padding="same")) model.add(Activation('relu')) model.add(BatchNormalization(momentum=0.8)) model.add(Conv2D(self.channels, kernel_size=3, padding="same")) model.add(Activation('tanh')) model.summary() masked_img = Input(shape=self.img_shape) gen_missing = model(masked_img) return Model(masked_img, gen_missing)
示例18: build_generator# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def build_generator(self): """U-Net Generator""" def conv2d(layer_input, filters, f_size=4, bn=True): """Layers used during downsampling""" d = Conv2D(filters, kernel_size=f_size, strides=2, padding='same')(layer_input) d = LeakyReLU(alpha=0.2)(d) if bn: d = BatchNormalization(momentum=0.8)(d) return d def deconv2d(layer_input, skip_input, filters, f_size=4, dropout_rate=0): """Layers used during upsampling""" u = UpSampling2D(size=2)(layer_input) u = Conv2D(filters, kernel_size=f_size, strides=1, padding='same', activation='relu')(u) if dropout_rate: u = Dropout(dropout_rate)(u) u = BatchNormalization(momentum=0.8)(u) u = Concatenate()([u, skip_input]) return u img = Input(shape=self.img_shape) # Downsampling d1 = conv2d(img, self.gf, bn=False) d2 = conv2d(d1, self.gf*2) d3 = conv2d(d2, self.gf*4) d4 = conv2d(d3, self.gf*8) # Upsampling u1 = deconv2d(d4, d3, self.gf*4) u2 = deconv2d(u1, d2, self.gf*2) u3 = deconv2d(u2, d1, self.gf) u4 = UpSampling2D(size=2)(u3) output_img = Conv2D(self.channels, kernel_size=4, strides=1, padding='same', activation='tanh')(u4) return Model(img, output_img)
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:40,代码来源:ccgan.py
示例19: build_disk_and_q_net# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def build_disk_and_q_net(self): img = Input(shape=self.img_shape) # Shared layers between discriminator and recognition network model = Sequential() model.add(Conv2D(64, kernel_size=3, strides=2, input_shape=self.img_shape, padding="same")) model.add(LeakyReLU(alpha=0.2)) model.add(Dropout(0.25)) model.add(Conv2D(128, kernel_size=3, strides=2, padding="same")) model.add(ZeroPadding2D(padding=((0,1),(0,1)))) model.add(LeakyReLU(alpha=0.2)) model.add(Dropout(0.25)) model.add(BatchNormalization(momentum=0.8)) model.add(Conv2D(256, kernel_size=3, strides=2, padding="same")) model.add(LeakyReLU(alpha=0.2)) model.add(Dropout(0.25)) model.add(BatchNormalization(momentum=0.8)) model.add(Conv2D(512, kernel_size=3, strides=2, padding="same")) model.add(LeakyReLU(alpha=0.2)) model.add(Dropout(0.25)) model.add(BatchNormalization(momentum=0.8)) model.add(Flatten()) img_embedding = model(img) # Discriminator validity = Dense(1, activation='sigmoid')(img_embedding) # Recognition q_net = Dense(128, activation='relu')(img_embedding) label = Dense(self.num_classes, activation='softmax')(q_net) # Return discriminator and recognition network return Model(img, validity), Model(img, label)
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:37,代码来源:infogan.py
示例20: build_critic# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def build_critic(self): model = Sequential() model.add(Conv2D(16, kernel_size=3, strides=2, input_shape=self.img_shape, padding="same")) model.add(LeakyReLU(alpha=0.2)) model.add(Dropout(0.25)) model.add(Conv2D(32, kernel_size=3, strides=2, padding="same")) model.add(ZeroPadding2D(padding=((0,1),(0,1)))) model.add(BatchNormalization(momentum=0.8)) model.add(LeakyReLU(alpha=0.2)) model.add(Dropout(0.25)) model.add(Conv2D(64, kernel_size=3, strides=2, padding="same")) model.add(BatchNormalization(momentum=0.8)) model.add(LeakyReLU(alpha=0.2)) model.add(Dropout(0.25)) model.add(Conv2D(128, kernel_size=3, strides=1, padding="same")) model.add(BatchNormalization(momentum=0.8)) model.add(LeakyReLU(alpha=0.2)) model.add(Dropout(0.25)) model.add(Flatten()) model.add(Dense(1)) model.summary() img = Input(shape=self.img_shape) validity = model(img) return Model(img, validity)
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:31,代码来源:wgan.py
示例21: build_generator# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def build_generator(self): """U-Net Generator""" def conv2d(layer_input, filters, f_size=4): """Layers used during downsampling""" d = Conv2D(filters, kernel_size=f_size, strides=2, padding='same')(layer_input) d = LeakyReLU(alpha=0.2)(d) d = InstanceNormalization()(d) return d def deconv2d(layer_input, skip_input, filters, f_size=4, dropout_rate=0): """Layers used during upsampling""" u = UpSampling2D(size=2)(layer_input) u = Conv2D(filters, kernel_size=f_size, strides=1, padding='same', activation='relu')(u) if dropout_rate: u = Dropout(dropout_rate)(u) u = InstanceNormalization()(u) u = Concatenate()([u, skip_input]) return u # Image input d0 = Input(shape=self.img_shape) # Downsampling d1 = conv2d(d0, self.gf) d2 = conv2d(d1, self.gf*2) d3 = conv2d(d2, self.gf*4) d4 = conv2d(d3, self.gf*8) # Upsampling u1 = deconv2d(d4, d3, self.gf*4) u2 = deconv2d(u1, d2, self.gf*2) u3 = deconv2d(u2, d1, self.gf) u4 = UpSampling2D(size=2)(u3) output_img = Conv2D(self.channels, kernel_size=4, strides=1, padding='same', activation='tanh')(u4) return Model(d0, output_img)
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:40,代码来源:cyclegan.py
示例22: build_discriminator# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def build_discriminator(self): model = Sequential() model.add(Conv2D(32, kernel_size=3, strides=2, input_shape=self.img_shape, padding="same")) model.add(LeakyReLU(alpha=0.2)) model.add(Dropout(0.25)) model.add(Conv2D(64, kernel_size=3, strides=2, padding="same")) model.add(ZeroPadding2D(padding=((0,1),(0,1)))) model.add(BatchNormalization(momentum=0.8)) model.add(LeakyReLU(alpha=0.2)) model.add(Dropout(0.25)) model.add(Conv2D(128, kernel_size=3, strides=2, padding="same")) model.add(BatchNormalization(momentum=0.8)) model.add(LeakyReLU(alpha=0.2)) model.add(Dropout(0.25)) model.add(Conv2D(256, kernel_size=3, strides=1, padding="same")) model.add(BatchNormalization(momentum=0.8)) model.add(LeakyReLU(alpha=0.2)) model.add(Dropout(0.25)) model.add(Flatten()) model.add(Dense(1, activation='sigmoid')) model.summary() img = Input(shape=self.img_shape) validity = model(img) return Model(img, validity)
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:31,代码来源:dcgan.py
示例23: get_model_3# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def get_model_3(params): # metadata inputs2 = Input(shape=(params["n_metafeatures"],)) x2 = Dropout(params["dropout_factor"])(inputs2) if params["n_dense"] > 0: dense2 = Dense(output_dim=params["n_dense"], init="uniform", activation='relu') x2 = dense2(x2) logging.debug("Output CNN: %s" % str(dense2.output_shape)) x2 = Dropout(params["dropout_factor"])(x2) if params["n_dense_2"] > 0: dense3 = Dense(output_dim=params["n_dense_2"], init="uniform", activation='relu') x2 = dense3(x2) logging.debug("Output CNN: %s" % str(dense3.output_shape)) x2 = Dropout(params["dropout_factor"])(x2) dense4 = Dense(output_dim=params["n_out"], init="uniform", activation=params['final_activation']) xout = dense4(x2) logging.debug("Output CNN: %s" % str(dense4.output_shape)) if params['final_activation'] == 'linear': reg = Lambda(lambda x :K.l2_normalize(x, axis=1)) xout = reg(xout) model = Model(input=inputs2, output=xout) return model# Metadata 2 inputs, post-merge with dense layers
开发者ID:sergiooramas,项目名称:tartarus,代码行数:36,代码来源:models.py
示例24: get_model_32# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def get_model_32(params): # metadata inputs = Input(shape=(params["n_metafeatures"],)) reg = Lambda(lambda x :K.l2_normalize(x, axis=1)) x1 = reg(inputs) inputs2 = Input(shape=(params["n_metafeatures2"],)) reg2 = Lambda(lambda x :K.l2_normalize(x, axis=1)) x2 = reg2(inputs2) # merge x = merge([x1, x2], mode='concat', concat_axis=1) x = Dropout(params["dropout_factor"])(x) if params['n_dense'] > 0: dense2 = Dense(output_dim=params["n_dense"], init="uniform", activation='relu') x = dense2(x) logging.debug("Output CNN: %s" % str(dense2.output_shape)) dense4 = Dense(output_dim=params["n_out"], init="uniform", activation=params['final_activation']) xout = dense4(x) logging.debug("Output CNN: %s" % str(dense4.output_shape)) if params['final_activation'] == 'linear': reg = Lambda(lambda x :K.l2_normalize(x, axis=1)) xout = reg(xout) model = Model(input=[inputs,inputs2], output=xout) return model# Metadata 3 inputs, pre-merge and l2
开发者ID:sergiooramas,项目名称:tartarus,代码行数:36,代码来源:models.py
示例25: get_model_33# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def get_model_33(params): # metadata inputs = Input(shape=(params["n_metafeatures"],)) reg = Lambda(lambda x :K.l2_normalize(x, axis=1)) x1 = reg(inputs) inputs2 = Input(shape=(params["n_metafeatures2"],)) reg2 = Lambda(lambda x :K.l2_normalize(x, axis=1)) x2 = reg2(inputs2) inputs3 = Input(shape=(params["n_metafeatures3"],)) reg3 = Lambda(lambda x :K.l2_normalize(x, axis=1)) x3 = reg3(inputs3) # merge x = merge([x1, x2, x3], mode='concat', concat_axis=1) x = Dropout(params["dropout_factor"])(x) if params['n_dense'] > 0: dense2 = Dense(output_dim=params["n_dense"], init="uniform", activation='relu') x = dense2(x) logging.debug("Output CNN: %s" % str(dense2.output_shape)) dense4 = Dense(output_dim=params["n_out"], init="uniform", activation=params['final_activation']) xout = dense4(x) logging.debug("Output CNN: %s" % str(dense4.output_shape)) if params['final_activation'] == 'linear': reg = Lambda(lambda x :K.l2_normalize(x, axis=1)) xout = reg(xout) model = Model(input=[inputs,inputs2,inputs3], output=xout) return model# Metadata 4 inputs, pre-merge and l2
开发者ID:sergiooramas,项目名称:tartarus,代码行数:41,代码来源:models.py
示例26: get_model_34# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def get_model_34(params): # metadata inputs = Input(shape=(params["n_metafeatures"],)) reg = Lambda(lambda x :K.l2_normalize(x, axis=1)) x1 = reg(inputs) inputs2 = Input(shape=(params["n_metafeatures2"],)) reg2 = Lambda(lambda x :K.l2_normalize(x, axis=1)) x2 = reg2(inputs2) inputs3 = Input(shape=(params["n_metafeatures3"],)) reg3 = Lambda(lambda x :K.l2_normalize(x, axis=1)) x3 = reg3(inputs3) inputs4 = Input(shape=(params["n_metafeatures4"],)) reg4 = Lambda(lambda x :K.l2_normalize(x, axis=1)) x4 = reg4(inputs4) # merge x = merge([x1, x2, x3, x4], mode='concat', concat_axis=1) x = Dropout(params["dropout_factor"])(x) if params['n_dense'] > 0: dense2 = Dense(output_dim=params["n_dense"], init="uniform", activation='relu') x = dense2(x) logging.debug("Output CNN: %s" % str(dense2.output_shape)) dense4 = Dense(output_dim=params["n_out"], init="uniform", activation=params['final_activation']) xout = dense4(x) logging.debug("Output CNN: %s" % str(dense4.output_shape)) if params['final_activation'] == 'linear': reg = Lambda(lambda x :K.l2_normalize(x, axis=1)) xout = reg(xout) model = Model(input=[inputs,inputs2,inputs3,inputs4], output=xout) return model
开发者ID:sergiooramas,项目名称:tartarus,代码行数:42,代码来源:models.py
示例27: get_model_6# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def get_model_6(params): # metadata inputs2 = Input(shape=(params["n_metafeatures"],)) #x2 = Dropout(params["dropout_factor"])(inputs2) if params["n_dense"] > 0: dense21 = Dense(output_dim=params["n_dense"], init="uniform", activation='relu') x21 = dense21(inputs2) logging.debug("Output CNN: %s" % str(dense21.output_shape)) dense22 = Dense(output_dim=params["n_dense"], init="uniform", activation='tanh') x22 = dense22(inputs2) logging.debug("Output CNN: %s" % str(dense22.output_shape)) dense23 = Dense(output_dim=params["n_dense"], init="uniform", activation='sigmoid') x23 = dense23(inputs2) logging.debug("Output CNN: %s" % str(dense23.output_shape)) # merge x = merge([x21, x22, x23], mode='concat', concat_axis=1) x2 = Dropout(params["dropout_factor"])(x) if params["n_dense_2"] > 0: dense3 = Dense(output_dim=params["n_dense_2"], init="uniform", activation='relu') x2 = dense3(x2) logging.debug("Output CNN: %s" % str(dense3.output_shape)) x2 = Dropout(params["dropout_factor"])(x2) dense4 = Dense(output_dim=params["n_out"], init="uniform", activation=params['final_activation']) xout = dense4(x2) logging.debug("Output CNN: %s" % str(dense4.output_shape)) if params['final_activation'] == 'linear': reg = Lambda(lambda x :K.l2_normalize(x, axis=1)) xout = reg(xout) model = Model(input=inputs2, output=xout) return model
开发者ID:sergiooramas,项目名称:tartarus,代码行数:43,代码来源:models.py
示例28: creat_model# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [as 别名]def creat_model(input_shape, num_class): init = initializers.Orthogonal(gain=args.norm) sequence_input =Input(shape=input_shape) mask = Masking(mask_value=0.)(sequence_input) if args.aug: mask = augmentaion()(mask) X = Noise(0.075)(mask) if args.model[0:2]=='VA': # VA trans = LSTM(args.nhid,recurrent_activation='sigmoid',return_sequences=True,implementation=2,recurrent_initializer=init)(X) trans = Dropout(0.5)(trans) trans = TimeDistributed(Dense(3,kernel_initializer='zeros'))(trans) rot = LSTM(args.nhid,recurrent_activation='sigmoid',return_sequences=True,implementation=2,recurrent_initializer=init)(X) rot = Dropout(0.5)(rot) rot = TimeDistributed(Dense(3,kernel_initializer='zeros'))(rot) transform = Concatenate()([rot,trans]) X = VA()([mask,transform]) X = LSTM(args.nhid,recurrent_activation='sigmoid',return_sequences=True,implementation=2,recurrent_initializer=init)(X) X = Dropout(0.5)(X) X = LSTM(args.nhid,recurrent_activation='sigmoid',return_sequences=True,implementation=2,recurrent_initializer=init)(X) X = Dropout(0.5)(X) X = LSTM(args.nhid,recurrent_activation='sigmoid',return_sequences=True,implementation=2,recurrent_initializer=init)(X) X = Dropout(0.5)(X) X = TimeDistributed(Dense(num_class))(X) X = MeanOverTime()(X) X = Activation('softmax')(X) model=Model(sequence_input,X) return model
开发者ID:microsoft,项目名称:View-Adaptive-Neural-Networks-for-Skeleton-based-Human-Action-Recognition,代码行数:33,代码来源:va-rnn.py
示例29: load_model# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import Dropout [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
|