Manuscript Offprint
arXiv:2610.30912Hierarchical Fine-Grained Cross-Modal Alignment via Dynamic Granularity Discovery and Optimal Transport
Abstract
Fine-grained image-text retrieval requires a model not only to assess global semantic consistency between an image and a text, but also to model visual evidence for local textual semantics, including objects, attributes, quantities, actions, and relations, so as to distinguish semantically similar candidates. Existing methods commonly use fixed image patches, detected regions, or text tokens as the basic matching units and then aggregate local interactions through max pooling, cross attention, or similarity accumulation. Such strategies remain limited in semantic unit construction and global matching consistency. This paper proposes a hierarchical fine-grained cross-modal alignment framework, termed HFCMA. The framework progressively transforms low-level patch and token representations into adaptive visual regions and textual phrases, and then performs structured region-phrase matching within a global retrieval scoring process. Specifically, HFCMA first adopts dynamic granularity discovery (DGD) to aggregate raw patches and tokens into semantically compact visual regions and textual phrases. It then formulates region-phrase matching as an entropy-regularized optimal transport problem, thereby estimating a structured alignment matrix under global marginal constraints. To reduce background noise and local semantic drift, HFCMA further introduces background debiasing, textual importance weighting, and prototype consistency regularization. Experiments on Flickr30K and MS-COCO show that HFCMA effectively combines dynamic semantic unit construction with OT-based structured matching under a dual-encoder retrieval framework. The resulting fine-grained score provides structured local alignment information for candidate ranking and improves the discrimination of subtle semantic differences.
Keywords: Image-text retrieval, Fine-grained cross-modal alignment, Dynamic granularity discovery, Optimal transport, Local semantic representation
1 Introduction
Large-scale image-text contrastive learning has substantially advanced visual-language representation learning. CLIP and ALIGN demonstrate that global alignment over massive image-text pairs can learn transferable multimodal representations [1, 2]. Subsequent work, including ViLBERT, LXMERT, and VL-BERT, improves cross-modal interaction through fusion-style pre-training [3–5]. OSCAR, ALBEF, and X-VLM further introduce object semantics, momentum distillation, and multi-grained visual concepts to strengthen image-text alignment [6–8]. Meanwhile, ViLT, BLIP, BLIP-2, CoCa, and SigLIP extend visual-language pre-training from region-free modeling, generative learning, frozen-encoder bridging, and loss design [9–13]. These advances have moved image-text retrieval from handcrafted features and region matching toward scalable pre-training frameworks.
Despite this progress, fine-grained image-text retrieval remains a weak aspect of current visual-language models. A global vector similarity is efficient for large-scale retrieval, but it is often insufficient when semantically similar candidates must be distinguished. For example, two images may contain the same object categories but differ in number, color, action, or spatial relation. A sentence may also describe only part of a visual scene rather than the whole image. In these cases, a retrieval model needs more reliable cross-modal correspondences at the levels of regions, attributes, and relations. Prior methods such as SCAN, VSR, UNITER, FILIP, SPARC, NAAF, CHAN, MSRM, CORA, and LAPS show that local interaction is important for improving the detailed discrimination of image-text retrieval [14–23].
Existing fine-grained approaches often build local interaction over backbone-produced patches, detector-based regions, tokens, words, or language-guided selected patches, and then design attention, graph reasoning, or similarity aggregation strategies for cross-modal matching. Although these designs improve local discrimination, the construction of matching units is still frequently constrained by fixed tokenization, external detectors, or predefined selection rules. As a result, the semantic granularity of local units may not be fully adaptive to each image-text pair. However, in real image-text pairs, a phrase may correspond to multiple adjacent patches, and a visual region may simultaneously carry object, attribute, and relation cues. If the matching units are semantically fragmented, subsequent local interaction can only partially remedy the mismatch. Recent studies on GroupViT, Slot Attention, TokenLearner, and Token Merging suggest that visual or textual representations can be adaptively organized into more compact semantic units [29–32]. This provides a different perspective for fine-grained retrieval: the matching granularity should not be treated merely as a by-product of the backbone, but should be explicitly modeled.
Local matching also requires global consistency. Max pooling and cross attention often select the most similar local counterpart independently for each element, which may overlook the joint constraint between a set of visual regions and a set of textual phrases. Optimal transport (OT) provides a principled formulation for structured set matching: given marginal distributions, all local correspondences are optimized jointly rather than independently [33, 34]. Although OT has been used in distribution alignment, word mover distance, domain adaptation, and vision-language prompt learning [35–39], how to combine dynamic semantic unit discovery with OT matching for fine-grained image-text retrieval remains under-explored.
Motivated by these observations, this paper proposes HFCMA, a hierarchical fine-grained cross-modal alignment framework. HFCMA addresses two questions: how to adaptively construct suitable visual regions and textual phrases for each image-text sample, and how to establish globally consistent region-phrase matching among these dynamic semantic units. HFCMA adopts a frozen CLIP-style dual encoder as the feature backbone. It first uses a dynamic granularity discovery module to organize patches and tokens into semantically more complete local units. It then solves a structured transport matrix with entropy-regularized OT and combines the resulting fine-grained score with the global similarity for candidate ranking.
The main contributions are summarized as follows.
-
We propose a dynamic granularity discovery mechanism for image-text retrieval, which bridges low-level patch/token representations and higher-level region-phrase semantic units, transforming fixed local matching into sample-adaptive region-phrase alignment.
-
We formulate fine-grained cross-modal matching as entropy-regularized optimal transport over the discovered semantic units, enabling region-phrase correspondences to be jointly optimized under global marginal constraints.
-
We introduce textual importance weighting, background debiasing, and prototype consistency regularization to improve the stability and discriminability of local semantic units.
-
We conduct comprehensive experiments covering standard retrieval, module ablation, matching mechanism comparison, parameter sensitivity, inference efficiency, cross-dataset transfer, and visualization, showing both the effectiveness and the applicable boundary of HFCMA.
2.1 Visual-Language Pre-Training and Image-Text Retrieval
Visual-language pre-training has evolved from fusion-based interaction to dual-encoder contrastive learning. ViLBERT, LXMERT, and VL-BERT jointly encode visual regions and text with cross-modal Transformers and achieve early progress on vision-language tasks [3–5]. OSCAR, UNITER, ALBEF, and X-VLM improve cross-modal semantics through object tags, alignment objectives, momentum distillation, and multi-grained visual concepts [6–8, 17]. These methods provide strong interaction ability, but their pairwise fusion cost is high when many candidates must be evaluated.
CLIP and ALIGN encode images and texts into global vectors, making large-scale retrieval efficient through offline indexing and fast inner-product search [1, 2]. Later models, including BLIP, BLIP-2, CoCa, and SigLIP, strengthen visual-language foundation models through generative pre-training, frozen encoder bridging, contrastive-generative modeling, and sigmoid loss [10–13]. However, the efficiency of dual encoders comes with a compression of local details. Global embeddings may not preserve object position, attribute modification, and relational cues completely. Therefore, this work focuses on enhancing fine-grained alignment while keeping the efficiency advantage of dual-encoder retrieval.
2.2 Fine-Grained Cross-Modal Alignment
Fine-grained image-text matching usually builds local interaction at region-word, patch-token, or phrase-region levels. SCAN models region-word correspondence with stacked cross attention [14]. VSR and GraDual exploit visual or cross-modal graph reasoning for local relation modeling [15, 40]. UNITER introduces word-region alignment objectives [17], while FILIP pushes alignment down to the token level [16]. Recent methods further study negative-aware attention, hard alignment, multilateral semantic relations, compositional relation modeling, and language-guided patch slimming, such as NAAF, CHAN, MSRM, CORA, and LAPS [19–23]. Related studies also explore context-aware attention, graph matching, improved visual semantic reasoning, causal attention, and granularity-aware uncertain region modeling for fine-grained retrieval [24–28].
These studies demonstrate that fine-grained cues are important for distinguishing semantically similar image-text samples. Nevertheless, most methods still regard local matching units as fixed inputs and mainly focus on how to aggregate local similarities. Fine-grained alignment should also answer what units should be matched. If patches or tokens do not form complete semantic units, local interaction may amplify accidental high similarities among fragmented elements. Different from these methods, HFCMA treats local semantic unit construction as an explicit part of retrieval-oriented matching. Instead of only improving the aggregation of local similarities, it first discovers sample-adaptive region and phrase units and then aligns them through a globally constrained transport plan.
2.3 Dynamic Semantic Grouping and Adaptive Representation
Dynamic semantic grouping aims to form compact and semantically coherent representations from low-level features. Slot Attention learns object-centric representations through competitive soft assignment [30]. Set Transformer and Perceiver show that attention-based architectures can process variable-length sets and compress high-dimensional inputs [41–43]. DETR decodes structured detection results with object queries [44]. GroupViT demonstrates that visual patches can gradually form semantic groups under text supervision [29]. TokenLearner and Token Merging reduce redundant representations through adaptive token selection or merging [31, 32].
Most of these methods are designed for detection, segmentation, video understanding, or efficient inference rather than image-text retrieval. These studies motivate adaptive semantic organization, but they are not designed to optimize dynamically grouped units for bidirectional image-text retrieval. HFCMA adapts this idea to retrieval by learning adaptive visual and textual semantic units under image-text supervision and aligning them with OT-based structured matching.
2.4 Optimal Transport and Structured Matching
Optimal transport minimizes the overall transportation cost between sets or distributions and can jointly optimize a matching matrix under marginal constraints. The entropy-regularized formulation and Sinkhorn iteration introduced by Cuturi make OT efficient and differentiable for deep learning [33]. From Earth Mover's Distance to Word Mover's Distance and domain adaptation, OT has become a useful tool for structured alignment [36–39]. In visual-language learning, PLOT applies OT to prompt learning for cross-modal transfer alignment [35].
However, existing OT-based methods are usually applied over fixed-granularity features, where the transport objects are predefined patches, tokens, or prompts. HFCMA places dynamic granularity discovery before OT, so that the transport matrix acts on more compact visual regions and textual phrases. This design improves both the semantic quality of matching units and the global consistency of local alignment.
3 Method
3.1 Problem Definition and Framework
Given an image I and a text T, image-text retrieval learns a matching function such that true image-text pairs receive higher scores than mismatched pairs. A frozen image encoder and a frozen text encoder produce global features and low-level local features:
where denotes patch-level visual features and denotes token-level textual features. Instead of directly matching and , HFCMA first organizes them into semantically more complete visual regions and textual phrases, and then solves a structured cross-modal matching problem. The CLIP-style image and text encoders are kept frozen throughout training. HFCMA only learns lightweight projection layers, dynamic granularity discovery modules, prototype parameters, and score fusion parameters. This preserves the efficiency of dual-encoder retrieval while adding structured local evidence for candidate ranking. In HFCMA, the hierarchical design refers to this progressive pipeline from low-level patch/token representations, to adaptive region-phrase semantic units, and then to structured OT matching combined with global retrieval scoring. Fig. 1 shows the overall framework.
The global similarity is computed as
The fine-grained module produces visual semantic units and textual semantic units , where and are the effective numbers of activated units. The final matching score is

Fig. 1 Overall framework of HFCMA. A frozen CLIP-style dual encoder extracts visual patch and textual token features. Dynamic granularity discovery organizes them into adaptive visual and textual semantic units, followed by visual background debiasing and phrase importance weighting. The refined units are matched by entropy-regularized OT, and the resulting fine-grained score is combined with global CLIP similarity for final image-text retrieval.
where is the OT-based fine-grained score and controls the contribution of local alignment.
3.2 Dynamic Granularity Discovery
The goal of dynamic granularity discovery is to convert fixed patch/token sequences into semantic units closer to visual regions and textual phrases. For the visual branch, the model introduces learnable visual slots . The soft assignment between patch and visual slot is computed by
where and are linear projections and is the assignment temperature. The -th visual semantic unit is obtained by weighted aggregation:
The text branch adopts the same mechanism with textual slots and produces phrase units . Compared with individual tokens, phrase units can better represent entity combinations, attribute modifiers, and relational fragments, such as “two zebras”, “standing next to”, or “on a green field”. Fig. 2 illustrates the conversion from fixed-granularity inputs to dynamic semantic units.

Fig. 2 Illustration of dynamic granularity discovery. Patch and token sequences are softly assigned to learnable visual and phrase slots, producing compact semantic units without requiring bounding-box or phrase-boundary annotations. Sparse and diverse regularization encourages sample-adaptive slot activation and reduces redundant local units.
To control the number of effective slots and reduce repeated semantic responses, a lightweight granularity regularizer is used:
For modality , let denote an input local feature, denote a discovered semantic unit, and denote the corresponding soft assignment. The compactness term is written as
The slot activation is . The sparsity term penalizes high activation entropy,
so that only content-relevant slots remain active. The diversity term reduces repeated slot responses:
Together, these terms encourage compact, selective, and non-redundant semantic units. They serve the retrieval objective and do not require a slot to correspond exactly to a human-annotated region or phrase boundary.

Fig. 3 OT-based structured matching between discovered visual and textual slots. HFCMA builds a cross-modal cost matrix, estimates a transport plan with Sinkhorn iteration under visual and textual marginal constraints, and converts the transport cost into a fine-grained score for reranking together with the global similarity.
3.3 OT-based Structured Region-Phrase Matching
After obtaining visual units V and phrase units P, fine-grained matching is formulated as structured alignment between two semantic sets. The region-phrase cost matrix is defined by cosine distance:
HFCMA then solves an entropy-regularized OT problem:
where denotes the soft matching strength between visual unit k and phrase unit l, a and b are marginal distributions, and controls the smoothness of the transport plan. The base setting normalizes the marginals over active semantic units, and the textual side can be further reweighted by phrase importance as described in Sec. 3.4. The problem is efficiently solved by Sinkhorn iteration, which alternately rescales rows and columns of the transport matrix to satisfy the marginal constraints.
The fine-grained score is defined as the negative transport cost:
Fig. 3 shows the structured matching process. Unlike hard assignment, OT preserves uncertainty in local correspondence. Unlike max pooling, OT reduces the risk that multiple phrases compete for the same highly similar visual region. It is therefore more suitable for many-to-many fine-grained matching.
The main computational cost comes from Sinkhorn matching for candidate pairs. If the number of visual slots is , the number of text slots is , and the number of
Sinkhorn iterations is , the major complexity for a candidate pair is
Because and are much smaller than the original patch/token lengths, the structured matching cost remains moderate and can be used as a lightweight reranking head after dual-encoder retrieval.
3.4 Debiasing, Importance Weighting, and Prototype Consistency
Background co-occurrence may create shortcut correlations in image-text matching. HFCMA therefore introduces a background debiasing term that penalizes high similarity between low-response visual slots and the textual global feature:
where is the aggregated low-response visual unit and is a margin.
Textual importance weighting further emphasizes entity, attribute, quantity, and relation phrases. For the l-th phrase unit, an importance gate is computed as
where is the sigmoid function. The weighted phrase representation is used to construct the region-phrase cost matrix. The normalized weights can also define the textual marginal, , so that informative phrases receive a larger matching budget in the transport plan.
To improve cross-sample stability, a prototype consistency loss, inspired by prototypical representation learning and balanced clustering [45, 46], is imposed over dynamic semantic units:
Here is the predicted prototype distribution and is a balanced stop-gradient target.
3.5 Training Objective and Inference
The full objective is
where is the bidirectional image-text contrastive loss, and maintains consistency between local semantic units and global representations.
During inference, the frozen dual encoder first retrieves a candidate set using the global similarity . HFCMA then applies dynamic granularity discovery and OT-based region-phrase matching only to the candidate pairs, and ranks them by . This design keeps the indexable dual-encoder retrieval pipeline while adding fine-grained local evidence at the reranking stage.
4 Experiments
4.1 Experimental Setup
Experiments are conducted on Flickr30K and MS-COCO [47, 48]. Flickr30K follows the 1K test protocol. MS-COCO is evaluated under both the 5K full test setting and the 1K five-fold average setting. MS-COCO contains diverse and sometimes semantically close captions, a property also discussed in extended caption similarity studies [49]. We report image-to-text (I2T) and text-to-image (T2I) Recall@1, Recall@5, Recall@10, and RSUM, which is the sum of the six recall metrics.
Unless otherwise specified, the backbone is OpenAI CLIP ViT-L/14 and is kept frozen. Only the lightweight HFCMA head is trained. The slot number denotes the number of dynamic semantic units used in DGD. For MS-COCO, the default setting uses 12 visual/text slots, 512 hidden dimensions, 48 prototypes, 15 Sinkhorn iterations, and an OT entropy coefficient of 0.07. For Flickr30K, it uses 8 visual/text slots, 256 hidden dimensions, 32 prototypes, 10 Sinkhorn iterations, and an OT entropy coefficient of 0.10. The experiments are conducted on an NVIDIA A100 GPU.
4.2 Main Retrieval Results
Table 1 shows that HFCMA achieves competitive retrieval performance with a frozen CLIP backbone and a lightweight matching head. On Flickr30K-1K, Full HFCMA obtains an RSUM of 535.78, while HFCMA-Fusion-Calib reaches 542.92. This result is clearly higher than classical and recent baselines such as VSE++, SCAN, VSRN, IMRAM, NAAF, CHAN, HREM, and EISIN, and is close to LAPS. On MS-COCO 1K, HFCMA-Fusion-Calib reaches an RSUM of 532.62, comparable to CHAN and higher than HREM and EISIN. On the larger MS-COCO 5K split, it achieves 442.27, higher than NAAF and EISIN and close to CHAN and HREM.
The advantage of HFCMA is particularly reflected in top-ranked retrieval. For Flickr30K-1K, HFCMA-Fusion-Calib achieves 87.0 I2T R@1, exceeding LAPS at 85.1. This indicates that dynamic semantic units and OT-based matching are effective for determining the most plausible caption when several candidates are globally similar. The reason is not merely an increase in local interaction, but a change in the matching objects and the matching constraint. DGD reduces fragmented patch/token noise by constructing compact region-phrase units, while OT prevents local phrases from independently selecting the same visually salient region. Such structured local evidence is especially useful for R@1, where only the first-ranked candidate matters.
Table 1 Main retrieval results on Flickr30K-1K and MS-COCO.
| Benchmark | Method | I2T | R@1 | R@5R@10T2I | R@1 | R@5R@10RSUM | ||
|---|---|---|---|---|---|---|---|---|
| Flickr30K-1K | VSE++ (2018) [50] | 52.9 | 80.5 | 87.2 | 39.6 | 70.1 | 79.5 | 409.8 |
| SCAN (2018) [14] | 67.4 | 90.3 | 95.8 | 48.6 | 77.7 | 85.2 | 465.0 | |
| VSRN (2019) [15] | 71.3 | 90.6 | 96.0 | 54.7 | 81.8 | 88.2 | 482.6 | |
| IMRAM (2020) [51] | 74.1 | 93.0 | 96.6 | 53.9 | 79.4 | 87.2 | 484.2 | |
| NAAF (2022) [19] | 81.9 | 96.1 | 98.3 | 61.0 | 85.3 | 90.6 | 513.2 | |
| CHAN (2023) [20] | 80.6 | 96.1 | 97.8 | 63.9 | 87.5 | 92.6 | 518.5 | |
| HREM (2023) [52] | 83.3 | 96.0 | 98.1 | 63.5 | 87.1 | 92.4 | 520.4 | |
| LAPS (2024) [23] | 85.1 | 97.7 | 99.2 | 74.0 | 93.0 | 96.3 | 545.3 | |
| EISIN (2025) [53] | 83.3 | 96.2 | 98.3 | 63.6 | 87.3 | 92.0 | 520.7 | |
| Full HFCMA (ours) | 86.6 | 98.3 | 99.4 | 67.6289.28 | 94.58 | 535.78 | ||
| HFCMA-Fusion-Calib (ours) | 87.0 | 98.0 | 99.4 | 72.2091.14 | 95.18 | 542.92 | ||
| MS-COCO 1K | VSE++ (2018) [50] | 64.6 | 90.0 | 95.7 | 52.0 | 84.3 | 92.0 | 478.6 |
| SCAN (2018) [14] | 72.7 | 94.8 | 98.4 | 58.8 | 88.4 | 94.8 | 507.9 | |
| VSRN (2019) [15] | 76.2 | 94.8 | 98.2 | 62.8 | 89.7 | 95.1 | 516.8 | |
| IMRAM (2020) [51] | 76.7 | 95.6 | 98.5 | 61.7 | 89.1 | 95.0 | 516.6 | |
| NAAF (2022) [19] | 80.5 | 96.5 | 98.8 | 64.1 | 90.7 | 96.5 | 527.2 | |
| CHAN (2023) [20] | 81.4 | 96.9 | 98.9 | 66.5 | 92.1 | 96.7 | 532.6 | |
| HREM (2023) [52] | 81.1 | 96.6 | 98.9 | 66.1 | 91.6 | 96.5 | 530.7 | |
| LAPS (2024) [23] | 84.1 | 97.4 | 99.2 | 72.1 | 93.9 | 97.4 | 544.1 | |
| EISIN (2025) [53] | 79.3 | 95.9 | 98.5 | 63.9 | 90.8 | 95.8 | 524.1 | |
| Full HFCMA (ours) | 81.3896.58 | 98.50 | 62.5688.04 | 95.89 | 522.95 | |||
| HFCMA-Fusion-Calib (ours) | 81.7297.50 | 98.82 | 66.1891.52 | 96.88 | 532.62 | |||
| MS-COCO 5K | VSE++ (2018) [50] | 41.3 | 71.1 | 81.2 | 30.3 | 59.4 | 72.4 | 355.7 |
| SCAN (2018) [14] | 50.4 | 82.2 | 90.0 | 38.6 | 69.3 | 80.4 | 410.9 | |
| VSRN (2019) [15] | 53.0 | 81.1 | 89.4 | 40.5 | 70.6 | 81.1 | 415.7 | |
| IMRAM (2020) [51] | 53.7 | 83.2 | 91.0 | 39.7 | 69.1 | 79.8 | 416.5 | |
| NAAF (2022) [19] | 58.9 | 85.2 | 92.0 | 42.5 | 70.9 | 81.4 | 430.9 | |
| CHAN (2023) [20] | 59.8 | 87.2 | 93.3 | 44.9 | 74.5 | 84.2 | 443.9 | |
| HREM (2023) [52] | 62.3 | 87.6 | 93.4 | 43.9 | 73.6 | 83.3 | 444.1 | |
| LAPS (2024) [23] | 67.1 | 88.6 | 94.3 | 53.0 | 79.5 | 87.6 | 470.1 | |
| EISIN (2025) [53] | 59.6 | 84.4 | 91.2 | 42.0 | 72.3 | 82.5 | 432.1 | |
| Full HFCMA (ours) | 64.7885.76 | 91.98 | 46.9370.72 | 79.42 | 439.59 | |||
| HFCMA-Fusion-Calib (ours) | 64.7085.52 | 90.94 | 47.8672.37 | 80.88 | 442.27 |
4.3 Ablation Study
Table 2 verifies the contributions of the main components. On COCO 5K, DGD alone improves RSUM from 390.97 to 407.99, indicating that adaptive semantic units already provide useful local evidence. Adding OT matching further increases RSUM to 425.00, showing that structured region-phrase matching is more effective than merely constructing local units. Debiasing with textual importance weighting and prototype consistency continue to improve the result to 433.74 and 439.59. Similar trends can be observed on COCO 1K and Flickr30K, which confirms the complementarity between semantic unit discovery and structured matching.
4.4 Comparison of Fine-Grained Matching Mechanisms
To directly examine whether a fine-grained mechanism can push correct candidates toward the top of the ranking list, we evaluate candidate promotion. A frozen CLIP
Table 2 Core module ablation results.
| Dataset | Variant | I2T R@1 | T2I R@1 | RSUM | ΔRSUM |
|---|---|---|---|---|---|
| COCO 5K | CLIP baseline | 56.34 | 36.50 | 390.97 | 0.00 |
| COCO 5K | DGD only | 59.29 | 40.15 | 407.99 | +17.02 |
| COCO 5K | + OT matching | 62.25 | 43.80 | 425.00 | +34.03 |
| COCO 5K | + background debiasing | 63.77 | 45.68 | 433.74 | +42.77 |
| COCO 5K | + textual importance weighting | 64.78 | 46.93 | 439.59 | +48.62 |
| COCO 1K | CLIP baseline | 74.22 | 55.44 | 493.13 | 0.00 |
| COCO 1K | DGD only | 76.73 | 57.93 | 503.57 | +10.44 |
| COCO 1K | + OT matching | 79.23 | 60.42 | 514.00 | +20.87 |
| COCO 1K | + background debiasing | 80.52 | 61.71 | 519.37 | +26.24 |
| COCO 1K | + textual importance weighting | 81.38 | 62.56 | 522.95 | +29.82 |
| Flickr30K | CLIP baseline | 85.20 | 64.92 | 525.94 | 0.00 |
| Flickr30K | DGD only | 85.69 | 65.86 | 529.38 | +3.44 |
| Flickr30K | + OT matching | 86.18 | 66.81 | 532.83 | +6.89 |
| Flickr30K | + background debiasing | 86.43 | 67.30 | 534.60 | +8.66 |
| Flickr30K | + textual importance weighting | 86.60 | 67.62 | 535.78 | +9.84 |
Table 3 Candidate promotion success rates (%) of different fine-grained matching mechanisms under the Top-128 candidate pool.
| Dataset | Mechanism | Top10 | Top5 | Top1 | Gain |
|---|---|---|---|---|---|
| Flickr30K | Max pooling | 32.99 | 26.29 | 13.57 | 0.00 |
| Flickr30K | Smooth Chamfer | 36.62 | 27.70 | 14.85 | +3.63 |
| Flickr30K | Hard assignment | 39.74 | 28.48 | 15.75 | +6.75 |
| Flickr30K | OT matching | 43.64 | 31.77 | 17.99 | +10.65 |
| MS-COCO 5K | Max pooling | 25.30 | 20.22 | 12.22 | 0.00 |
| MS-COCO 5K | Smooth Chamfer | 27.93 | 21.76 | 13.02 | +2.63 |
| MS-COCO 5K | Hard assignment | 30.08 | 23.70 | 14.19 | +4.78 |
| MS-COCO 5K | OT matching | 33.71 | 26.54 | 15.39 | +8.41 |
global similarity first produces the initial ranking. Queries whose true matches are already in Top-128 but not yet in Top-10, Top-5, or Top-1 are selected. Different local matching mechanisms are then used to rerank the candidate set. Table 3 and Fig. 4 show that OT matching consistently achieves the highest promotion success rate. The improvement is larger at Top-10 than at Top-1, which is expected because moving a candidate into the first position is more difficult and requires highly reliable global-local consistency.
4.5 Parameter Sensitivity and Inference Efficiency
Table 4 summarizes the sensitivity of six key parameters. Here K denotes the number of dynamic semantic slots rather than a manually defined scale. It has a clear effective range: too few slots compress multiple entities and relations into a small number of units, while too many slots introduce redundancy. The prototype number controls the
Rank-promotion success rates of fine-grained matching mechanisms

OT matching
Hard assignment
Smooth Chamfer
Max pooling
Fig. 4 Candidate promotion success-rate curves under different fine-grained matching mechanisms.
Table 4 Numerical summary of key hyper-parameter sensitivity.
| Parameter | Search range | Points | Recommended value | Best RSUM | Endpoint drop |
|---|---|---|---|---|---|
| Slot number | 1-48 | 14 | Flickr 8, COCO 12 | 535.78 / 522.95 / 439.59 | 67.19 / 85.58 |
| Prototype number | 4-768 | 14 | Flickr 32, COCO 48 | 535.78 / 522.95 / 439.59 | 47.49 / 117.75 |
| OT coefficient | 0.001-1.00 | 14 | Flickr 0.10,COCO 0.07 | 535.78 / 522.95 / 439.59 | 112.55 / 105.68 |
| Sinkhorn steps | 1-50 | 14 | 10-15 | 535.78 / 522.95 / 439.59 | 52.55 / 0.98 |
| Fusion weight | 0.00-1.50 | 16 | 0.10-0.20 | 535.78 / 522.95 / 439.59 | 48.62 / 192.75 |
| Rerank size | 4-1024 | 15 | 128-256 | 535.78 / 522.95 / 439.59 | 52.92 / 7.52 |
capacity of cross-sample semantic priors. The OT entropy coefficient shows a middle-range optimum: a too small value makes the transport plan close to hard matching, while a too large value over-smooths the alignment. Sinkhorn iteration becomes stable after about 10–15 steps. The fusion weight and the reranking size reflect how HFCMA interacts with dual-encoder retrieval. A moderate and a candidate range of 128–256 balance ranking gain and computational cost.
Table 5 Inference efficiency of HFCMA.
| Stage | Candidates | Params (M) | Time (ms) | Memory (MB) |
|---|---|---|---|---|
| CLIP encoding | 0 | 427.62 | 97.01 / 73.12 | 2299.90 |
| HFCMA head | 1 | 1.35 | 0.097 | 2299.90 |
| OT solver | 1 | 0.00 | 0.049 | - |
| Top-64 rerank | 64 | 1.35 | 6.24 | 2299.90 |
| Top-128 rerank | 128 | 1.35 | 12.47 | 2299.90 |
| Top-256 rerank | 256 | 1.35 | 24.94 | 2299.90 |
Table 5 shows that the additional parameters of the HFCMA head are only 1.35M. The per-candidate overhead of the OT solver is small. Even for Top-128 reranking, the extra inference time is about 12.47 ms under the tested setting. Therefore, HFCMA can act as a lightweight fine-grained ranking module after global retrieval.


Fig. 5 Key parameter sensitivity analysis.
4.6 Cross-Dataset Generalization
Table 6 reports cross-dataset transfer results. Training on MS-COCO and testing on Flickr30K brings clear improvements over the CLIP baseline, indicating that the learned region-phrase alignment can transfer to a smaller retrieval benchmark. The reverse direction, from Flickr30K to MS-COCO 5K, is more challenging because the test collection is larger and contains more diverse image-text descriptions. Even in this setting, HFCMA-Fusion-Calib still improves RSUM from 390.86 to 414.44. These
Table 6 Cross-dataset generalization analysis.
| Training set | Test set | Method | I2T R@1 | R@5 | R@10 | T2I R@1 | R@5 | R@10 | RSUM |
|---|---|---|---|---|---|---|---|---|---|
| MS-COCO 5K | Flickr30K | CLIP baseline | 85.10 | 97.40 | 99.20 | 64.90 | 87.28 | 92.00 | 525.88 |
| MS-COCO 5K | Flickr30K | Full HFCMA | 86.40 | 98.30 | 98.70 | 68.04 | 88.66 | 91.88 | 531.98 |
| MS-COCO 5K | Flickr30K | HFCMA-Fusion-Calib | 88.70 | 98.20 | 98.60 | 73.78 | 90.60 | 92.56 | 542.44 |
| Flickr30K | MS-COCO 5K | CLIP baseline | 56.36 | 79.26 | 86.58 | 36.51 | 61.02 | 71.13 | 390.86 |
| Flickr30K | MS-COCO 5K | Full HFCMA | 56.64 | 79.34 | 87.00 | 37.06 | 61.63 | 71.62 | 393.29 |
| Flickr30K | MS-COCO 5K | HFCMA-Fusion-Calib | 58.58 | 81.26 | 88.12 | 43.12 | 67.36 | 76.00 | 414.44 |
results suggest that HFCMA has a certain level of cross-dataset adaptability, while its effect is influenced by differences between training and test distributions.
4.7 Visualization Analysis
Visualization is used to inspect whether HFCMA provides interpretable local evidence. Fig. 6 presents representative ranking-improvement cases. The corrected candidates are visually close to the original CLIP top results, but differ in attributes, quantities, local objects, or spatial relations. The dynamic semantic units make these discriminative fragments explicit, and the OT transport plan assigns them under a global matching constraint. This explains why HFCMA can move some correct candidates from the candidate pool to the top positions.
(a) COCO +: rank 2 -> 1

GT rank: CLIP 2, HFCMA 1, delta 1
A large jetliner sitting on top of an airport runway.
(b) COCO +: rank 2 -> 1
GT rank: CLIP 2, HFCMA 1, delta 1
A baseball player preparing to throw a pitch during a game.
(c) COCO +: rank 3 -> 2
GT rank: CLIP 3, HFCMA 2, delta 1
A table with a coffee and a salad on it.
(d) Flickr30K +: rank 3 -> 1

GT rank: CLIP 3, HFCMA 1, delta 2
Two blond women sit outside as people walk by wearing casual clothing and some wearing bookbags.
(e) Flickr30K +: rank 4 -> 2
GT rank: CLIP 4, HFCMA 2, delta 2
Four police officers are swallowed up by the large crowd of people on the street.
(f) Flickr30K +: rank 3 -> 2
GT rank: CLIP 3, HFCMA 2, delta 1
A construction worker is driving heavy equipment at a work site.
Fig. 6 Visualization of ranking-improvement cases.
Fig. 7 shows the local alignment evidence behind the ranking changes. Active visual slots tend to cover semantically meaningful regions, while textual slots correspond to phrases involving objects, attributes, and relations. The transport matrix concentrates on plausible region-phrase pairs while retaining soft uncertainty, which is consistent with the role of OT as a structured many-to-many matching mechanism.
Dynamic slots and OT transport: effective alignments and failure boundaries
(a) COCO +: rank 2 -> 1
A large jetliner sitting on top of an airport runway.
query image

slot 1
slot 2
OT transport

(b) Flickr30K +: rank 4 -> 2
Four police officers are swallowed up by the large crowd of people on the street.
query image
slot 1
slot 2
OT transport

(c) COCO -: rank 1 -> 21
A row of motorcycles parked in front of a building.
query image
slot 1
slot 2
OT transport

(d) Flickr30K -: rank 1 -> 2
A young female student performing a downward kick to break a board held by her Karate instructor.
query image
slot 1
slot 2
OT transport


Fig. 7 Dynamic visual slots and local alignment evidence from the OT transport matrix.
Fig. 8 further reports ranking-degradation and failure cases. These examples usually contain crowded scenes, overlapping objects, weakly localized attributes, or near-duplicate candidates. In such cases, dynamic slots may respond to background or visually salient but semantically irrelevant regions, and the transport plan may amplify this imperfect local evidence. The failure analysis indicates that HFCMA is most reliable when the caption contains local cues that can be grounded by stable region-phrase correspondences.
5 Discussion
The experimental results indicate that the core issue in fine-grained image-text retrieval is not only how to aggregate local similarities, but also what local units should be matched. Fixed patches and tokens are computationally convenient, but they are not always consistent with semantic units. Dynamic granularity discovery organizes local features into compact visual regions and textual phrases, allowing subsequent
(a) COCO -: rank 1 -> 21

GT rank: CLIP 1, HFCMA 21, delta -20
A row of motorcycles parked in front of a building.
(b) COCO -: rank 1 -> 81
GT rank: CLIP 1, HFCMA 81, delta -80
Black and white photograph of two men on motorcycles.
(c) COCO -: rank 37 -> 160
GT rank: CLIP 37, HFCMA 160, delta -123
The bathroom is clean and ready to be used.
(d) Flickr30K -: rank 1 -> 2

GT rank: CLIP 1, HFCMA 2, delta -1
A young female student performing a downward kick to break a board held by her Karate instructor.
(e) Flickr30K -: rank 1 -> 2
GT rank: CLIP 1, HFCMA 2, delta -1
A softball player dressed in a maroon and gold uniform, at home plate with a catcher and umpire, prepares to run after hitting the ball.
(f) Flickr30K -: rank 1 -> 2
GT rank: CLIP 1, HFCMA 2, delta -1
A mountaineer about to descend down a mountain with a blue helmet on.
Fig. 8 Visualization of ranking-degradation and failure cases.
matching to operate on units that better represent entities, attributes, and relations. OT matching further places these units under a unified transport constraint, avoiding independent local maximum selection. In this sense, the hierarchical nature of HFCMA lies in the progressive transition from low-level patch/token features through adaptive region-phrase semantic units to structured cross-modal matching combined with global retrieval scoring.
The ablation results provide the most direct structural evidence: DGD brings stable improvement, OT strengthens structured matching, and auxiliary regularization further improves stability. Fusion and calibration are useful in practical retrieval because local fine-grained scores should cooperate with global semantic anchors rather than replace them. This point is important for large-scale datasets such as MS-COCO, where many candidates are visually or semantically close.
Several limitations remain. First, dynamic slots are not explicit detection boxes or segmentation masks, and semantic drift may occur in crowded scenes, occlusion, or near-duplicate objects. Second, calibration depends on the candidate distribution and should be fixed by validation protocols rather than repeatedly tuned on the test set. Third, different CLIP backbones may influence the gain of the fine-grained head. Finally, current experiments focus on English short-text retrieval benchmarks, whose brittleness and evaluation sensitivity have also been noted in recent benchmark analyses . Future work may extend the framework to multilingual descriptions, long-form narratives, and noisy open-domain image-text collections.
6 Conclusion
This paper proposes HFCMA, a hierarchical fine-grained cross-modal alignment framework for image-text retrieval. The method adaptively constructs visual regions and textual phrases through dynamic granularity discovery, and solves a globally constrained region-phrase transport matrix with entropy-regularized optimal transport. Compared with methods that rely on fixed patches/tokens and heuristic local aggregation, HFCMA improves both the matching units and the matching mechanism.
Experiments on Flickr30K and MS-COCO show that HFCMA can enhance retrieval performance under a frozen CLIP dual-encoder framework with only a lightweight additional head. Ablation, matching mechanism comparison, parameter sensitivity, efficiency analysis, cross-dataset generalization, and visualization further verify the complementary role of dynamic semantic unit construction and OT-based structured matching. The main conclusion is that adaptive semantic unit construction combined with structured set matching provides a feasible path for improving fine-grained discrimination in image-text retrieval.
Acknowledgements
This work was supported by the Zhejiang Provincial Natural Science Foundation of China (Grant No. LY23G020007).
Competing Interests
The authors declare that they have no competing interests.
Data and Code Availability
The Flickr30K and MS-COCO datasets used in this study are publicly available from their respective providers. The HFCMA code is available at https://github.com/sungkites/HFCMA.
References
[1] Radford A, Kim J W, Hallacy C, et al. Learning transferable visual models from natural language supervision. In: Proceedings of the International Conference on Machine Learning, 2021: 8748–8763.
[2] Jia C, Yang Y, Xia Y, et al. Scaling up visual and vision-language representation learning with noisy text supervision. In: Proceedings of the International Conference on Machine Learning, 2021.
[3] Lu J, Batra D, Parikh D, et al. ViLBERT: Pretraining task-agnostic visiolinguistic representations for vision-and-language tasks. In: Advances in Neural Information Processing Systems, 2019.
[4] Tan H, Bansal M. LXMERT: Learning cross-modality encoder representations from transformers. In: Proceedings of EMNLP-IJCNLP, 2019.
[5] Su W, Zhu X, Cao Y, et al. VL-BERT: Pre-training of generic visual-linguistic representations. In: International Conference on Learning Representations, 2020.
[6] Li X, Yin X, Li C, et al. OSCAR: Object-semantics aligned pre-training for vision-language tasks. In: Proceedings of the European Conference on Computer Vision, 2020: 121–137.
[7] Li J, Selvaraju R R, Gotmare A D, et al. Align before fuse: Vision and language representation learning with momentum distillation. In: Advances in Neural Information Processing Systems, 2021: 9694–9705.
[8] Zeng Y, Zhang X, Li H. Multi-grained vision language pre-training: Aligning texts with visual concepts. In: Proceedings of the International Conference on Machine Learning, 2022: 25994–26009.
[9] Kim W, Son B, Kim I. ViLT: Vision-and-language transformer without convolution or region supervision. In: Proceedings of the International Conference on Machine Learning, 2021: 5583–5594.
[10] Li J, Li D, Xiong C, et al. BLIP: Bootstrapping language-image pre-training for unified vision-language understanding and generation. In: Proceedings of the International Conference on Machine Learning, 2022: 12888–12900.
[11] Li J, Li D, Savarese S, et al. BLIP-2: Bootstrapping language-image pre-training with frozen image encoders and large language models. In: Proceedings of the International Conference on Machine Learning, 2023: 19730–19742.
[12] Yu J, Wang Z, Vasudevan V, et al. CoCa: Contrastive captioners are image-text foundation models. arXiv:2205.01917, 2022.
[13] Zhai X, Mustafa B, Kolesnikov A, et al. Sigmoid loss for language image pre-training. In: Proceedings of the IEEE/CVF International Conference on Computer Vision, 2023: 11975–11986.
[14] Lee K H, Chen X, Hua G, et al. Stacked cross attention for image-text matching. In: Proceedings of the European Conference on Computer Vision, 2018: 201–216.
[15] Li K, Zhang Y, Li K, et al. Visual semantic reasoning for image-text matching. In: Proceedings of the IEEE/CVF International Conference on Computer Vision, 2019: 4654–4662.
[16] Yao L, Huang R, Hou L, et al. FILIP: Fine-grained interactive language-image pre-training. In: International Conference on Learning Representations, 2022.
[17] Chen Y C, Li L, Yu L, et al. UNITER: Universal image-text representation learning. In: Proceedings of the European Conference on Computer Vision, 2020: 104–120.
[18] Bica I, Ilic A, Bauer M, et al. Improving fine-grained understanding in image-text pre-training. In: Proceedings of the International Conference on Machine Learning, 2024: 3974–3995.
[19] Zhang K, Mao Z, Wang Q, et al. Negative-aware attention framework for image-text matching. In: Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, 2022: 15661–15670.
[20] Pan Z, Wu F, Zhang B. Fine-grained image-text matching by cross-modal hard aligning network. In: Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, 2023: 19275–19284.
[21] Wang Z, Gao Z, Guo K, et al. Multilateral semantic relations modeling for image text retrieval. In: Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, 2023: 2830–2839.
[22] Pham K, Huynh C, Lim S N, et al. Composing object relations and attributes for image-text matching. In: Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, 2024: 14354–14363.
[23] Fu Z, Zhang L, Xia H, et al. Linguistic-aware patch slimming framework for fine-grained cross-modal alignment. In: Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, 2024: 26307–26316.
[24] Zhang Q, Lei Z, Zhang Z, Li S Z. Context-aware attention network for image-text retrieval. In: Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, 2020: 3536–3545.
[25] Cheng Y, Zhu X, Qian J, Wen F, Liu P. Cross-modal graph matching network for image-text retrieval. ACM Transactions on Multimedia Computing, Communications, and Applications, 2022, 18: 1–23.
[26] Yuan H, Huang Y, Zhang D, Chen Z, Cheng W, Wang L. VSR++: Improving visual semantic reasoning for fine-grained image-text matching. In: Proceedings of the International Conference on Pattern Recognition, 2021.
[27] Yang X, Zhang H, Qi G, et al. Causal attention for vision-language tasks. In: Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, 2021: 9847–9857.
[28] Liu J, Zhou H, Liu Y, et al. Cross-modal fine-grained alignment via granularity-aware and region-uncertain modeling. In: Proceedings of the AAAI Conference on Artificial Intelligence, 2026.
[29] Xu J, De Mello S, Liu S, et al. GroupViT: Semantic segmentation emerges from text supervision. In: Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, 2022: 18134–18144.
[30] Locatello F, Weissenborn D, Unterthiner T, et al. Object-centric learning with slot attention. In: Advances in Neural Information Processing Systems, 2020.
[31] Ryoo M S, Piergiovanni A, Arnab A, et al. TokenLearner: Adaptive space-time tokenization for videos. In: Advances in Neural Information Processing Systems, 2021: 12786–12797.
[32] Bolya D, Fu C Y, Dai X, et al. Token merging: Your ViT but faster. In: International Conference on Learning Representations, 2023.
[33] Cuturi M. Sinkhorn distances: Lightspeed computation of optimal transport. In: Advances in Neural Information Processing Systems, 2013: 2292–2300.
[34] Peyre G, Cuturi M. Computational optimal transport. Foundations and Trends in Machine Learning, 2019, 11(5–6): 355–607.
[35] Chen G, Yao W, Song X, et al. PLOT: Prompt learning with optimal transport for vision-language models. In: International Conference on Learning Representations, 2023.
[36] Rubner Y, Tomasi C, Guibas L J. The earth mover's distance as a metric for image retrieval. International Journal of Computer Vision, 2000, 40(2): 99–121.
[37] Kusner M J, Sun Y, Kolkin N I, et al. From word embeddings to document distances. In: Proceedings of the International Conference on Machine Learning, 2015: 957–966.
[38] Courty N, Flamary R, Tuia D, et al. Optimal transport for domain adaptation. IEEE Transactions on Pattern Analysis and Machine Intelligence, 2017, 39(9): 1853–1865.
[39] Damodaran B B, Kellenberger B, Flamary R, et al. DeepJDOT: Deep joint distribution optimal transport for unsupervised domain adaptation. In: Proceedings of the European Conference on Computer Vision, 2018: 447–463.
[40] Long S, Han S C, Wan X, et al. GraDual: Graph-based dual-modal representation for image-text matching. In: Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision, 2022: 3459–3468.
[41] Lee J, Lee Y, Kim J, et al. Set transformer: A framework for attention-based permutation-invariant neural networks. In: Proceedings of the International Conference on Machine Learning, 2019: 3744–3753.
[42] Jaegle A, Gimeno F, Brock A, et al. Perceiver: General perception with iterative attention. In: Proceedings of the International Conference on Machine Learning, 2021: 4651–4664.
[43] Jaegle A, Borgeaud S, Alayrac J B, et al. Perceiver IO: A general architecture for structured inputs and outputs. In: International Conference on Learning Representations, 2022.
[44] Carion N, Massa F, Synnaeve G, et al. End-to-end object detection with transformers. In: Proceedings of the European Conference on Computer Vision, 2020.
[45] Snell J, Swersky K, Zemel R S. Prototypical networks for few-shot learning. In: Advances in Neural Information Processing Systems, 2017.
[46] Caron M, Misra I, Mairal J, et al. Unsupervised learning of visual features by contrasting cluster assignments. In: Advances in Neural Information Processing Systems, 2020.
[47] Plummer B A, Wang L, Cervantes C M, et al. Flickr30k Entities: Collecting region-to-phrase correspondences for richer image-to-sentence models. In: Proceedings of the IEEE International Conference on Computer Vision, 2015.
[48] Lin T Y, Maire M, Belongie S, et al. Microsoft COCO: Common objects in context. In: Proceedings of the European Conference on Computer Vision, 2014.
[49] Parekh Z, Baldridge J, Cer D, et al. Crisscrossed captions: Extended intramodal and intermodal semantic similarity judgments for MS-COCO. Transactions of the Association for Computational Linguistics, 2021, 9: 318–333.
[50] Faghri F, Fleet D J, Kiros J R, et al. VSE++: Improving visual-semantic embeddings with hard negatives. In: Proceedings of the British Machine Vision Conference, 2018: 12.1–12.13.
[51] Chen H, Ding G, Liu X, Lin Z, Liu J, Han J. IMRAM: Iterative matching with recurrent attention memory for cross-modal image-text retrieval. In: Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, 2020:
12655–12663.
[52] Fu Z, Mao Z, Song Y, Zhang Y. Learning semantic relationship among instances for image-text matching. In: Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, 2023: 15159–15168.
[53] Peng S, Wang Z, Liu J, Zhang C, Jia L. Fine-grained local and global semantic fusion for multimodal image-text retrieval. Big Data and Cognitive Computing, 2025, 9(3): 53.
[54] Hendriksen M, Odijk D, de Rijke M. Assessing brittleness of image-text retrieval benchmarks. arXiv:2407.15239, 2024.