Towards Generative Class Prompt Learning for Fine-grained Visual Recognition

Soumitri Chattopadhyay, Sanket Biswas, Emanuele Vivoli, Josep Lladós

Abstract

Vision-Language Models (VLMs) like CLIP have demonstrated remarkable zero-shot capabilities, yet they often struggle with fine-grained visual recognition tasks where categories are visually similar or domain-specific. Traditional adaptation methods focus on "soft prompt tuning" of the context surrounding a class name. This paper proposes a paradigm shift toward Generative Class Prompt Learning (GCPL) and Contrastive Multi-class Prompt Learning (CoMPLe). By leveraging the generative power of diffusion models to learn class-specific tokens, these methods capture rich visual attributes that standard text embeddings lack. Experimental results across natural, medical, and abstract datasets show that generative learning significantly outperforms discriminative baselines, particularly in out-of-distribution scenarios.

Introduction

Foundational Vision-Language Models (VLMs) have redefined the state-of-the-art in image-text alignment. However, their performance often degrades in specialized domains—such as medical imaging or abstract pattern recognition—where the textual labels (e.g., "Tu-154" or "adenocarcinoma") do not inherently convey the visual complexity required for accurate classification.

The primary bottleneck in current adaptation strategies is the reliance on fixed or contextually tuned class embeddings. While methods like CoOp and MaPLe optimize the "context" (e.g., "A photo of a [CLASS]"), they leave the class token itself largely unchanged. This paper argues that for fine-grained tasks, the class name is the weak link. To address this, the authors propose learning the class token through a generative reconstruction objective, effectively "teaching" the model what a class looks like rather than just how it is described.

Methodology

Generative Class Prompt Learning (GCPL)

GCPL moves away from purely discriminative objectives. Drawing inspiration from "textual inversion," the method treats the class name as a learnable placeholder token within a pre-trained diffusion model (e.g., Stable Diffusion). During the training phase, the model is presented with a few images of a specific class. The objective is to optimize the class token such that the diffusion model can accurately reconstruct (denoise) those images. This process allows the text embedding to "imbibe" specific visual features—textures, shapes, and patterns—directly from the pixel data.

Contrastive Multi-class Prompt Learning (CoMPLe)

While GCPL learns class representations in isolation, fine-grained recognition often requires understanding the subtle differences between similar categories. CoMPLe introduces a contrastive loss into the generative framework. It forces the model to minimize reconstruction error for the ground-truth class while simultaneously maximizing it for other classes. This dual objective encourages the model to identify features that are not only representative of a class but also discriminative against its neighbors.

Inference via Diffusion Classifier

At test time, classification is performed using the "Diffusion Classifier" approach. Instead of a standard CLIP dot-product similarity, the model calculates the epsilon-reconstruction error for each learned class prompt. The class that allows the diffusion model to denoise the test image most effectively is selected as the prediction.

Experimental Setup

The authors evaluated GCPL and CoMPLe across seven diverse datasets categorized into three domains:

  1. Natural Images: StanfordCars (196 car models), Flowers102, and Cornseeds.
  2. Medical Imaging: CRC5k (histopathology), ISIC2018 (skin lesions), and LC25000 (lung/colon tissues).
  3. Abstract Concepts: Fractals (60 categories of complex mathematical patterns).

These datasets were chosen specifically to test the models' ability to handle domain gaps and visual concepts that are difficult to describe in natural language.

Results and Discussion

Performance in Specialized Domains

The most striking results were observed in the Fractals and Medical datasets. On the Fractals dataset, where textual descriptions are almost entirely uninformative, GCPL achieved 90.76% accuracy. In contrast, zero-shot CLIP achieved only 9.25%, and the advanced prompt-tuning method MaPLe reached 76.91%. Similar trends were observed in medical imaging, where CoMPLe's inter-class awareness proved vital for distinguishing between minute differences in tissue samples.

Fine-Grained Accuracy

On the StanfordCars dataset, a benchmark for fine-grained natural image recognition, GCPL reached 88.47% in a 16-shot setting. This outperformed the best-performing discriminative prompt-learning baseline, PromptSRC, by over 5%.

Robustness and Scaling

Experiments varying the number of training "shots" (1 to 16) revealed that generative methods maintain a steady performance trajectory. Unlike some discriminative methods that exhibit unstable or "spurious" behavior when faced with out-of-domain data, GCPL and CoMPLe consistently improved as more visual evidence was provided.

Conclusion and Future Work

This research demonstrates that generative learning is a powerful alternative to discriminative prompt tuning for fine-grained visual recognition. By optimizing the class token itself through a reconstruction objective, models can bridge the gap between abstract text and complex visual reality.

However, the authors note significant computational trade-offs. Diffusion-based inference is substantially slower and more resource-intensive than standard VLM forward passes. Future research should focus on optimizing the efficiency of these generative classifiers to make them viable for real-time applications and larger-scale datasets.

Summary updated

BibTeX
@inproceedings{chattopadhyay2024towards,
  author = {Soumitri Chattopadhyay and Sanket Biswas and Emanuele Vivoli and Josep Lladós},
  title = {{Towards Generative Class Prompt Learning for Fine-grained Visual Recognition}},
  booktitle = {BMVC},
  year = {2024},
}
Figure