What is the Right Embedding Space for Contrastive Learning in Referring Expression Counting?

1Stony Brook University    2UNC Charlotte
*Indicates equal contribution. Correspondence to kostas@cs.stonybrook.edu
Left: a street scene with people walking, riding bicycles and riding motorcycles. Right: (a) image-text contrastive learning, where visual tokens for different referring expressions stay entangled; (b) image-only contrastive learning, where positives form a compact green cluster clearly separated from red negatives.
Existing REC methods rely on image–text contrastive learning, which depends on text guidance and can introduce misalignment. (a) Each anchor visual token (blue) is compared against positive (green) and negative (red) prompt text embeddings. Because the image and text embedding spaces are not necessarily aligned, visual tokens for different prompts can remain entangled — they are never separated directly. (b) We instead perform image-only contrastive learning, directly optimizing relationships among object embeddings in the visual space. This yields more compact intra-class clusters and clearer inter-class separation.

Abstract

Referring Expression Counting (REC) requires distinguishing visually similar objects described by fine-grained text cues. Existing methods tackle this via image-text contrastive learning of visual features which aims to distinguish visual features corresponding to positive and negative referring expressions. However, this strategy relies heavily on accurate image–text alignment and is constrained by the limited number of available negative expressions. We argue that these limitations can be avoided by performing contrastive learning entirely in the visual embedding space. To this end, we introduce C-REX, a simple but effective supervised contrastive learning framework that learns fine-grained visual representations by contrasting visual tokens within the same image. By shifting the negative samples from incorrect Referring Expressions to visual tokens from the image, C-REX vastly increases the number of potential negatives, providing richer and more stable supervision. This design leads to stronger fine-grained visual discrimination and better generalization across complex open-world counting settings. C-REX serves as a plug-in module that can be seamlessly applied to any existing REC model without architectural changes. We apply it in three different REC architectures and achieve state-of-the-art results improving by up to 28% in MAE and 24.5% in RMSE. Moreover, we show that our framework is versatile and general, and can be applied to other counting tasks like class-agnostic counting, improving the performance of existing models.

Method

(a) One image token compared against three text tokens: green arrow to 'person riding a bicycle', red arrows to 'person walking' and 'person riding a motorcycle'. (b) The same image token compared against many other image tokens, with green arrows to other cyclists and red arrows to pedestrians, motorcyclists, cars and signs.
(a) Standard REC models distinguish visually similar but contextually distinct objects through image–text contrastive learning, which falls short when the image and text embedding spaces are poorly aligned — and offers only a handful of negatives, since they are drawn from the referring expressions available for that image (typically fewer than four). (b) We operate solely in the image space, contrasting each matched visual token against every other token in the image. This provides a much larger pool of negatives (typically in the hundreds) and a more stable supervisory signal.

C-REX replaces the image–text contrastive loss used by previous REC methods with a supervised contrastive objective computed entirely among the visual tokens of a single image. Predicted points are matched to the ground-truth points by bipartite matching: the matched tokens become the positive set, and every other token in the image becomes a negative, so the referring expression only conditions the visual backbone and never enters the contrastive objective itself. That turns a handful of text negatives into hundreds of visual ones, and because only positives act as anchors, unrelated negatives are pushed away from the positives without being pulled together. Every other counting loss is left unchanged, which is what makes C-REX a drop-in module for any existing REC architecture.

Qualitative Results

Each slide shows one referring expression. Every model is paired with its C-REX counterpart and colour-coded to match the count-range chart in the results below — the darker swatch is the baseline, the lighter one is the same model trained with C-REX. Image contrast is adjusted to make predictions easier to see.

Results

We integrate C-REX into GroundingREC, CAD-GD and a detection-based GroundingDINO baseline, with Swin-T and Swin-B backbones. It improves performance across models, backbones and metrics.

REC-8K

Method Validation set Test set
MAE RMSE Prec Rec F1 MAE RMSE Prec Rec F1
Swin-T GrREC 6.8018.130.650.710.68 6.5019.790.670.720.69
  + C-REX 4.7414.500.700.710.71 4.9118.870.710.720.72
CAD-GD 6.3315.900.650.690.67 6.2518.910.670.700.69
  + C-REX 5.9814.840.660.700.68 5.9717.370.670.730.70
CAD-GD 4.6512.870.650.690.67 4.8115.020.670.700.69
  + C-REX 4.7013.780.660.700.68 4.6114.710.670.730.70
GrDINO 5.9217.090.650.650.65 5.9019.730.680.680.68
  + C-REX 4.2612.890.750.720.73 4.3817.930.760.740.75
Swin-B GrREC 5.6615.240.660.770.71 5.4218.470.710.690.70
  + C-REX 4.5714.220.720.720.72 4.5818.070.740.720.73
CAD-GD 5.3113.680.700.730.72 5.3616.140.730.730.73
  + C-REX 5.0612.730.700.740.72 5.0215.090.720.740.73
CAD-GD 4.4012.200.700.730.72 4.5813.810.730.730.73
  + C-REX 4.3812.430.700.740.72 4.4913.210.720.740.73
GrDINO 4.5814.640.700.760.73 4.6417.580.720.760.74
  + C-REX 4.0014.490.780.760.77 4.2016.760.790.770.78

Results on REC-8K. GrREC and GrDINO are GroundingREC and GroundingDINO. GroundingREC results come from the released models; CAD-GD is retrained on REC-8K with the authors’ public code, since no pre-trained models are available. CAD-GD uses the alternative positive-detection strategy, selecting the top N tokens by density map estimate rather than a static threshold. Best result per backbone in bold; rows with C-REX are highlighted.

Performance across count ranges

Grouped bar charts of MAE and RMSE for each baseline model and its C-REX counterpart, binned by object count range on REC-8K, with the number of samples shown below each bin.
Each baseline REC model compared to its C-REX counterpart across object count ranges on REC-8K; sample counts are shown below each bin. In most cases C-REX yields lower MAE and RMSE, showing consistent improvements across low-, mid- and high-density conditions.

Class-agnostic counting on FSC-147

Method Val set Test set
MAE RMSE MAE RMSE
ZSC26.9388.6322.09115.17
CounTX17.1065.6115.88106.29
CountGD12.1447.5114.76120.42
DAVE15.4852.5714.90103.42
CAD-GD13.8064.7412.1599.87
  + C-REX13.8661.0411.9099.65
GroundingDINO9.7155.1110.73103.79
  + C-REX9.4254.7410.04102.35
GroundingREC10.0658.6210.12107.19
  + C-REX9.6654.0712.46104.53

Results on FSC-147 using only textual information (class names) to guide counting. For all models except CAD-GD and GroundingDINO we report results from their original papers. Best results in bold.

BibTeX

@inproceedings{triaridis2026crex,
  title     = {What is the Right Embedding Space for Contrastive Learning in
               Referring Expression Counting?},
  author    = {Triaridis, Kostas and Kaliosis, Panagiotis and Nguyen, E-Ro and
               Xu, Jingyi and Samaras, Dimitris and Le, Hieu},
  booktitle = {European Conference on Computer Vision (ECCV)},
  year      = {2026}
}

Acknowledgements

This research was partially supported by NSF grants IIS-2123920 and IIS-2212046, and by the CCI startup fund at UNC Charlotte.