Skip to content

Instantly share code, notes, and snippets.

@AFAgarap
Created May 16, 2019 09:32
Show Gist options
  • Save AFAgarap/4b541e0bbb96ae1e42126c4b46097c41 to your computer and use it in GitHub Desktop.
Save AFAgarap/4b541e0bbb96ae1e42126c4b46097c41 to your computer and use it in GitHub Desktop.
TensorFlow 2.0 implementation of a sampling layer for a variational autoencoder.
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