Patch-level Contrastive Learning via Positional Query for Visual Pre-training

Shaofeng Zhang, Qiang Zhou, Zhibin Wang, Fan Wang, Junchi YanICML 2023

TL;DR

PQCL (Positional Query for patch-level Contrastive Learning) is a novel plug-in for self-supervised transformer frameworks like DINO and iBOT. It solves the "correspondence problem" in dense contrastive learning by using positional queries to align patches across different image views, significantly boosting performance in downstream tasks like object detection and semantic segmentation.

The Correspondence Problem in Dense Contrastive Learning

In self-supervised learning (SSL), Contrastive Learning has been a dominant paradigm. Usually, it works by taking two different "views" (crops or augmentations) of the same image and teaching a model that they represent the same underlying object.

While this works great for classification (which relies on global features), it struggles with dense prediction tasks like object detection or segmentation, which require fine-grained, local information. To learn these, models need Dense Contrastive Learning (DCL)—aligning specific pixels or patches between views.

The primary challenge here is the correspondence problem: If you crop an image in two different ways, how do you accurately map a patch in Crop A to its counterpart in Crop B?

  1. The Simple Approach: Use the exact same crop twice. Problem: Low input variance makes the task too easy, and the model fails to learn robust features.
  2. The Complex Approach: Use different crops and use bilinear interpolation to guess where patches overlap. Problem: It’s computationally heavy and fails entirely if the crops don't overlap.

The PQCL Approach

The authors introduce PQCL, a method that establishes exact patch correspondence without sacrificing input variance.

The Core Mechanism: Positional Queries

Instead of just feeding image patches into a Vision Transformer (ViT), PQCL introduces "query crops."

Overview of the PQCL architecture
  • The Student Branch: Receives the global image views with some patches masked. Crucially, it also receives positional embeddings (but no pixel data) for a set of "query patches" located elsewhere in the image.
  • The Teacher Branch: Receives the actual pixel data for those same query patches.
  • The Task: The student must use the global context and the positional "hint" to predict the features of the query patches held by the teacher.

Key Technical Innovations

  1. Cross-Attention Integration: Rather than simply concatenating query tokens (which shifts the data distribution and hurts performance), PQCL uses a cross-attention mechanism within each ViT block. This allows the positional queries to "look at" the visible patches to extract semantic information.
  2. Relative Positional Encoding: To make the queries work, the model needs to know exactly where a small query crop sits within the larger global image. The authors use fixed sine-cosine embeddings to represent these relative spatial coordinates.
Absolute vs. Relative Positional Encoding
  1. Plug-and-Play: PQCL is designed as an add-on. It was tested on top of DINO (which focuses on global distillation) and iBOT (which adds masked image modeling).

Key Insights

  • Variance is a Feature, Not a Bug: Contrastive learning is most effective when the task is challenging. By using positional queries to bridge two different views, PQCL maintains high input variance, forcing the model to learn more generalized spatial representations.
  • The Distribution Shift Problem: The authors found that directly inputting query patches into the self-attention layer actually decreased accuracy. This happens because the model sees a different number of patches during pretraining versus downstream finetuning. Their cross-attention approach bypasses this by keeping the query stream separate from the primary patch stream.
  • Spatial Sensitivity: Because the model is constantly tasked with "locating" and "identifying" patches based on coordinates, it develops a much stronger sense of geometry and spatial layout than standard DINO or iBOT models.

Results & Performance

Pretrained on ImageNet-1K, PQCL achieves state-of-the-art (SOTA) results across several benchmarks, particularly in dense tasks:

  • ImageNet-1K Linear Probing: Using a ViT-Base, PQCL achieved 76.9% top-1 accuracy, outperforming the iBOT baseline (75.8%).
  • MS-COCO Detection: On ViT-Small, PQCL improved the iBOT baseline by 2.4 mAP (moving from 40.7 to 43.1).
  • ADE20K Segmentation: PQCL achieved 45.2 mIoU, a significant jump over standard iBOT (44.1) and DINO (38.3).
  • Video Segmentation (DAVIS 2017): It reached a SOTA average score (J&F) of 63.8, proving that the learned features are highly robust for tracking objects across frames.

Limitations and Future Work

  • GPU Memory Constraints: Due to memory limits, the authors could only use two global views during pretraining. Incorporating "local views" (as seen in SwAV or DINO) could further improve results.
  • Architectural Specificity: While PQCL is a "plug-in," it is specifically designed for Transformer-based architectures. Adapting this positional query logic to pure Convolutional Neural Networks (CNNs) remains an open challenge.
  • Hyperparameter Sensitivity: The "query crop ratio" and the balance between global and query losses require careful tuning to achieve optimal performance.

Summary updated

BibTeX
@inproceedings{zhang2023patch,
  author = {Shaofeng Zhang and Qiang Zhou and Zhibin Wang and Fan Wang and Junchi Yan},
  title = {{Patch-level Contrastive Learning via Positional Query for Visual Pre-training}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=6dEQtx9NMs},
}
Figure