I am trying to implement a variational autoencoder using python and tensorflow. I have seen various implementations on the internet. I have managed to create my own using the various parts that I found and made them work with my specific case. I have concluded with an autoencoder here: my autoncoder on git
Briefly I have an autoencoder that contains:
1) an encoder with 2 convolutional layers and 1 flatten layer,
2) the latent space ( of dimension 2),
3) and a decoder with the reverse parts of the encoder.
My problem is when I try to implement the variational part of the autoencoder. By that I mean the math procedure in the latent space. Atleast that is where I pinpoint the problem.
To be more clear I have the following 2 cases:
Case 1: Without actually implementing any variational maths, just simply set the variables in the latent space and feed them in the decoder with no math applied.In that case the cost function is just the difference between input and output. You can see the code for that case in these figures on the git(sorry cannot post more links): figure1_code_part1.png, figure1_code_part2.png
Case2: Trying to implement the maths in the latent space variables. You can see the code for that case in these figures: figure_2_code_part1.png, figure_2_code_part2.png
The plot of the latent space I get in each of the cases is: figure_1.png figure_2.png
I think something is clearly wrong with the variational implementation, but I can't figure out what. Everyone who implements variational auto encoder uses these mathematic formulas (at least the ones I found on the internet). Probably I am missing something.
Any comments/suggestions are welcome. Thanks!!!