{"id":26911394,"url":"https://github.com/kimrass/vae","last_synced_at":"2025-04-01T14:38:10.651Z","repository":{"id":214356706,"uuid":"736311493","full_name":"KimRass/VAE","owner":"KimRass","description":"Training 'VAE' (Kingma and Welling, 2014) on MNIST from scratch in PyTorch","archived":false,"fork":false,"pushed_at":"2024-01-24T05:11:45.000Z","size":38509,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-01-24T07:27:25.586Z","etag":null,"topics":["genrative-ai","mnist","vae"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KimRass.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-12-27T15:02:47.000Z","updated_at":"2024-01-18T12:52:11.000Z","dependencies_parsed_at":"2023-12-29T17:21:10.785Z","dependency_job_id":"34e2911f-15d5-43c8-9813-df2db04978ec","html_url":"https://github.com/KimRass/VAE","commit_stats":null,"previous_names":["kimrass/vae"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KimRass%2FVAE","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KimRass%2FVAE/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KimRass%2FVAE/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KimRass%2FVAE/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KimRass","download_url":"https://codeload.github.com/KimRass/VAE/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246656921,"owners_count":20812913,"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":["genrative-ai","mnist","vae"],"created_at":"2025-04-01T14:38:10.152Z","updated_at":"2025-04-01T14:38:10.641Z","avatar_url":"https://github.com/KimRass.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 1. Pre-trained Parameters\n- Trained on MNIST for 84 epochs ([vae_mnist.pth](https://drive.google.com/file/d/1RLy035sMe-Wn1bgB9A60nmCc_tZbK3t7/view?usp=sharing))\n    - `seed=888, recon_weight=600, lr=0.0005, batch_size=64`\n    - `val_recon_loss=0.1085, val_kld_loss=7.3032`\n\n# 2. Visualization\n## 1) Encoder Output\n```bash\n# e.g.,\npython3 vis/encoder_output/main.py\\\n    --seed=888\\ # Optional\n    --batch_size=64\\ # Optional\n    --taget=\"mean\"\\ # Or `\"std\"`\n    --model_params=\"/.../datasets/vae/vae_mnist.pth\"\\\n    --data_dir=\"/.../datasets\"\\\n    --save_dir=\"/.../workspace/VAE/vis/encoder_output\"\n```\n- Mean and STD of MNIST Test Set\n    - \u003cimg src=\"https://github.com/KimRass/KimRass/assets/67457712/d375b8c2-71ae-488a-b46e-7e1c8897ba9c\" width=\"600\"\u003e\n    - 평균의 경우 4와 9, 3과 5가 많이 겹쳐 있습니다.\n    - 표준편차의 경우 1에 가까워지도록 학습이 이루어졌으나 0에 가까운 값을 띄고 있습니다. 시각화를 통해 얻을 수 있는 인사이트는 크게 없는 것으로 보입니다.\n## 2) Decoder Output\n```bash\npython3 vis/decoder_output/main.py\\\n    --seed=888\\ # Optional\n    --latent_min=-4\\ # Optional\n    --latent_max=-4\\ # Optional\n    --n_cells=32\\ # Optional\n    --model_params=\"/.../datasets/vae/vae_mnist.pth\"\\\n    --data_dir=\"/.../datasets\"\\\n    --save_dir=\"/.../workspace/VAE/vis/encoder_output\"\n```\n- `latent_min=-4, latent_max=4, n_cells=32`\n    - \u003cimg src=\"https://github.com/KimRass/KimRass/assets/67457712/8f28fa49-24a9-4916-b9a7-960feda9b7d4\" width=\"600\"\u003e\n    - Encoder output의 평균의 분포와 매우 유사함을 볼 수 있습니다.\n## 3) Image Reconstruction\n```bash\npython3 vis/reconstruct/main.py\\\n    --seed=888\\ # Optional\n    --batch_size=128\\ # Optional\n    --model_params=\"/.../datasets/vae/vae_mnist.pth\"\\\n    --data_dir=\"/.../datasets\"\\\n    --save_dir=\"/.../workspace/VAE/vis/encoder_output\"\n```\n- MNIST Test Set\n    - \u003cimg src=\"https://github.com/KimRass/KimRass/assets/67457712/c08037a5-de9e-411a-81f4-6921b07fd402\" width=\"800\"\u003e\n\n# 3. Theoretical Background\n## 1) Bayes' Theorem [3]\n$$P(A \\vert B) = \\frac{P(B \\vert A)P(A)}{P(B)}$$\n- $P(A \\vert B)$ is a conditional probability or posterior probability of $A$ given $B$.\n- $P(A)$ and $P(B)$ are known as the prior probability and marginal probability.\n$$P(A \\vert B) = \\frac{P(B \\vert A)P(A)}{P(B)}, \\text{ if } P(B) \\neq 0$$\n## 2) ELBO (Evidence Lower BOund)\n$$\\int q_{\\phi}(z \\vert x)dz = 1$$\n$$\n\\begin{align}\n\\ln(P(x))\n\u0026= \\int \\ln(P(x))q_{\\phi}(z \\vert x)dz\\\\\n\u0026= \\int \\ln \\bigg(\\frac{P(z, x)}{P(z \\vert x)}\\bigg)q_{\\phi}(z \\vert x)dz\\\\\n\u0026= \\int \\ln \\bigg(\\frac{P(z, x)}{q_{\\phi}(z \\vert x)}\\frac{q_{\\phi}(z \\vert x)}{P(z \\vert x)}\\bigg)q_{\\phi}(z \\vert x)dz\\\\\n\u0026= \\int \\ln \\bigg(\\frac{P(z, x)}{q_{\\phi}(z \\vert x)}\\bigg)q_{\\phi}(z \\vert x)dz + \\int \\ln \\bigg(\\frac{q_{\\phi}(z \\vert x)}{P(z \\vert x)}\\bigg)q_{\\phi}(z \\vert x)dz\\\\\n\\end{align}\n$$\n- A basic result in variational inference is that latent_minimizing the KL-divergence is equivalent to latent_maximizing the log-likelihood [2].\n$$\n\\begin{align}\n\\text{ELBO}\n\u0026= \\int \\ln \\bigg(\\frac{P(z, x)}{q_{\\phi}(z \\vert x)}\\bigg)q_{\\phi}(z \\vert x)dz\\\\\n\u0026= \\int \\ln \\bigg(\\frac{P(x \\vert z)P(z)}{q_{\\phi}(z \\vert x)}\\bigg)q_{\\phi}(z \\vert x)dz\\\\\n\u0026= \\int \\ln \\big(P(x \\vert z)\\big)q_{\\phi}(z \\vert x)dz + \\int \\ln \\bigg(\\frac{P(z)}{q_{\\phi}(z \\vert x)}\\bigg)q_{\\phi}(z \\vert x)dz\\\\\n\\end{align}\n$$\n\u003c!-- ## 왜 reparametrization trick?\n## KLD loss 공식 유도\n## 논문 읽기, Monte Carlo, 왜 샘플링 한 번만? --\u003e\n\n# 4. References\n- [1] [Auto Encoding Variational Bayes](https://github.com/KimRass/VAE/blob/main/papers/auto_encoding_variational_bayes.pdf)\n- [2] [Evidence lower bound](https://en.wikipedia.org/wiki/Evidence_lower_bound)\n- [3] [Bayes' theorem](https://en.wikipedia.org/wiki/Bayes%27_theorem)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkimrass%2Fvae","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkimrass%2Fvae","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkimrass%2Fvae/lists"}