Created
May 16, 2019 09:32
-
-
Save AFAgarap/4b541e0bbb96ae1e42126c4b46097c41 to your computer and use it in GitHub Desktop.
TensorFlow 2.0 implementation of a sampling layer for a variational autoencoder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Sampling(tf.keras.layers.Layer): | |
def call(self, args): | |
z_mean, z_log_var = args | |
batch = tf.shape(z_mean)[0] | |
dim = tf.shape(z_mean)[1] | |
epsilon = tf.random.normal(shape=(batch, dim), mean=0., stddev=1.) | |
return z_mean + epsilon * tf.exp(0.5 * z_log_var) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment