Regularized Vector Quantization for Tokenized Image Synthesis

Jiahui Zhang, Fangneng Zhan, Christian Theobalt, Shijian Lu

Introduction

In modern generative AI, many state-of-the-art models do not operate directly on raw pixels. Instead, they utilize Vector Quantization (VQ) to "tokenize" images, representing them as a grid of discrete codes from a learned vocabulary known as a codebook. While this approach has enabled significant breakthroughs in auto-regressive and diffusion-based synthesis, it is plagued by two primary issues: codebook collapse and inference misalignment.

Codebook collapse occurs when a model utilizes only a small fraction of its available vocabulary, wasting representational capacity. Inference misalignment refers to the discrepancy between training (where the model often uses deterministic selection) and generation (where stochastic sampling is required). This paper introduces Reg-VQ, a regularized vector quantization framework designed to resolve these tensions by combining uniform prior distributions, stochastic masking, and a novel contrastive loss.

The VQ Dilemma: Deterministic vs. Stochastic

Existing VQ methods generally fall into two categories, each with distinct drawbacks:

  1. Deterministic Quantization (e.g., VQ-GAN): These models select the single best-matching code for each image patch. While this produces sharp reconstructions, it frequently leads to codebook collapse. Furthermore, because the model is trained to always pick the "best" token, it struggles during inference when it must sample from a distribution of potential tokens.
  2. Stochastic Quantization (e.g., Gumbel-VQ): These models sample tokens from a distribution during training. While this mitigates collapse, it often results in low codebook utilization and "noisy" reconstructions, making it difficult for the generative backbone to learn high-quality textures.

Reg-VQ aims to bridge this gap, ensuring the model uses its full vocabulary effectively while remaining robust to the randomness inherent in the generation process.

The Reg-VQ Framework

The authors propose three core innovations to regularize the VQ process and improve synthesis quality.

1. Prior Distribution Regularization

To combat codebook collapse, Reg-VQ introduces a KL-divergence loss that encourages the model's token usage to follow a uniform distribution. By forcing the encoder to utilize the entire codebook with roughly equal frequency, the framework ensures that every entry in the vocabulary carries useful information, maximizing the latent space's efficiency.

2. Stochastic Mask Regularization

Reg-VQ employs a hybrid training strategy to narrow the gap between training and inference. During the training phase, approximately 40% of the image regions are randomly masked. In these masked regions, the model uses stochastic sampling (Gumbel-Softmax); in the remaining unmasked regions, it uses deterministic selection (Argmax). This "stochastic mask" forces the model to learn to handle both precise matches and noisy samples simultaneously, creating a more robust representation for downstream generation tasks.

3. Probabilistic Contrastive Loss (PCL)

Traditional VQ models rely heavily on L1 or L2 pixel-matching losses for reconstruction. Reg-VQ introduces Probabilistic Contrastive Loss (PCL), which treats patches at the same spatial location in the original and reconstructed images as positive pairs.

Crucially, PCL incorporates adaptive weights. If a sampled token deviates significantly from the "optimal" token, the model reduces the pulling force of the loss. This allows for "elastic" reconstruction, where the model prioritizes semantic consistency over pixel-perfect accuracy—a trade-off that the authors demonstrate actually improves final generation quality.

Experimental Results and Insights

The framework was evaluated across four standard datasets: ADE20K (semantic synthesis), CelebA-HQ (faces), CUB-200 (birds), and MS-COCO (complex scenes).

Performance Metrics

Reg-VQ consistently outperformed baselines like VQ-VAE, VQ-GAN, and Gumbel-VQ. On the ADE20K dataset, Reg-VQ achieved a Fréchet Inception Distance (FID) of 34.47, a notable improvement over VQ-GAN’s 38.53. These gains were consistent across both Auto-regressive Transformers and Diffusion Model backbones.

Codebook Scaling and Utilization

One of the most significant findings involves codebook scaling. In traditional VQ-GANs, increasing the codebook size (e.g., from 1024 to 8192) often degrades performance because more codes go unused. In contrast, Reg-VQ shows continued performance improvements as the vocabulary grows, proving that its regularization effectively manages larger latent spaces. Visualization of the codebook usage confirms that Reg-VQ utilizes the entire vocabulary, whereas VQ-GAN leaves large portions of the codebook "dead."

The 40% Masking Threshold

Ablation studies identified that masking 40% of the image for stochastic sampling provides the optimal balance. This ratio allows the model to maintain high reconstruction accuracy (PSNR) while significantly boosting the quality of generated images (FID).

Conclusion and Future Directions

Reg-VQ demonstrates that regularizing the quantization process is essential for high-fidelity tokenized image synthesis. By allowing for "elastic" semantic reconstruction and enforcing uniform codebook usage, the model overcomes the traditional limitations of VQ-GAN and Gumbel-VQ.

Future research may explore separating the learning objectives of the encoder and decoder, as the encoder’s task (discretization) and the decoder’s task (realistic reconstruction) are fundamentally different. Additionally, while this work focused on uniform priors, exploring other distributions, such as Gaussian priors, remains a promising avenue for further optimizing the latent space.

Summary updated

BibTeX
@inproceedings{zhang2023regularized,
  author = {Jiahui Zhang and Fangneng Zhan and Christian Theobalt and Shijian Lu},
  title = {{Regularized Vector Quantization for Tokenized Image Synthesis}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2023},
}
Figure