Generating new data

After the VAE model is trained, we can chop off its decoder part and use this as a generator to generate new data for us. It will work by feeding it new latent vectors that come from a unit Gaussian distribution.

We present in TensorFlow the code responsible for build this generating VAE graph as follows:

class VAE_CNN_GEN(object): 
   def __init__(self, img_size=28, latent_size=20): 
       self.__x = tf.placeholder(tf.float32, shape=[None, latent_size], name='LATENT_IN') 
       with tf.name_scope('DECODER'): 
           # Linear layer 
           self.__z_develop = tf.layers.dense(inputs=self.__x, 
                                              units=7 * 7 * 32, activation=None, name="z_matrix") 
           self.__z_develop_act = tf.nn.relu(tf.reshape(self.__z_develop, [tf.shape(self.__x)[0], 7, 7, 32])) 
 
           # DECONV1 
           self.__conv_t2_out_act = tf.layers.conv2d_transpose(inputs=self.__z_develop_act, 
                                                               strides=(2, 2), kernel_size=[5, 5], filters=16, 
                                                               padding="same", activation=tf.nn.relu) 
 
           # DECONV2 
           # Model output 
           self.__y = tf.layers.conv2d_transpose(inputs=self.__conv_t2_out_act, 
                                                 strides=(2, 2), kernel_size=[5, 5], filters=1, 
                                                 padding="same", activation=tf.nn.sigmoid) 
 
   @property 
   def output(self): 
       return self.__y 
 
   @property 
   def input(self): 
       return self.__x 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.190.211