SD4Match: Learning to Prompt Stable Diffusion Model for Semantic Matching

Xinghui Li, Jingyi Lu, Kai Han, Victor Adrian PrisacariuOpenReview 2023 · Submission to ICLR 2024 · Withdrawn · DOI

Abstract

Semantic image matching—identifying corresponding keypoints between images of similar objects—is a fundamental challenge in computer vision due to significant variations in viewpoint, scale, and appearance. While pre-trained text-to-image models like Stable Diffusion (SD) have emerged as powerful feature extractors for this task, their performance is often limited by the use of handcrafted text prompts. We present SD4Match, a framework that optimizes prompt embeddings directly in the latent space. By introducing a novel Conditional Prompting Module (CPM) that generates dynamic prompts based on local feature patches from image pairs, SD4Match achieves state-of-the-art results, notably surpassing previous benchmarks on the SPair-71k dataset by 12 percentage points.

Introduction

Semantic matching involves finding correspondences between semantically similar parts of different objects, such as the headlights of two distinct car models. This task is complicated by occlusions and intra-class variations. Recent research has demonstrated that the intermediate UNet layers of Stable Diffusion models contain rich semantic information. However, existing methods typically use generic text prompts (e.g., "a photo of a dog") or simple captioners, which may not provide the most discriminative context for matching. SD4Match addresses this by treating the prompt as a learnable parameter, moving beyond the limitations of natural language descriptions.

Methods: From Handcrafted to Learned Prompts

SD4Match freezes the SD UNet and focuses on optimizing prompt embeddings through prompt tuning. The framework explores three distinct strategies for generating these embeddings:

  1. SD4Match-Single: Learns a single, universal prompt embedding applied across all image categories.
  2. SD4Match-Class: Learns category-specific prompt embeddings for different object classes.
  3. SD4Match-CPM (Conditional Prompting Module): This approach utilizes a frozen DINOv2 encoder to extract local feature patches from both images in a pair. These features are fused to generate a dynamic prompt conditioned on the specific shared details of the pair.
The SD4Match framework overview, illustrating the prompting modules and the training/inference pipeline.

During training, the system optimizes these embeddings using a cross-entropy loss between predicted matching probability maps and ground-truth keypoint correspondences. The CPM variant is particularly effective because it captures relational context between images, which is inherent to the matching task.

Experimental Results

SD4Match was evaluated on standard benchmarks including PF-Pascal, PF-Willow, and the highly challenging SPair-71k dataset.

Performance Gains

On the SPair-71k dataset, SD4Match-CPM achieved an overall accuracy (PCK @ $\alpha=0.1$) of 75.5%, a massive improvement over the previous state-of-the-art (SimSC-iBOT at 63.5%). When compared to the DIFT baseline—which uses the same SD model but with standard text prompts—SD4Match-Single improved performance by 37.2%, highlighting the efficacy of latent space prompt tuning over manual engineering.

Ablation study (a) and performance vs. timestep graph (b) showing SD4Match variants significantly outperforming the DIFT baseline.

Key Insights

  • Relational Conditioning: Conditioning prompts on the image pair rather than individual images leads to superior matching, as the prompt can focus on shared semantic features.
  • Local Granularity: Using local feature patches for conditioning outperforms global descriptors, as matching relies on fine-grained spatial details.
  • Abstract Semantics: Visualizing the learned prompts by generating images from them reveals that the model learns abstract, high-level category representations (e.g., a collage of car parts) even when supervised only by keypoint correspondences.

Conclusion and Future Work

SD4Match demonstrates that optimizing prompt embeddings is a highly effective way to unlock the potential of pre-trained diffusion models for discriminative vision tasks. While the method sets new benchmarks, it remains sensitive to input resolution, as the underlying SD model's feature extraction is optimized for specific training sizes. Future research will focus on improving the scale-invariance of these features and enhancing the generalizability of learned prompts when moving from small to large-scale datasets.

Summary updated

BibTeX
@misc{li2023sd,
  author = {Xinghui Li and Jingyi Lu and Kai Han and Victor Adrian Prisacariu},
  title = {{SD4Match: Learning to Prompt Stable Diffusion Model for Semantic Matching}},
  year = {2023},
  eprint = {2310.17569},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2310.17569},
}
Figure