{"id":17296109,"url":"https://github.com/cdoersch/vae_tutorial","last_synced_at":"2025-04-06T03:07:48.876Z","repository":{"id":44761122,"uuid":"61499288","full_name":"cdoersch/vae_tutorial","owner":"cdoersch","description":"Caffe code to accompany my Tutorial on Variational Autoencoders","archived":false,"fork":false,"pushed_at":"2016-12-22T15:58:28.000Z","size":1039,"stargazers_count":508,"open_issues_count":2,"forks_count":135,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-03-30T02:05:26.544Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","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/cdoersch.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}},"created_at":"2016-06-19T20:37:00.000Z","updated_at":"2025-03-29T16:04:28.000Z","dependencies_parsed_at":"2022-09-07T20:32:56.124Z","dependency_job_id":null,"html_url":"https://github.com/cdoersch/vae_tutorial","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdoersch%2Fvae_tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdoersch%2Fvae_tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdoersch%2Fvae_tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdoersch%2Fvae_tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cdoersch","download_url":"https://codeload.github.com/cdoersch/vae_tutorial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247427006,"owners_count":20937201,"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":[],"created_at":"2024-10-15T11:12:01.124Z","updated_at":"2025-04-06T03:07:48.852Z","avatar_url":"https://github.com/cdoersch.png","language":"Python","funding_links":[],"categories":["\u003ca name=\"Vision\"\u003e\u003c/a\u003e2. Vision"],"sub_categories":[],"readme":"# Tutorial on Variational Autoencoders\n### Introduction\n\nThis code is a supplement to the [Tutorial on Variational Autoencoders](http://arxiv.org/abs/1606.05908).  It allows you to reproduce the example experiments in the tutorial's later sections.\n\nThis code contains two demos.  The first is a standard Variational Autoencoder (VAE) for MNIST.  The second is a Conditional Variational Autoencoder (CVAE) for reconstructing a digit given only a noisy, binarized column of pixels from the digit's center.  For details on the experimental setup, see the paper.\n\nNo additional Caffe layers are needed to make a VAE/CVAE work in Caffe.  The only requirements are a working Caffe/pycaffe installation.  A GPU will make the experiments run faster, but is not necessary (comment out set_mode_gpu() in the python files if you don't have one).  On my system (a Titan X), these experiments all complete in about 10 minutes.\n\n### VAE and CVAE Network Structure\n  The code will generate a network drawing, but for convenience I've included the result of that drawing here.  This is for the VAE:\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd colspan=2 \u003e\u003cp align=\"center\"\u003eVAE\u003c/p\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cp align=\"center\"\u003eTrain Net\u003c/p\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cp align=\"center\"\u003eTest Net\u003c/p\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cp align=\"center\"\u003e\u003ca href=\"https://raw.githubusercontent.com/cdoersch/vae_tutorial/master/net_drawings/vae_train_net.png\"\u003e\u003cimg style=\"height:300px\" src=\"https://raw.githubusercontent.com/cdoersch/vae_tutorial/master/net_drawings/vae_train_net.png\" height=300 /\u003e\u003c/a\u003e\u003c/p\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cp align=\"center\"\u003e\u003ca href=\"https://raw.githubusercontent.com/cdoersch/vae_tutorial/master/net_drawings/vae_test_net.png\"\u003e\u003cimg style=\"height:300px\" src=\"https://raw.githubusercontent.com/cdoersch/vae_tutorial/master/net_drawings/vae_test_net.png\" height=300 /\u003e\u003c/a\u003e\u003c/p\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nHere is a side-by-side comparison between the CVAE and regressor which solve the same problem.  Note that both networks have several initial layers for constructing the input and output data that's used to train the network.\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd colspan=4 \u003e\u003cp align=\"center\"\u003eCVAE and Regressor\u003c/p\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cp align=\"center\"\u003eCVAE Train Net\u003c/p\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cp align=\"center\"\u003eCVAE Test Net\u003c/p\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cp align=\"center\"\u003eRegressor Train Net\u003c/p\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cp align=\"center\"\u003eRegressor Test Net\u003c/p\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd style=\"text-align:center\"\u003e\u003cp align=\"center\"\u003e\u003ca href=\"https://raw.githubusercontent.com/cdoersch/vae_tutorial/master/net_drawings/cvae_train_net.png\"\u003e\u003cimg style=\"height:300px\" src=\"https://raw.githubusercontent.com/cdoersch/vae_tutorial/master/net_drawings/cvae_train_net.png\" height=300 /\u003e\u003c/a\u003e\u003c/p\u003e\u003c/td\u003e\n    \u003ctd style=\"text-align:center\"\u003e\u003cp align=\"center\"\u003e\u003ca href=\"https://raw.githubusercontent.com/cdoersch/vae_tutorial/master/net_drawings/cvae_test_net.png\"\u003e\u003cimg style=\"height:300px\" src=\"https://raw.githubusercontent.com/cdoersch/vae_tutorial/master/net_drawings/cvae_test_net.png\" height=300 /\u003e\u003c/a\u003e\u003c/p\u003e\u003c/td\u003e\n    \u003ctd style=\"text-align:center\"\u003e\u003cp align=\"center\"\u003e\u003ca href=\"https://raw.githubusercontent.com/cdoersch/vae_tutorial/master/net_drawings/regressor_train_net.png\"\u003e\u003cimg style=\"height:300px\" src=\"https://raw.githubusercontent.com/cdoersch/vae_tutorial/master/net_drawings/regressor_train_net.png\" height=300 /\u003e\u003c/a\u003e\u003c/p\u003e\u003c/td\u003e\n    \u003ctd style=\"text-align:center\"\u003e\u003cp align=\"center\"\u003e\u003ca href=\"https://raw.githubusercontent.com/cdoersch/vae_tutorial/master/net_drawings/regressor_test_net.png\"\u003e\u003cimg style=\"height:300px\" src=\"https://raw.githubusercontent.com/cdoersch/vae_tutorial/master/net_drawings/regressor_test_net.png\" height=300 /\u003e\u003c/a\u003e\u003c/p\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n### Setup\n  1. Install Caffe (see: [Caffe installation instructions](http://caffe.berkeleyvision.org/installation.html)).  Build `Caffe` and `pycaffe`.  For this readme, we'll call the installation path $CAFFE_PATH.\n\n  2. Clone this repo.  For this readme, we'll call the installation path $TUTORIAL_PATH\n  ```Shell\n  git clone https://github.com/cdoersch/vae_tutorial.git\n  ```\n\n  3. Download MNIST using Caffe's pre-packaged downloader, and run create_mnist.sh to create an lmdb.\n  ```Shell\n    cd $CAFFE_PATH/data/mnist/\n    ./get_mnist.sh\n    cd $CAFFE_PATH/\n    ./examples/mnist/create_mnist.sh\n  ```\n\n  4. Optional: create a symlink for snapshots.  \n  ```Shell\n    cd $TUTORIAL_PATH\n    ln -s [...] snapshots\n  ```\n\n### Running the VAE\n  1. Edit mnist_vae.prototxt and enter the correct \"source\" path to the training lmdb (line 13)\n\n  2. Run the code.  Make sure $CAFFE_PATH/python is on your PYTHONPATH.\n\n  ```Shell\n    cd $TUTORIAL_PATH\n    python mnist_vae.py\n  ```\n\n  Note that the python is only required for generating the visualizations: the net can also be trained simply by calling\n  ```Shell\n    $CAFFE_PATH/build/tools/caffe train --solver=mnist_vae_solver_adam.prototxt\n  ```\n\n### Running the CVAE\n  1. Edit mnist_cvae.prototxt and enter the correct \"source\" path for BOTH training and testing lmdb's (line 13 AND 29)\n\n  2. Run the code.  Make sure $CAFFE_PATH/python is on your PYTHONPATH.\n\n  ```Shell\n    cd $TUTORIAL_PATH\n    python mnist_cvae.py\n  ```\n\n  Note that the python is only required for generating the visualizations: the net can also be trained simply by calling\n  ```Shell\n    $CAFFE_PATH/build/tools/caffe train --solver=mnist_cvae_solver_adam.prototxt\n  ```\n\n  3. Optional: do the same thing for the regressor to see the baseline results.  After altering the \"source\" paths in mnist_regressor.prototxt, run:\n  ```Shell\n    cd $TUTORIAL_PATH\n    python mnist_regressor.py\n  ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdoersch%2Fvae_tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcdoersch%2Fvae_tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdoersch%2Fvae_tutorial/lists"}