Пример #1
0
def model_generator():
    model = Sequential()
    nch = 256
    reg = lambda: l1l2(l1=1e-7, l2=1e-7)
    h = 5
    model.add(Dense(nch * 4 * 4, input_dim=100, W_regularizer=reg()))
    model.add(BatchNormalization(mode=0))
    model.add(Reshape(dim_ordering_shape((nch, 4, 4))))
    model.add(
        Convolution2D(nch / 2, h, h, border_mode='same', W_regularizer=reg()))
    model.add(BatchNormalization(mode=0, axis=1))
    model.add(LeakyReLU(0.2))
    model.add(UpSampling2D(size=(2, 2)))
    model.add(
        Convolution2D(nch / 2, h, h, border_mode='same', W_regularizer=reg()))
    model.add(BatchNormalization(mode=0, axis=1))
    model.add(LeakyReLU(0.2))
    model.add(UpSampling2D(size=(2, 2)))
    model.add(
        Convolution2D(nch / 4, h, h, border_mode='same', W_regularizer=reg()))
    model.add(BatchNormalization(mode=0, axis=1))
    model.add(LeakyReLU(0.2))
    model.add(UpSampling2D(size=(2, 2)))
    model.add(Convolution2D(3, h, h, border_mode='same', W_regularizer=reg()))
    model.add(Activation('sigmoid'))
    return model
Пример #2
0
def model_generator(latent_dim,
                    units=512,
                    dropout=0.5,
                    reg=lambda: l1l2(l1=1e-7, l2=1e-7)):
    model = Sequential(name="decoder")
    h = 5
    model.add(Dense(units * 4 * 4, input_dim=latent_dim, W_regularizer=reg()))
    model.add(BatchNormalization(mode=0))
    model.add(Reshape(dim_ordering_shape((units, 4, 4))))
    model.add(
        Convolution2D(units / 2, h, h, border_mode='same',
                      W_regularizer=reg()))
    model.add(BatchNormalization(mode=0, axis=1))
    model.add(LeakyReLU(0.2))
    model.add(UpSampling2D(size=(2, 2)))
    model.add(
        Convolution2D(units / 2, h, h, border_mode='same',
                      W_regularizer=reg()))
    model.add(BatchNormalization(mode=0, axis=1))
    model.add(LeakyReLU(0.2))
    model.add(UpSampling2D(size=(2, 2)))
    model.add(
        Convolution2D(units / 4, h, h, border_mode='same',
                      W_regularizer=reg()))
    model.add(BatchNormalization(mode=0, axis=1))
    model.add(LeakyReLU(0.2))
    model.add(UpSampling2D(size=(2, 2)))
    model.add(Convolution2D(3, h, h, border_mode='same', W_regularizer=reg()))
    model.add(Activation('sigmoid'))
    return model
Пример #3
0
def model_generator():
    nch = 256
    reg = lambda: l1l2(l1=1e-7, l2=1e-7)
    h = 5

    input_z = Input(shape=(latent_dim, ))
    input_label = Input(shape=(1, ))

    input_label_embedding = Flatten()(
        Embedding(nb_labels,
                  latent_dim,
                  embeddings_initializer='glorot_normal')(input_label))

    H = layers.multiply([input_z, input_label_embedding])
    H = Dense(nch * 4 * 4, W_regularizer=reg())(H)
    H = BatchNormalization(mode=0)(H)
    H = Reshape(dim_ordering_shape((nch, 4, 4)))(H)
    H = Convolution2D(int(nch / 2),
                      h,
                      h,
                      border_mode='same',
                      W_regularizer=reg())(H)
    H = BatchNormalization(mode=0, axis=1)(H)
    H = LeakyReLU(0.2)(H)
    H = (UpSampling2D(size=(2, 2)))(H)
    H = (Convolution2D(int(nch / 2),
                       h,
                       h,
                       border_mode='same',
                       W_regularizer=reg()))(H)
    H = (BatchNormalization(mode=0, axis=1))(H)
    H = (LeakyReLU(0.2))(H)
    H = (UpSampling2D(size=(2, 2)))(H)
    H = (Convolution2D(int(nch / 2),
                       h,
                       h,
                       border_mode='same',
                       W_regularizer=reg()))(H)
    H = (BatchNormalization(mode=0, axis=1))(H)
    H = (LeakyReLU(0.2))(H)
    H = (UpSampling2D(size=(2, 2)))(H)
    H = (Convolution2D(int(nch / 4),
                       h,
                       h,
                       border_mode='same',
                       W_regularizer=reg()))(H)
    H = (BatchNormalization(mode=0, axis=1))(H)
    H = (LeakyReLU(0.2))(H)
    H = (UpSampling2D(size=(2, 2)))(H)
    H = (Convolution2D(3, h, h, border_mode='same', W_regularizer=reg()))(H)
    H = (Activation('sigmoid'))(H)
    return Model(inputs=[input_z, input_label], outputs=H)
Пример #4
0
def model_generator():
    nch = 256
    g_input = Input(shape=[100])
    H = Dense(nch * 14 * 14)(g_input)
    H = BatchNormalization(mode=2)(H)
    H = Activation('relu')(H)
    H = dim_ordering_reshape(nch, 14)(H)
    H = UpSampling2D(size=(2, 2))(H)
    H = Convolution2D(int(nch / 2), 3, 3, border_mode='same')(H)
    H = BatchNormalization(mode=2, axis=1)(H)
    H = Activation('relu')(H)
    H = Convolution2D(int(nch / 4), 3, 3, border_mode='same')(H)
    H = BatchNormalization(mode=2, axis=1)(H)
    H = Activation('relu')(H)
    H = Convolution2D(1, 1, 1, border_mode='same')(H)
    g_V = Activation('sigmoid')(H)
    return Model(g_input, g_V)