Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def build_generator(latent_size):
- # we will map a pair of (z, L), where z is a latent vector and L is a
- # label drawn from P_c, to image space (..., 28, 28, 1)
- cnn = Sequential()
- cnn.add(Dense(3 * 3 * 384, input_dim=latent_size, activation='relu'))
- cnn.add(Reshape((3, 3, 384)))
- # upsample to (7, 7, ...)
- cnn.add(Conv2DTranspose(192, 5, strides=1, padding='valid',
- activation='relu',
- kernel_initializer='glorot_normal'))
- cnn.add(BatchNormalization())
- # upsample to (14, 14, ...)
- cnn.add(Conv2DTranspose(96, 5, strides=2, padding='same',
- activation='relu',
- kernel_initializer='glorot_normal'))
- cnn.add(BatchNormalization())
- # upsample to (28, 28, ...)
- cnn.add(Conv2DTranspose(1, 5, strides=2, padding='same',
- activation='tanh',
- kernel_initializer='glorot_normal'))
- # this is the z space commonly referred to in GAN papers
- latent = Input(shape=(latent_size, ))
- # this will be our label
- image_class = Input(shape=(1,), dtype='int32')
- cls = Flatten()(Embedding(num_classes, latent_size,
- embeddings_initializer='glorot_normal')(image_class))
- # hadamard product between z-space and a class conditional embedding
- h = layers.multiply([latent, cls])
- fake_image = cnn(h)
- return Model([latent, image_class], fake_image)
Add Comment
Please, Sign In to add comment