Hierarchical Residual Learning Based Vector Quantized Variational Autoencoder for Image Reconstruction and Generation

Mohammad Adiban, Kalin Stefanov, Sabato Marco Siniscalchi, Giampiero Salvi · DOI

Introduction

Vector Quantized Variational Autoencoders (VQVAEs) have become a cornerstone of generative modeling by discretizing latent representations. Unlike standard VAEs that utilize continuous values, VQVAEs map data to a discrete set of "codewords." This discretization mimics human categorical perception and provides a structured latent space that is highly effective for downstream image generation tasks.

Despite their success, VQVAEs face two significant challenges: codebook collapse and computational complexity. Codebook collapse occurs when the model utilizes only a small fraction of its available codewords, leading to wasted capacity and poor reconstruction quality. Furthermore, as the codebook size increases to capture finer details, the nearest-neighbor search required for quantization becomes computationally expensive, scaling linearly with the number of codewords.

The HR-VQVAE Framework

To overcome these hurdles, this research introduces Hierarchical Residual VQVAE (HR-VQVAE). This framework departs from traditional hierarchical architectures (such as VQVAE-2) by implementing two core innovations: hierarchical residual learning and tree-structured codebook access.

Hierarchical Residual Learning

In standard hierarchical models, layers often attempt to reconstruct the entire image redundantly. HR-VQVAE instead adopts a residual learning strategy. The first layer is responsible for capturing the "big picture" or global structure. Each subsequent layer is then tasked specifically with learning the residual error—the detail left over by the preceding layers. This is enforced through a novel objective function that encourages layers to be contrastive. By forcing deeper layers to focus on what the first layer missed, the model naturally avoids codebook collapse and ensures that the entire capacity of the hierarchical codebook is utilized.

Tree-Structured Codebook Access

To address the bottleneck of search complexity, HR-VQVAE organizes its codebooks into a tree structure. Instead of performing a linear search across a massive library of codewords, the model uses the selection made at the first layer to restrict the search space for the second layer. If the first layer contains $m$ codes, the second layer effectively accesses $m$ distinct sub-codebooks. This transformation reduces the search complexity from $O(M)$ to $O(n \times m)$, where $n$ is the number of layers. This efficiency allows HR-VQVAE to scale to massive total codebook sizes (e.g., $64^3$ codewords) that would be computationally prohibitive for flatter architectures.

Experimental Results

The model was evaluated across four diverse benchmarks: MNIST, CIFAR10, ImageNet (128 × 128), and FFHQ (256 × 256). The results demonstrate significant improvements in both quality and efficiency.

Superior Reconstruction and Generation

HR-VQVAE consistently outperformed VQVAE and VQVAE-2 in terms of Mean Squared Error (MSE) and Fréchet Inception Distance (FID). Qualitatively, the model captures intricate details, such as hair texture and skin pores, that baseline models often smooth over. When paired with a PixelCNN prior for image generation, HR-VQVAE achieved an FID of 17.45 on the FFHQ dataset, surpassing other prominent models like VDVAE.

Order-of-Magnitude Speedups

The hierarchical search mechanism provides a transformative boost to inference speed. In benchmarking tests on the FFHQ dataset, HR-VQVAE processed a batch of 10,000 samples in approximately 0.84 seconds. In contrast, VQVAE-2 required 9.34 seconds for the same task. This represents a more than 10x speedup, making high-resolution discrete latent modeling far more accessible for real-time applications.

Conclusion and Future Work

HR-VQVAE effectively solves the twin problems of codebook collapse and search inefficiency in discrete generative models. By leveraging the relationship between hierarchical layers and residual errors, the model achieves state-of-the-art reconstruction fidelity with unprecedented speed. While Transformer-based priors currently offer superior generation quality for highly complex scenes, they come at a high computational cost. Future research aims to integrate the efficient HR-VQVAE backbone with Transformer-based sampling to combine high-fidelity residual encoding with powerful long-range modeling.

Summary updated

BibTeX
@inproceedings{adiban2022hierarchical,
  author = {Mohammad Adiban and Kalin Stefanov and Sabato Marco Siniscalchi and Giampiero Salvi},
  title = {{Hierarchical Residual Learning Based Vector Quantized Variational Autoencoder for Image Reconstruction and Generation}},
  booktitle = {BMVC},
  year = {2022},
  url = {https://openreview.net/forum?id=GHD5REGafJP},
}
Figure