Just Leaf It: Accelerating Diffusion Classifiers with Hierarchical Class Pruning

Arundhati S. Shanbhag, Brian B. Moser, Tobias C. Nauen, Stanislav Frolov, Federico Raue, Andreas Dengel

TL;DR

Diffusion classifiers turn generative models into powerful zero-shot discriminators, but evaluating every single class candidate makes them painfully slow. This paper introduces the Hierarchical Diffusion Classifier (HDC), which leverages dataset label hierarchies to prune irrelevant categories early in the inference process. The result is a massive inference speedup of up to 60% with virtually no loss—and sometimes a slight improvement—in classification accuracy.

What Problem Does This Paper Address?

While diffusion models are famous for generating stunning imagery, recent work has shown they can also act as excellent zero-shot classifiers. By flipping Bayes' theorem, a pre-trained diffusion model can evaluate how well it can reconstruct an image when conditioned on a specific text prompt (e.g., "a photo of a [class]").

However, there is a massive catch: to classify an image, standard diffusion classifiers must run this computationally expensive noise-prediction loop for every single possible class label. If you are classifying an image against the 1,000 classes of ImageNet, the model scales linearly ($O(N)$), resulting in an immense computational bottleneck. This paper tackles this exact scalability issue, aiming to make diffusion-based classification practical for large-scale applications.

Methods

The authors introduce the Hierarchical Diffusion Classifier (HDC). Instead of treating all classes as a flat list, HDC organizes them into a tree structure based on parent-child relationships (e.g., Entity $\rightarrow$ Living Thing $\rightarrow$ Animal $\rightarrow$ Bird $\rightarrow$ Bald Eagle).

HDC Pruning and Classification Pipeline

The core algorithm operates in two main stages:

  1. The Pruning Stage: HDC traverses the label tree from top to bottom. At each level, it calculates a rough reconstruction error for the category labels using a significantly lower number of Monte Carlo steps ($M$) than a standard diffusion classifier. It then discards highly irrelevant branches using one of two strategies:
  2. Fixed Pruning (Strategy 1): Keeps a fixed top-$k$ percentage of the most promising nodes at each hierarchy level.
  3. Dynamic Pruning (Strategy 2): Dynamically keeps all nodes whose errors fall within two standard deviations of the minimum error at that level.
  4. The Final Prediction Stage: Once the tree is pruned down to a small subset of specific leaf nodes (the actual target classes), the algorithm runs the standard, high-fidelity diffusion classification process on just those remaining candidates to make the final prediction.

Datasets

The authors evaluated their approach on two benchmark datasets:

  • ImageNet-1K: Utilizing a 7-level hierarchy modified from the dataset's inherent WordNet ontology.
  • CIFAR-100: To prove the method works even when a dataset lacks a native hierarchy, the authors used a Large Language Model (LLM) to self-generate a custom label tree.

Key Insights and Ideas

  • Coarse-to-Fine Efficiency: You don't need a high-fidelity, computationally expensive evaluation to realize an image of a bird isn't a "screwdriver." A cheap, low-sample estimate at a high category level is more than enough to safely prune entire branches of the label tree.
  • Pruning as a Regularizer: Surprisingly, pruning doesn't just save time; it can actually improve accuracy. By eliminating distant, irrelevant classes early on, the classifier avoids getting confused by random noise matches in unrelated categories during the final fine-grained decision.
  • Tunable Control: The pruning ratio acts as a knob that engineers can twist to perfectly balance speed and precision depending on their application's constraints.

Key Results

Evaluated using Stable Diffusion 2.0 on ImageNet-1K, the results highlight a highly customizable trade-off:

Performance Comparison on ImageNet-1K
  • Strategy 1 (Fixed Pruning): Achieved a 38.75% speedup while actually boosting Top-1 accuracy slightly from 64.70% to 64.90% (and up to 65.16% class-wise average).
  • Strategy 2 (Dynamic Pruning): Slashed inference time by 59.38% (dropping from 1600 seconds to 650 seconds per class evaluation) with only a minor drop in Top-1 accuracy to 63.20%.

An empirical example of this hierarchical traversal in action can be seen below, where the model successfully isolates a bird image while discarding non-living things and mammals early on:

Figure 4. Example classification of an image in the pruning stage of the HDC using Strategy 1. In this stage, the error scores of each node are used to iteratively prune the tree, narrowing it down to rel- evant leaf nodes that will undergo further refinement in subsequent stages. The subsequent steps then focus on closely related nodes (see leaves under the purple line), such as the American Bald Eagle and Vulture, ultimately selecting the leaf node with the lowest error score—Kite (Bird of Prey) - in the final stage.

Limitations and Future Work

Despite the impressive speedups, the authors note a few limitations:

  • Hierarchy Dependency: The efficiency gains are heavily reliant on the depth and balance of the underlying label tree. Datasets with flat structures or very shallow hierarchies will not benefit as significantly.
  • Still Computationally Heavy: Even with a 60% reduction in runtime, diffusion classifiers remain fundamentally slower than traditional, dedicated discriminative networks (like standard ResNets or Vision Transformers).
  • Future Directions: The authors point toward exploring automated, data-driven tree construction methods using LLMs or greedy expansion strategies to seamlessly handle any unstructured dataset in the future.

Summary updated

BibTeX
@misc{shanbhag2024just,
  author = {Arundhati S. Shanbhag and Brian B. Moser and Tobias C. Nauen and Stanislav Frolov and Federico Raue and Andreas Dengel},
  title = {{Just Leaf It: Accelerating Diffusion Classifiers with Hierarchical Class Pruning}},
  year = {2024},
  eprint = {2411.12073},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2411.12073},
}
Figure