Conditional VAE (Variational Auto Encoder) 条件付きVAE

Version 1.1 (4.81 MB) by Kenta
This example shows how to create a conditional variational autoencoder (VAE) in MATLAB to generate digit images. 条件付き変分オートエンコーダによる手書き数字生成


Updated 16 Apr 2020

View License

This example shows how to create a conditional variational autoencoder (VAE) in MATLAB to generate digit images. The VAE generates hand-drawn digits in the style of the MNIST data set. The difference from Variational Auto Encoder (VAE) is that conditional VAE can input the class label to generate, which enables to synthesize clearer images. A conditional GAN (Generative Adversarial Network) is also a variable to synthesize images. Synthesized images from VAE tend to be blurred since loss value becomes lower with such images. Using the GANs, the problem might be solved.

The conditional VAE in this demo was inspired by Kingma et al [1]. This live script was made based on the Matlab official document [2].
[1] Kingma, D. P., Mohamed, S., Rezende, D. J., & Welling, M. (2014). Semi-supervised learning with deep generative models. In Advances in neural information processing systems (pp. 3581-3589).
[2] Train Variational Autoencoder (VAE) to Generate Images (;jsessionid=e6dfca3f40831afcce0ff7b71670)
[3] 山下隆義、イラストで学ぶ ディープラーニング 改訂第2版、KS情報科学専門書、2018年 (amazon)
[4] 巣籠 悠輔, 詳説ディープラーニング: 生成モデル編 Kindle版 (amazon)
[5] LeCun, Y., C. Cortes, and C. J. C. Burges. "The MNIST Database of Handwritten Digits."
[6] van der Maaten, Laurens, and Geoffrey Hinton. Visualizing Data using t-SNE. J. Machine Learning Research 9, 2008, pp. 2579–2605.
[7] Federico Errica, "Step-By-Step Derivation of SNE and t-SNE gradients"'StepByStep+Derivation+of+SNE+and+tSNE+gradients'
The illustrations in this script were obtained from the website below.
[8] かわいいフリーイラスト集 いらすとや
[9] Dr Stephen Odaibo: Variational Inference & Derivation of the Variational Autoencoder (VAE) Loss Function: A True Story
[10] 高校数学の美しい物語:対数和不等式の証明と応用

Cite As

Kenta (2023). Conditional VAE (Variational Auto Encoder) 条件付きVAE (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2020a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

Explanation added


supplementary file added