Towards visually explaining variational autoencoders

Octavia Camps, WenQian Liu, Runze Li, Meng Zheng, Ziyan Wu, Richard Radke, Bir Bhanu, Srikrishna Karanam

Abstract

Variational Autoencoders (VAEs) are powerful generative models but often lack interpretability. This paper introduces a gradient-based visual attention mechanism for VAEs, allowing for the visualization of latent dimensions and improved performance in anomaly localization and representation disentanglement.

1. Introduction

While supervised learning benefits from interpretability tools like Grad-CAM, generative models like VAEs have largely remained black boxes. Interpreting what specific latent dimensions represent or identifying the precise location of anomalies in reconstructed images is challenging. This work bridges this gap by porting visual attention to the unsupervised domain.

2. Methodology

The authors propose a gradient-based attention mechanism that operates without a classification layer. This approach allows for the generation of heatmaps that explain the influence of specific input regions on the latent representation.

  • VAE Attention Generation: To explain a latent dimension $z_i$, the gradient of its activation is backpropagated to the final convolutional feature map. Global Average Pooling (GAP) and a ReLU activation are then applied to produce a heatmap highlighting the input pixels most influential to that dimension.
  • Anomaly Localization: By comparing the latent distribution of a test image against the learned "normal" distribution, the model generates attention maps that highlight regions contributing to high reconstruction error or statistical deviation.
  • Attention Disentanglement Loss ($L_{AD}$): A novel loss function is introduced to penalize spatial overlap between attention maps of different latent dimensions, encouraging the model to learn more distinct and interpretable features.

3. Experimental Setup

The approach was evaluated on several diverse benchmarks:

  • MNIST: Used for qualitative digit feature analysis.
  • UCSD Ped1: A pedestrian video dataset for testing anomaly localization.
  • MVTec-AD: A comprehensive industrial dataset for real-world defect detection.
  • Dsprites: A standard dataset for measuring latent space disentanglement.

4. Key Insights

A primary finding is that latent dimensions in VAEs are often spatially grounded, meaning individual neurons in the latent vector correspond to specific physical regions of the input.

Visualization of latent dimensions $z_1, z_2, z_3$ for the digit '3'. Each dimension focuses on a specific spatial component.
  • Spatial Grounding: For example, one dimension might focus on the top horizontal bar of a digit, while another focuses on the vertical stem.
  • Attention vs. Reconstruction: Gradient-based attention maps provide more precise anomaly localization than standard pixel-wise reconstruction error, which can be noisy.
  • Explaining as a Training Signal: Incorporating attention-based constraints ($L_{AD}$) during training improves the quality of the learned latent space, effectively bootstrapping the model into learning cleaner features.

5. Results

  • Anomaly Detection: On MVTec-AD, the method achieved state-of-the-art results in categories like "Leather" and "Cable," outperforming AnoGAN and standard SSIM-based autoencoders.
  • Disentanglement: On Dsprites, the AD-FactorVAE reached a disentanglement score of approximately 0.90, compared to 0.82 for the baseline FactorVAE and 0.73 for $\beta$-VAE.
  • Localization: Qualitative tests on UCSD Ped1 showed precise isolation of anomalies (e.g., bicycles) where vanilla VAEs produced noisy results.

6. Conclusion

This work provides a significant step toward interpretable generative modeling. Future directions include extending these techniques to GANs and leveraging the full posterior distribution of VAEs to generate a "distribution of attention maps" to account for model uncertainty.

Summary updated

BibTeX
@inproceedings{camps2020towards,
  author = {Octavia Camps and WenQian Liu and Runze Li and Meng Zheng and Ziyan Wu and Richard Radke and Bir Bhanu and Srikrishna Karanam},
  title = {{Towards visually explaining variational autoencoders}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2020},
  doi = {10.1109/cvpr42600.2020.00867},
}
Figure