Reparameterization trick by sampling from an isotropic unit Gaussian. # Arguments: args (tensor): mean and log of variance of Q(z|X) # Returns: z (tensor): sampled latent vector
(args)
| 13 | latent_dim = 6 |
| 14 | |
| 15 | def sampling(args): |
| 16 | """Reparameterization trick by sampling from an isotropic unit Gaussian. |
| 17 | # Arguments: |
| 18 | args (tensor): mean and log of variance of Q(z|X) |
| 19 | # Returns: |
| 20 | z (tensor): sampled latent vector |
| 21 | """ |
| 22 | z_mean, z_log_var = args |
| 23 | batch = K.shape(z_mean)[0] |
| 24 | dim = K.int_shape(z_mean)[1] |
| 25 | epsilon = K.random_normal(shape=(batch, dim)) |
| 26 | return z_mean + K.exp(0.5 * z_log_var) * epsilon |
| 27 | |
| 28 | def build_model(): |
| 29 | """Builds/compiles the model and returns (encoder, decoder, vae).""" |
nothing calls this directly
no outgoing calls
no test coverage detected