这篇教程Python layers.BatchNormalization方法代码示例写得很实用,希望能帮到您。
本文整理汇总了Python中keras.layers.BatchNormalization方法的典型用法代码示例。如果您正苦于以下问题:Python layers.BatchNormalization方法的具体用法?Python layers.BatchNormalization怎么用?Python layers.BatchNormalization使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块keras.layers 的用法示例。 在下文中一共展示了layers.BatchNormalization方法的26个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。 示例1: CausalCNN# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [as 别名]def CausalCNN(n_filters, lr, decay, loss, seq_len, input_features, strides_len, kernel_size, dilation_rates): inputs = Input(shape=(seq_len, input_features), name='input_layer') x=inputs for dilation_rate in dilation_rates: x = Conv1D(filters=n_filters, kernel_size=kernel_size, padding='causal', dilation_rate=dilation_rate, activation='linear')(x) x = BatchNormalization()(x) x = Activation('relu')(x) #x = Dense(7, activation='relu', name='dense_layer')(x) outputs = Dense(3, activation='sigmoid', name='output_layer')(x) causalcnn = Model(inputs, outputs=[outputs]) return causalcnn
开发者ID:BruceBinBoxing,项目名称:Deep_Learning_Weather_Forecasting,代码行数:23,代码来源:weather_model.py
示例2: build_generator# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [as 别名]def build_generator(self): model = Sequential() model.add(Dense(128 * 7 * 7, activation="relu", input_dim=self.latent_dim)) model.add(Reshape((7, 7, 128))) model.add(BatchNormalization(momentum=0.8)) 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(1, kernel_size=3, padding="same")) model.add(Activation("tanh")) model.summary() noise = Input(shape=(self.latent_dim,)) img = model(noise) return Model(noise, img)
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:26,代码来源:sgan.py
示例3: build_discriminator# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [as 别名]def build_discriminator(self): model = Sequential() model.add(Conv2D(64, kernel_size=3, strides=2, input_shape=self.missing_shape, 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(256, kernel_size=3, padding="same")) model.add(LeakyReLU(alpha=0.2)) model.add(BatchNormalization(momentum=0.8)) model.add(Flatten()) model.add(Dense(1, activation='sigmoid')) model.summary() img = Input(shape=self.missing_shape) validity = model(img) return Model(img, validity)
示例4: build_generator# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [as 别名]def build_generator(self): model = Sequential() model.add(Dense(512, input_dim=self.latent_dim)) model.add(LeakyReLU(alpha=0.2)) model.add(BatchNormalization(momentum=0.8)) model.add(Dense(512)) model.add(LeakyReLU(alpha=0.2)) model.add(BatchNormalization(momentum=0.8)) model.add(Dense(np.prod(self.img_shape), activation='tanh')) model.add(Reshape(self.img_shape)) model.summary() z = Input(shape=(self.latent_dim,)) gen_img = model(z) return Model(z, gen_img)
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:20,代码来源:bigan.py
示例5: build_generator# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [as 别名]def build_generator(self): model = Sequential() model.add(Dense(128 * 7 * 7, activation="relu", input_dim=self.latent_dim)) model.add(Reshape((7, 7, 128))) model.add(UpSampling2D()) model.add(Conv2D(128, kernel_size=4, padding="same")) model.add(BatchNormalization(momentum=0.8)) model.add(Activation("relu")) model.add(UpSampling2D()) model.add(Conv2D(64, kernel_size=4, padding="same")) model.add(BatchNormalization(momentum=0.8)) model.add(Activation("relu")) model.add(Conv2D(self.channels, kernel_size=4, padding="same")) model.add(Activation("tanh")) model.summary() noise = Input(shape=(self.latent_dim,)) img = model(noise) return Model(noise, img)
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:25,代码来源:wgan.py
示例6: build_discriminator# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [as 别名]def build_discriminator(self): def d_layer(layer_input, filters, f_size=4, bn=True): """Discriminator layer""" 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 img_A = Input(shape=self.img_shape) img_B = Input(shape=self.img_shape) # Concatenate image and conditioning image by channels to produce input combined_imgs = Concatenate(axis=-1)([img_A, img_B]) d1 = d_layer(combined_imgs, self.df, bn=False) d2 = d_layer(d1, self.df*2) d3 = d_layer(d2, self.df*4) d4 = d_layer(d3, self.df*8) validity = Conv2D(1, kernel_size=4, strides=1, padding='same')(d4) return Model([img_A, img_B], validity)
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:26,代码来源:pix2pix.py
示例7: build_generator# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [as 别名]def build_generator(self): model = Sequential() model.add(Dense(256, input_dim=self.latent_dim)) model.add(LeakyReLU(alpha=0.2)) model.add(BatchNormalization(momentum=0.8)) model.add(Dense(512)) model.add(LeakyReLU(alpha=0.2)) model.add(BatchNormalization(momentum=0.8)) model.add(Dense(1024)) model.add(LeakyReLU(alpha=0.2)) model.add(BatchNormalization(momentum=0.8)) model.add(Dense(np.prod(self.img_shape), activation='tanh')) model.add(Reshape(self.img_shape)) model.summary() noise = Input(shape=(self.latent_dim,)) img = model(noise) return Model(noise, img)
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:24,代码来源:lsgan.py
示例8: build_generator# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [as 别名]def build_generator(self): model = Sequential() model.add(Dense(128 * 7 * 7, activation="relu", input_dim=self.latent_dim)) model.add(Reshape((7, 7, 128))) model.add(UpSampling2D()) model.add(Conv2D(128, kernel_size=3, padding="same")) model.add(BatchNormalization(momentum=0.8)) model.add(Activation("relu")) model.add(UpSampling2D()) model.add(Conv2D(64, kernel_size=3, padding="same")) model.add(BatchNormalization(momentum=0.8)) model.add(Activation("relu")) model.add(Conv2D(self.channels, kernel_size=3, padding="same")) model.add(Activation("tanh")) model.summary() noise = Input(shape=(self.latent_dim,)) img = model(noise) return Model(noise, img)
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:25,代码来源:dcgan.py
示例9: _initial_conv_block_inception# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [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
示例10: weather_conv1D# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [as 别名]def weather_conv1D(layers, lr, decay, loss, input_len, input_features, strides_len, kernel_size): inputs = Input(shape=(input_len, input_features), name='input_layer') for i, hidden_nums in enumerate(layers): if i==0: #inputs = BatchNormalization(name='BN_input')(inputs) hn = Conv1D(hidden_nums, kernel_size=kernel_size, strides=strides_len, data_format='channels_last', padding='same', activation='linear')(inputs) hn = BatchNormalization(name='BN_{}'.format(i))(hn) hn = Activation('relu')(hn) elif i<len(layers)-1: hn = Conv1D(hidden_nums, kernel_size=kernel_size, strides=strides_len, data_format='channels_last', padding='same',activation='linear')(hn) hn = BatchNormalization(name='BN_{}'.format(i))(hn) hn = Activation('relu')(hn) else: hn = Conv1D(hidden_nums, kernel_size=kernel_size, strides=strides_len, data_format='channels_last', padding='same',activation='linear')(hn) hn = BatchNormalization(name='BN_{}'.format(i))(hn) outputs = Dense(80, activation='relu', name='dense_layer')(hn) outputs = Dense(3, activation='tanh', name='output_layer')(outputs) weather_model = Model(inputs, outputs=[outputs]) return weather_model
开发者ID:BruceBinBoxing,项目名称:Deep_Learning_Weather_Forecasting,代码行数:33,代码来源:weather_model.py
示例11: weather_fnn# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [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
示例12: _get_model# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [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
示例13: ss_bt# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [as 别名]def ss_bt(self, x, dilation, strides=(1, 1), padding='same'): x1, x2 = self.channel_split(x) filters = (int(x.shape[-1]) // self.groups) x1 = layers.Conv2D(filters, kernel_size=(3, 1), strides=strides, padding=padding)(x1) x1 = layers.Activation('relu')(x1) x1 = layers.Conv2D(filters, kernel_size=(1, 3), strides=strides, padding=padding)(x1) x1 = layers.BatchNormalization()(x1) x1 = layers.Activation('relu')(x1) x1 = layers.Conv2D(filters, kernel_size=(3, 1), strides=strides, padding=padding, dilation_rate=(dilation, 1))( x1) x1 = layers.Activation('relu')(x1) x1 = layers.Conv2D(filters, kernel_size=(1, 3), strides=strides, padding=padding, dilation_rate=(1, dilation))( x1) x1 = layers.BatchNormalization()(x1) x1 = layers.Activation('relu')(x1) x2 = layers.Conv2D(filters, kernel_size=(1, 3), strides=strides, padding=padding)(x2) x2 = layers.Activation('relu')(x2) x2 = layers.Conv2D(filters, kernel_size=(3, 1), strides=strides, padding=padding)(x2) x2 = layers.BatchNormalization()(x2) x2 = layers.Activation('relu')(x2) x2 = layers.Conv2D(filters, kernel_size=(1, 3), strides=strides, padding=padding, dilation_rate=(1, dilation))( x2) x2 = layers.Activation('relu')(x2) x2 = layers.Conv2D(filters, kernel_size=(3, 1), strides=strides, padding=padding, dilation_rate=(dilation, 1))( x2) x2 = layers.BatchNormalization()(x2) x2 = layers.Activation('relu')(x2) x_concat = layers.concatenate([x1, x2], axis=-1) x_add = layers.add([x, x_concat]) output = self.channel_shuffle(x_add) return output
开发者ID:JACKYLUO1991,项目名称:Face-skin-hair-segmentaiton-and-skin-color-evaluation,代码行数:34,代码来源:lednet.py
示例14: down_sample# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [as 别名]def down_sample(self, x, filters): x_filters = int(x.shape[-1]) x_conv = layers.Conv2D(filters - x_filters, kernel_size=3, strides=(2, 2), padding='same')(x) x_pool = layers.MaxPool2D()(x) x = layers.concatenate([x_conv, x_pool], axis=-1) x = layers.BatchNormalization()(x) x = layers.Activation('relu')(x) return x
开发者ID:JACKYLUO1991,项目名称:Face-skin-hair-segmentaiton-and-skin-color-evaluation,代码行数:10,代码来源:lednet.py
示例15: apn_module# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [as 别名]def apn_module(self, x): def right(x): x = layers.AveragePooling2D()(x) x = layers.Conv2D(self.classes, kernel_size=1, padding='same')(x) x = layers.BatchNormalization()(x) x = layers.Activation('relu')(x) x = layers.UpSampling2D(interpolation='bilinear')(x) return x def conv(x, filters, kernel_size, stride): x = layers.Conv2D(filters, kernel_size=kernel_size, strides=(stride, stride), padding='same')(x) x = layers.BatchNormalization()(x) x = layers.Activation('relu')(x) return x x_7 = conv(x, int(x.shape[-1]), 7, stride=2) x_5 = conv(x_7, int(x.shape[-1]), 5, stride=2) x_3 = conv(x_5, int(x.shape[-1]), 3, stride=2) x_3_1 = conv(x_3, self.classes, 3, stride=1) x_3_1_up = layers.UpSampling2D(interpolation='bilinear')(x_3_1) x_5_1 = conv(x_5, self.classes, 5, stride=1) x_3_5 = layers.add([x_5_1, x_3_1_up]) x_3_5_up = layers.UpSampling2D(interpolation='bilinear')(x_3_5) x_7_1 = conv(x_7, self.classes, 3, stride=1) x_3_5_7 = layers.add([x_7_1, x_3_5_up]) x_3_5_7_up = layers.UpSampling2D(interpolation='bilinear')(x_3_5_7) x_middle = conv(x, self.classes, 1, stride=1) x_middle = layers.multiply([x_3_5_7_up, x_middle]) x_right = right(x) x_middle = layers.add([x_middle, x_right]) return x_middle
开发者ID:JACKYLUO1991,项目名称:Face-skin-hair-segmentaiton-and-skin-color-evaluation,代码行数:37,代码来源:lednet.py
示例16: decoder# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [as 别名]def decoder(self, x): x = self.apn_module(x) x = layers.UpSampling2D(size=8, interpolation='bilinear')(x) x = layers.Conv2D(self.classes, kernel_size=3, padding='same')(x) x = layers.BatchNormalization()(x) x = layers.Activation('softmax')(x) return x
开发者ID:JACKYLUO1991,项目名称:Face-skin-hair-segmentaiton-and-skin-color-evaluation,代码行数:9,代码来源:lednet.py
示例17: conv2d_bn# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [as 别名]def conv2d_bn(x, filters, kernel_size, strides=1, padding='same', activation='relu', use_bias=False, name=None): """Utility function to apply conv + BN. # Arguments x: input tensor. filters: filters in `Conv2D`. kernel_size: kernel size as in `Conv2D`. padding: padding mode in `Conv2D`. activation: activation in `Conv2D`. strides: strides in `Conv2D`. name: name of the ops; will become `name + '_ac'` for the activation and `name + '_bn'` for the batch norm layer. # Returns Output tensor after applying `Conv2D` and `BatchNormalization`. """ x = Conv2D(filters, kernel_size, strides=strides, padding=padding, use_bias=use_bias, name=name)(x) if not use_bias: bn_axis = 1 if K.image_data_format() == 'channels_first' else 3 bn_name = None if name is None else name + '_bn' x = BatchNormalization(axis=bn_axis, scale=False, name=bn_name)(x) if activation is not None: ac_name = None if name is None else name + '_ac' x = Activation(activation, name=ac_name)(x) return x
示例18: identity_block# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [as 别名]def identity_block(input_tensor, kernel_size, filters, stage, block): """The identity block is the block that has no conv layer at shortcut. # Arguments input_tensor: input tensor kernel_size: default 3, the kernel size of middle conv layer at main path filters: list of integers, the filters of 3 conv layer at main path stage: integer, current stage label, used for generating layer names block: 'a','b'keras.., current block label, used for generating layer names # Returns Output tensor for the block. """ filters1, filters2, filters3 = filters if K.image_data_format() == 'channels_last': bn_axis = 3 else: bn_axis = 1 conv_name_base = 'res' + str(stage) + block + '_branch' bn_name_base = 'bn' + str(stage) + block + '_branch' x = Conv2D(filters1, (1, 1), name=conv_name_base + '2a')(input_tensor) x = BatchNormalization(axis=bn_axis, name=bn_name_base + '2a')(x) x = Activation('relu')(x) x = Conv2D(filters2, kernel_size, padding='same', name=conv_name_base + '2b')(x) x = BatchNormalization(axis=bn_axis, name=bn_name_base + '2b')(x) x = Activation('relu')(x) x = Conv2D(filters3, (1, 1), name=conv_name_base + '2c')(x) x = BatchNormalization(axis=bn_axis, name=bn_name_base + '2c')(x) x = layers.add([x, input_tensor]) x = Activation('relu')(x) return x
示例19: build_discriminator# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [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
示例20: build_generator# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [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)
示例21: build_generator# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [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
示例22: build_discriminator# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [as 别名]def build_discriminator(self): def d_block(layer_input, filters, strides=1, bn=True): """Discriminator layer""" d = Conv2D(filters, kernel_size=3, strides=strides, padding='same')(layer_input) d = LeakyReLU(alpha=0.2)(d) if bn: d = BatchNormalization(momentum=0.8)(d) return d # Input img d0 = Input(shape=self.hr_shape) d1 = d_block(d0, self.df, bn=False) d2 = d_block(d1, self.df, strides=2) d3 = d_block(d2, self.df*2) d4 = d_block(d3, self.df*2, strides=2) d5 = d_block(d4, self.df*4) d6 = d_block(d5, self.df*4, strides=2) d7 = d_block(d6, self.df*8) d8 = d_block(d7, self.df*8, strides=2) d9 = Dense(self.df*16)(d8) d10 = LeakyReLU(alpha=0.2)(d9) validity = Dense(1, activation='sigmoid')(d10) return Model(d0, validity)
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:29,代码来源:srgan.py
示例23: build_generator# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [as 别名]def build_generator(self): model = Sequential() model.add(Dense(256, input_dim=self.latent_dim)) model.add(LeakyReLU(alpha=0.2)) model.add(BatchNormalization(momentum=0.8)) model.add(Dense(512)) model.add(LeakyReLU(alpha=0.2)) model.add(BatchNormalization(momentum=0.8)) model.add(Dense(1024)) model.add(LeakyReLU(alpha=0.2)) model.add(BatchNormalization(momentum=0.8)) model.add(Dense(np.prod(self.img_shape), activation='tanh')) model.add(Reshape(self.img_shape)) model.summary() noise = Input(shape=(self.latent_dim,)) label = Input(shape=(1,), dtype='int32') label_embedding = Flatten()(Embedding(self.num_classes, self.latent_dim)(label)) model_input = multiply([noise, label_embedding]) img = model(model_input) return Model([noise, label], img)
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:28,代码来源:cgan.py
示例24: build_generator# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [as 别名]def build_generator(self): """Resnet Generator""" def residual_block(layer_input): """Residual block described in paper""" d = Conv2D(64, kernel_size=3, strides=1, padding='same')(layer_input) d = BatchNormalization(momentum=0.8)(d) d = Activation('relu')(d) d = Conv2D(64, kernel_size=3, strides=1, padding='same')(d) d = BatchNormalization(momentum=0.8)(d) d = Add()([d, layer_input]) return d # Image input img = Input(shape=self.img_shape) l1 = Conv2D(64, kernel_size=3, padding='same', activation='relu')(img) # Propogate signal through residual blocks r = residual_block(l1) for _ in range(self.residual_blocks - 1): r = residual_block(r) output_img = Conv2D(self.channels, kernel_size=3, padding='same', activation='tanh')(r) return Model(img, output_img)
开发者ID:eriklindernoren,项目名称:Keras-GAN,代码行数:28,代码来源:pixelda.py
示例25: build_disk_and_q_net# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [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
示例26: build_critic# 需要导入模块: from keras import layers [as 别名]# 或者: from keras.layers import BatchNormalization [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
|