Improving Dense Contrastive Learning with Dense Negative Pairs

Berk Iskender, Zhenlin Xu, Simon Kornblith, Enhung Chu, Maryam KhademiarXiv 2022

Abstract

Many contrastive representation learning methods learn a single global representation of an entire image. However, dense contrastive representation learning methods such as DenseCL (Wang et al., 2021) can learn better representations for tasks requiring stronger spatial localization of features, such as multi-label classification, detection, and segmentation. In this work, we study how to improve the quality of the representations learned by DenseCL by modifying the training scheme and objective function, and propose DenseCL++. We also conduct several ablation studies to better understand the effects of: (i) various techniques to form dense negative pairs among augmentations of different images, (ii) cross-view dense negative and positive pairs, and (iii) an auxiliary reconstruction task. Our results show 3.5% and 4% mAP improvement over SimCLR (Chen et al., 2020a) and DenseCL in COCO multi-label classification. In COCO and VOC segmentation tasks, we achieve 1.8% and 0.7% mIoU improvements over SimCLR, respectively.

Introduction

Standard contrastive learning methods typically focus on learning a single global representation for an entire image. While effective for single-label classification tasks, this approach often falls short in "dense" tasks where spatial information is critical, such as object detection or semantic segmentation. Previous attempts like DenseCL introduced "dense-to-global" comparisons, matching local patches to global image summaries. However, this creates a bottleneck by losing fine-grained local information in the negative samples. DenseCL++ addresses this by shifting to a "dense-to-dense" paradigm, comparing local features directly across different images to learn more discriminative and localized features.

Methods

DenseCL++ introduces several architectural and objective modifications to enhance feature localization and discriminability.

Overview of the DenseCL++ architecture, illustrating the Transformer Encoder followed by Global and Dense projection heads.
  1. Dense Negative Pairs: Instead of comparing a local feature to a global average of a negative image, DenseCL++ compares it directly to local features sampled from that image. This forces the model to learn granular distinctions between different objects or textures.
  2. Guided Negative Sampling: To increase task difficulty, the method samples multiple candidates and selects "hard negatives"—those most similar to the anchor—making the learning process more robust.
  3. Cross-View Negatives: Negative pairs are also formed using the least similar features from different augmented views of the same image, encouraging a better distribution of features in the latent space.
  4. Auxiliary Reconstruction Task: A decoder is optionally added to reconstruct the original image. Findings suggest this only benefits performance when the reconstruction loss weight is kept low, preventing the model from over-focusing on low-level pixel details at the expense of semantic features.

Results and Analysis

The proposed DenseCL++ was evaluated on MS COCO and PASCAL VOC datasets, focusing on multi-label classification and semantic segmentation. The model shows consistent improvements over both the baseline SimCLR and the original DenseCL.

mAP performance on COCO multi-label classification across different weights (lambda) for the dense contrastive loss.

As shown in the figure above, the model achieves peak performance when the dense contrastive loss is weighted heavily (λ = 0.9). This underscores the importance of local feature learning over global consistency. Quantitatively, DenseCL++ achieved a 3.5% mAP improvement over SimCLR and a 4% improvement over DenseCL on COCO multi-label classification. For semantic segmentation, improvements of 1.8% mIoU on COCO and 0.7% mIoU on PASCAL VOC were observed over the SimCLR baseline.

Discussion and Conclusion

The transition from "dense-to-global" to "dense-to-dense" negatives proves to be a critical factor in improving performance for spatially sensitive tasks. While auxiliary tasks like reconstruction can provide additional signals, they must be carefully balanced to avoid degrading semantic representation quality. Future work may explore the scalability of these dense strategies with larger hierarchical architectures like Swin Transformers and further optimize the computational overhead introduced by guided sampling techniques.

Summary updated

BibTeX
@misc{iskender2022improving,
  author = {Berk Iskender and Zhenlin Xu and Simon Kornblith and Enhung Chu and Maryam Khademi},
  title = {{Improving Dense Contrastive Learning with Dense Negative Pairs}},
  year = {2022},
  eprint = {2210.05063},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2210.05063},
}
Figure