EGC: Image Generation and Classification via a Diffusion Energy-Based Model

Qiushan Guo, Chuofan Ma, Yi Jiang, Zehuan Yuan, Yizhou Yu, Ping LuoICCV 2023 · DOI

Abstract

Learning image classification and image generation using a single set of network parameters has long been a challenging objective in computer vision. Traditional approaches often sacrifice performance in one domain to excel in the other. This paper introduces the Energy-based Classifier and Generator (EGC), a unified framework that achieves superior performance in both tasks. By reformulating the forward pass to output a joint distribution $p(\mathbf{x}, y)$ and utilizing the backward pass for image generation through label marginalization, EGC bridges the gap between discriminative and generative learning. Leveraging diffusion processes to stabilize energy-based training, EGC demonstrates state-of-the-art generative results on ImageNet-1k and high-resolution CelebA-HQ, while simultaneously providing enhanced classification accuracy and adversarial robustness.

Introduction

In the current deep learning landscape, a clear divide exists between discriminative models, which excel at categorizing data (e.g., ResNets), and generative models, which excel at creating it (e.g., Diffusion models). Historically, models designed for one task perform poorly on the other. For instance, Joint Energy-based Models (JEM) attempted to bridge this gap but often suffered from significant training instability. The EGC framework addresses this "performance gap" by integrating Energy-Based Models (EBMs) with the stability of diffusion processes, allowing a single neural network to both "see" and "draw" with high proficiency.

The EGC Framework

The core innovation of EGC lies in its treatment of the classification and generation tasks as two sides of the same coin, modeled through a joint distribution.

1. Joint Distribution Modeling

Standard classifiers typically model the conditional distribution $p(y|\mathbf{x})$. In contrast, EGC’s forward pass is designed to output the joint distribution $p(\mathbf{x}, y)$. By modeling the relationship between images and labels directly, the model gains a more holistic understanding of the data manifold.

2. Diffusion as a Stabilizer

Traditional EBMs are notoriously difficult to train because they require estimating an energy landscape across the entire data space. In low-density regions where data is scarce, gradients can become "sharp" and unstable. EGC solves this by adopting a diffusion process. By gradually adding Gaussian noise to images during training, the model "populates" these low-density regions, smoothing the energy landscape and making it significantly easier to learn.

3. Fisher Divergence and the Unified Backward Pass

Rather than attempting to calculate the intractable partition function required for maximum likelihood training, EGC optimizes using Fisher divergence (score matching). This allows the model to learn the score function—the gradient of the log-probability. In the backward pass, the model performs denoising. Because it models the joint distribution, EGC can provide both an unconditional score (ensuring image realism) and classifier guidance (ensuring label consistency) in a single, unified step.

Experimental Results

The authors evaluated EGC across several benchmarks, ranging from low-resolution datasets to high-resolution latent spaces.

  • CIFAR-10: EGC achieved a 95.9% classification accuracy, surpassing the Wide ResNet-28-12 baseline. Simultaneously, it reached a Fréchet Inception Distance (FID) of 3.30, competitive with dedicated generative models like DDPM.
  • ImageNet-1k: At 256×256 resolution, the model reached a 78.9% Top-1 accuracy and a generative FID of 6.05.
  • High-Resolution Synthesis: By utilizing Latent Diffusion (LDM) architectures, EGC successfully generated high-fidelity images at 1024×1024 resolution on CelebA-HQ, a significant milestone for hybrid EBMs.

Key Insights

Adversarial Robustness

One of the most significant findings is that training a model to generate images inherently improves its classification robustness. EGC proved significantly more resilient against adversarial attacks (such as FGSM and PGD) compared to standard discriminative-only models. This suggests that the generative objective forces the model to learn more robust, meaningful features.

Architecture: U-Net vs. ResNet

The study found that the U-Net architecture, common in diffusion models, is superior to the ResNet architecture for joint tasks. The skip connections in U-Nets are crucial for preserving the fine-grained spatial details necessary for high-quality synthesis—details that standard discriminative ResNets often discard in favor of global semantic features.

Conclusion

EGC represents a successful attempt to unify discriminative and generative learning within a single set of parameters. By combining the theoretical strengths of Energy-Based Models with the practical stability of diffusion, EGC achieves state-of-the-art results in both image classification and generation. This work paves the way for more versatile AI systems capable of complex understanding and creative synthesis.

Summary updated

BibTeX
@inproceedings{guo2023egc,
  author = {Qiushan Guo and Chuofan Ma and Yi Jiang and Zehuan Yuan and Yizhou Yu and Ping Luo},
  title = {{EGC: Image Generation and Classification via a Diffusion Energy-Based Model}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2023},
  doi = {10.1109/iccv51070.2023.02098},
}
Figure