{"id":16683394,"url":"https://github.com/ac-alpha/vaes-using-pytorch","last_synced_at":"2025-07-28T19:36:26.515Z","repository":{"id":69335018,"uuid":"169984627","full_name":"ac-alpha/VAEs-using-Pytorch","owner":"ac-alpha","description":"Variational Autoencoders trained on MNIST Dataset using PyTorch","archived":false,"fork":false,"pushed_at":"2019-02-10T21:08:59.000Z","size":15248,"stargazers_count":6,"open_issues_count":0,"forks_count":3,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-14T20:42:41.259Z","etag":null,"topics":["deep-learning","deep-neural-networks","pytorch","pytorch-cnn","pytorch-implmention","vae"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ac-alpha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-10T14:05:55.000Z","updated_at":"2024-12-12T17:05:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"a72eadac-72a4-4cc5-94a9-ae4ffcb1c4ae","html_url":"https://github.com/ac-alpha/VAEs-using-Pytorch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ac-alpha/VAEs-using-Pytorch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ac-alpha%2FVAEs-using-Pytorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ac-alpha%2FVAEs-using-Pytorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ac-alpha%2FVAEs-using-Pytorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ac-alpha%2FVAEs-using-Pytorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ac-alpha","download_url":"https://codeload.github.com/ac-alpha/VAEs-using-Pytorch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ac-alpha%2FVAEs-using-Pytorch/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261601483,"owners_count":23183093,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","deep-neural-networks","pytorch","pytorch-cnn","pytorch-implmention","vae"],"created_at":"2024-10-12T14:24:23.299Z","updated_at":"2025-06-24T04:06:52.355Z","avatar_url":"https://github.com/ac-alpha.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"images/digit_transition.png\" width=\"200\" /\u003e \u003cimg src=\"images/scatter_both.png\" width=\"250\" /\u003e\n\n# Variational Auto-Encoders using Pytorch\n\n` Variational Auto-Encoder Implementation trained on MNIST Dataset in Pytorch`\n\n## Introduction\n\nVariational AutoEncoders are a class of Generative Models which are used to deal with models of distributions `P(X)`, defined over datapoints X in some potentially high-dimensional space X. We get examples X distributed according to some unknown distribution `Pgt(X)`, and our goal is to learn a model P which we can sample from, such that `P` is as similar as possible to `Pgt`.\n\nFirst we map our original image X to a latent variable z using some distribution `Q(z|X)` . Then we pass that value of z to the distribution `P(X|z)` to get an image as close to original image X.\nBefore we can say that our model is representative of our dataset, we need to make sure that for every datapoint X in the dataset, there is one (or many) settings of the latent variables which causes the model to generate something very similar to X. \n\nWe wish to optimize parameters such that we can sample z from `P(z)` and, with high probability, `P(X|z)` will be like the X’s in our dataset. For most z, `P(X|z)` will be nearly zero, and hence contribute\nalmost nothing to our estimate of `P(X)`. The key idea behind the variational\nautoencoder is to attempt to sample values of z that are likely to have\nproduced X, and compute `P(X)` just from those.\n\nUsually the distribution Q(z|X) is taken to be gaussian. After taking everything into account,  the final loss function comes out to be a sum of KL Divergence of `Q(z|X)` and `P(z)`, i.e. `D(Q(z|X)||P(z))`; and cross entropy loss between original X and reconstructed X. For more details on this, see the [paper](https://arxiv.org/pdf/1312.6114) and [tutorial](https://arxiv.org/pdf/1606.05908)\n\n## Pipeline\n\n\u003cimg src=\"images/VAE_pipeline.png\" /\u003e\n\nThis image has been taken from this [tutorial](https://arxiv.org/pdf/1606.05908).\n\n## Dataset\n\nFor all the experiments, I have used the [MNIST dataset](http://yann.lecun.com/exdb/mnist/) loaded using the DataLoader present in pytorch only.\n\n## Code\n\nCode is well documented in the following files :-\n1. [VAE Vanilla](https://github.com/ac-alpha/VAEs-using-Pytorch/blob/readme/VAE.ipynb) - Simple VAE using **20 latent variables** trained on a **fully connected** network.\n2. [VAE_two_latent_variables](https://github.com/ac-alpha/VAEs-using-Pytorch/blob/readme/VAE_two_latent_variables.ipynb) - **Fully Connected** network with **only 2 latent variables**.\n3. [VAE_CNN](https://github.com/ac-alpha/VAEs-using-Pytorch/blob/readme/VAE_CNN.ipynb) - VAE using **Convolution Layers** .\n4. [VAE_without_KLD_Loss](https://github.com/ac-alpha/VAEs-using-Pytorch/blob/readme/VAE_without_KLD_Loss.ipynb) - VAE trained using only **Cross Entropy Loss** and **only 2 latent variables**.\n5. [VAE_without_Cross_Entropy_Loss](https://github.com/ac-alpha/VAEs-using-Pytorch/blob/readme/VAE_without_KLD_Loss.ipynb) - VAE trained using only **KL Divergence Loss** and **only 2 latent variables**.\n\n## Experiments and Visualisations :-\n\nExperiments 1-3 are available on [this notebook](https://github.com/ac-alpha/VAEs-using-Pytorch/blob/master/VAE.ipynb); 4-5 on [this notebook](https://github.com/ac-alpha/VAEs-using-Pytorch/blob/readme/VAE_two_latent_variables.ipynb); 6-7 on [this notebook](https://github.com/ac-alpha/VAEs-using-Pytorch/blob/readme/VAE_without_KLD_Loss.ipynb) and 8 on [this notebook](https://github.com/ac-alpha/VAEs-using-Pytorch/blob/readme/VAE_without_KLD_Loss.ipynb).\n\n1. When we sample epsilon values at regular intervals, make z from them using mu and sigma of some image, then the reconstructed images are all similar to the original image but having some minute differences.\n\u003cimg src=\"images/experiment_1.png\" width=\"300\"/\u003e\n\n2. When we change only one dimension of z, and then create samples, then they look very similar to the original image.\n\u003cimg src=\"images/experiment_2.png\" width=\"300\"/\u003e\n\n3. Taking a fixed value of epsilon, when we make 2 z values z1 and z2 (using mu and sigma of 2 different images) using that epsilon then the values in between them create samples which are mix of the 2 digits.\n\u003cimg src=\"images/four_to_nine.png\" width=\"300\"/\u003e\n\n4. In 2 latent variable model, when we sample z values at specific intervals and pass them into the decoder, then we can see the transition between the digits.\n\u003cimg src=\"images/digit_transition.png\" width=\"300\"/\u003e\n\n5. In 2 latent variable model, the scatter plot observed has the points belonging to one digit very close to that belonging to other digits and we can transition between them without sampling much of noise.\n\u003cimg src=\"images/scatter_both.png\" width=\"300\"/\u003e\n\n6. If we perform experiment similar to experiment 1 in the VAE_without_KLD_Loss model, then the reconstructed images look similar and are actually having same value.\n\n7. In the VAE_without_KLD_Loss model, the scatter plot contains blobs of different digits seperated by random noise.\n\u003cimg src=\"images/scatter_ce.png\" width=\"300\"/\u003e\n\n8. In the VAE_without_Cross_Entropy_Loss model, the scatter plot contains blobs of different digits randomly mixed together but they tend to be closer to each other.\n\u003cimg src=\"images/scatter_kld.png\" width=\"300\"/\u003e\n\n9. As we increase the number of latent variables, we get more number of z's which produce noise upon passing through the decoder network.\n\n## Contributing\n\nSuggestions to the repository are more than welcome. To open a pull request, [click here](https://github.com/ac-alpha/VAEs-using-Pytorch/pulls). No specific naming criteria of variables is necessary as long as the name is explanatory.\n\n## License\n\nSee [License](https://github.com/ac-alpha/VAEs-using-Pytorch/blob/readme/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fac-alpha%2Fvaes-using-pytorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fac-alpha%2Fvaes-using-pytorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fac-alpha%2Fvaes-using-pytorch/lists"}