Guest User

Untitled

a guest
Jun 24th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. def build_generator(latent_size):
  2. # we will map a pair of (z, L), where z is a latent vector and L is a
  3. # label drawn from P_c, to image space (..., 28, 28, 1)
  4. cnn = Sequential()
  5.  
  6. cnn.add(Dense(3 * 3 * 384, input_dim=latent_size, activation='relu'))
  7. cnn.add(Reshape((3, 3, 384)))
  8.  
  9. # upsample to (7, 7, ...)
  10. cnn.add(Conv2DTranspose(192, 5, strides=1, padding='valid',
  11. activation='relu',
  12. kernel_initializer='glorot_normal'))
  13. cnn.add(BatchNormalization())
  14.  
  15. # upsample to (14, 14, ...)
  16. cnn.add(Conv2DTranspose(96, 5, strides=2, padding='same',
  17. activation='relu',
  18. kernel_initializer='glorot_normal'))
  19. cnn.add(BatchNormalization())
  20.  
  21. # upsample to (28, 28, ...)
  22. cnn.add(Conv2DTranspose(1, 5, strides=2, padding='same',
  23. activation='tanh',
  24. kernel_initializer='glorot_normal'))
  25.  
  26. # this is the z space commonly referred to in GAN papers
  27. latent = Input(shape=(latent_size, ))
  28.  
  29. # this will be our label
  30. image_class = Input(shape=(1,), dtype='int32')
  31.  
  32. cls = Flatten()(Embedding(num_classes, latent_size,
  33. embeddings_initializer='glorot_normal')(image_class))
  34.  
  35. # hadamard product between z-space and a class conditional embedding
  36. h = layers.multiply([latent, cls])
  37.  
  38. fake_image = cnn(h)
  39.  
  40. return Model([latent, image_class], fake_image)
Add Comment
Please, Sign In to add comment