Skip to main content
QUICK REVIEW

[Paper Review] TransHP: Image Classification with Hierarchical Prompting

Wenhao Wang, Yifan Sun|arXiv (Cornell University)|Apr 13, 2023
Domain Adaptation and Few-Shot LearningComputer Science7 citations
TL;DR

TransHP proposes a novel hierarchical prompting mechanism for vision transformers that improves image classification by injecting coarse-class prompts into intermediate layers, enhancing accuracy, data efficiency, and model explainability. It boosts ViT-B/16 accuracy by +2.83% on ImageNet and improves data efficiency by +12.69% under 10% training data.

ABSTRACT

This paper explores a hierarchical prompting mechanism for the hierarchical image classification (HIC) task. Different from prior HIC methods, our hierarchical prompting is the first to explicitly inject ancestor-class information as a tokenized hint that benefits the descendant-class discrimination. We think it well imitates human visual recognition, i.e., humans may use the ancestor class as a prompt to draw focus on the subtle differences among descendant classes. We model this prompting mechanism into a Transformer with Hierarchical Prompting (TransHP). TransHP consists of three steps: 1) learning a set of prompt tokens to represent the coarse (ancestor) classes, 2) on-the-fly predicting the coarse class of the input image at an intermediate block, and 3) injecting the prompt token of the predicted coarse class into the intermediate feature. Though the parameters of TransHP maintain the same for all input images, the injected coarse-class prompt conditions (modifies) the subsequent feature extraction and encourages a dynamic focus on relatively subtle differences among the descendant classes. Extensive experiments show that TransHP improves image classification on accuracy (e.g., improving ViT-B/16 by +2.83% ImageNet classification accuracy), training data efficiency (e.g., +12.69% improvement under 10% ImageNet training data), and model explainability. Moreover, TransHP also performs favorably against prior HIC methods, showing that TransHP well exploits the hierarchical information. The code is available at: https://github.com/WangWenhao0716/TransHP.

Motivation & Objective

  • To improve image classification accuracy by leveraging hierarchical semantic structures in datasets like ImageNet and iNaturalist.
  • To enhance data efficiency by enabling models to generalize better under low-data regimes using coarse-class prompts.
  • To improve model explainability by guiding attention to critical local regions through hierarchical prompting.
  • To mimic human visual recognition by using ancestor classes as dynamic prompts to focus on subtle differences among descendant classes.

Proposed method

  • TransHP learns a set of prompt tokens to represent all coarse (ancestor) classes in the hierarchy.
  • An intermediate transformer block performs on-the-fly coarse-class prediction for each input image.
  • The predicted coarse-class prompt token is injected into the intermediate feature via cross-attention, conditioning subsequent feature extraction.
  • The injected prompt modifies attention dynamics, encouraging focus on fine-grained discriminative regions after coarse classification.
  • The method uses soft attention weights to integrate prompt tokens with patch and class tokens in a differentiable manner.
  • The architecture maintains fixed parameters across inputs, enabling dynamic attention modulation without parameter sharing changes.

Experimental results

Research questions

  • RQ1Can hierarchical prompting improve the accuracy of vision transformers in image classification tasks?
  • RQ2Does hierarchical prompting enhance data efficiency, especially under low-data training regimes?
  • RQ3Can the model's attention mechanism be made more interpretable through coarse-to-fine prompting?
  • RQ4How does hierarchical prompting compare to existing prompting and hierarchical classification methods in terms of performance and robustness?

Key findings

  • TransHP improves ViT-B/16 top-1 accuracy by +2.83% on ImageNet compared to the baseline.
  • Under 10% training data, TransHP achieves a +12.69% improvement in accuracy gain over the baseline, demonstrating superior data efficiency.
  • The model's accuracy drop under data scarcity is significantly smaller—40.72% at 10% data—compared to 50.97% for the baseline, indicating strong robustness.
  • TransHP surpasses competing methods like HiMulConE by 7.17% under 10% training data, highlighting its effectiveness in low-data regimes.
  • Visualization shows that TransHP shifts attention from global to localized, critical regions (e.g., face and crown in goldfish) after prompt injection, improving focus and explainability.
  • The method successfully mimics human visual recognition by using coarse categories as prompts to guide attention to fine-grained differences.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.