Your Diffusion Model is Secretly a Zero-Shot Classifier

Alexander C. Li, Mihir Prabhudesai, Shivam Duggal, Ellis Brown, Deepak Pathak

Introduction

Researchers from Carnegie Mellon University have demonstrated that large-scale text-to-image diffusion models, such as Stable Diffusion, possess capabilities far beyond image generation. These models can be repurposed as powerful zero-shot image classifiers. By framing the diffusion process as a method for estimating conditional density, a generative model can be transformed into a recognition model that excels in compositional reasoning and exhibits significant robustness to distribution shifts.

The Generative vs. Discriminative Debate

Historically, the AI field has distinguished between discriminative models (e.g., CLIP, ResNet), which learn decision boundaries, and generative models, which learn the underlying data distribution. While diffusion models have set new standards in content creation, their potential for discriminative tasks has been largely untapped. Standard zero-shot classifiers like CLIP often struggle with compositional relationships—the "bag-of-words" problem—where they fail to distinguish between "a cat on a mat" and "a mat on a cat." This research explores whether the extensive world knowledge embedded in diffusion models can address these recognition challenges without further training.

Methodology: The Diffusion Classifier

The proposed Diffusion Classifier method leverages Bayes' Theorem to determine the probability of a class $c$ given an image $x$ by evaluating the likelihood of the image given that class.

The Diffusion Classifier pipeline: an input image is noised and passed through a diffusion model conditioned on various text prompts to find the class with the minimum reconstruction error.
  1. Likelihood Proxy: The training objective of diffusion models (the ELBO) serves as a proxy for log-likelihood. Specifically, the "noise reconstruction error" indicates how well the model understands the image under a specific class condition.
  2. Classification Process: An input image is perturbed with random noise. The diffusion model then predicts this noise using different class-specific prompts (e.g., "a photo of a dog"). The prompt yielding the lowest reconstruction error is selected as the predicted class.
  3. Variance Reduction: To ensure stability, the method uses "paired" noise—applying the same noise and timestep across all candidate prompts to highlight relative differences.
  4. Adaptive Evaluation: To mitigate the computational cost of evaluating many classes, an adaptive "tournament" strategy prunes unlikely candidates early in the process.

Experimental Evaluation

The authors tested the Diffusion Classifier on several benchmarks:

  • Standard Datasets: CIFAR-10, Food-101, Oxford-IIIT Pets, and others.
  • Robustness Benchmarks: ImageNet-A (natural adversaries) and ObjectNet.
  • Compositional Reasoning: Winoground, which tests the understanding of complex object relationships.

Key Insights

The "Sweet Spot" for Noise

A critical finding is that classification accuracy peaks at intermediate timesteps ($t \approx 500$). At low noise levels, the model over-indexes on irrelevant pixel details; at high noise levels, the fundamental structure of the image is lost.

Accuracy vs. Timestep plot showing that the best classification performance occurs at intermediate noise levels.

Superior Compositional Reasoning

Diffusion Classifier significantly outperformed CLIP on the Winoground benchmark. Because the model is trained to construct scenes, it develops a deeper understanding of spatial and compositional relationships compared to models that merely associate images with captions.

Effective Robustness

The model demonstrated "effective robustness" on ImageNet-A, performing 15-25% better than predicted by its standard ImageNet accuracy. This suggests the model captures the "essence" of objects rather than just memorizing superficial patterns.

Results and Performance

  • Zero-Shot Accuracy: Using Stable Diffusion, the method proved competitive with CLIP ResNet-50 and outperformed other diffusion-based feature extraction methods.
  • Winoground: Diffusion Classifier achieved a score of 38.5%, surpassing OpenCLIP ViT-H/14 (33.0%) and CLIP ViT-L/14 (28.2%).
  • ImageNet Scaling: With a Diffusion Transformer (DiT), it reached 79.1% accuracy, proving that generative models can match optimized discriminative models on identical training data.

Limitations and Future Directions

The primary challenge is inference speed. Classifying a single image can take up to 1,000 seconds for a full ImageNet search due to the multiple forward passes required. Future work aims to address this through distillation into faster discriminative models, scaling with stronger language backbones (like T5), and architectural optimizations for more efficient class-conditional processing.

Summary updated

BibTeX
@inproceedings{li2023your,
  author = {Alexander C. Li and Mihir Prabhudesai and Shivam Duggal and Ellis Brown and Deepak Pathak},
  title = {{Your Diffusion Model is Secretly a Zero-Shot Classifier}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2023},
  url = {https://openreview.net/forum?id=DhKoTSrRuK},
}
Figure