|
Download README.md from Kiriti-Ray/binding-clip: direct link, hf CLI and curl.
- Browser
- Download file 12.1 kB
-
https://huggingface.co/Kiriti-Ray/binding-clip/resolve/main/README.md
- Command line
-
hf download hf://Kiriti-Ray/binding-clip/README.md
-
curl -L -o README.md https://huggingface.co/Kiriti-Ray/binding-clip/resolve/main/README.md
12.1 kB
| license: mit | |
| tags: | |
| - image-text | |
| - compositional-generalization | |
| - caption-ranking | |
| - clevr | |
| library_name: pytorch | |
| # BindingCLIP | |
| **Does a model still match captions to images when familiar colors and shapes appear in new combinations?** We trained four compact models from scratch on one M5 Max MacBook Pro to find out. On a disjoint CLEVR-CoGenT split, the **977,451-parameter factorized model ranked the correct caption above both alternatives 86.1% of the time**, compared with 40.5% for the model that learned region-pair scores. The learned-pair model led on the original color–shape distribution. | |
| [Results](#results) · [Example](#worked-example) · [Method](#method) · [Reproduce](#reproduce-the-experiment) · [GitHub](https://github.com/Kiriti96-Ray/binding-clip) · [Hugging Face weights](https://huggingface.co/Kiriti-Ray/binding-clip/tree/v0.1.0) | |
|  | |
| ## Results | |
| Each example pairs one image with a true caption, a **color swap** that exchanges the two colors, and a **spatial flip** that reverses left and right. Joint accuracy counts an example only if the true caption strictly outranks both alternatives. Condition A supplies training data and selects checkpoints. The first condition B slice informed the factorized design. The disjoint condition B slice was evaluated after the checkpoints were fixed. | |
| | Variant | Parameters | Condition A | First condition B | Disjoint condition B | | |
| | :--- | ---: | ---: | ---: | ---: | | |
| | Global | 1,026,689 | 39.5% | 13.5% | 14.5% | | |
| | Unary | 1,067,905 | 41.2% | 15.8% | 17.3% | | |
| | Learned pair | 1,082,529 | **93.9%** | 39.9% | 40.5% | | |
| | Factorized pair | **977,451** | 88.8% | **86.2%** | **86.1%** | | |
| On disjoint condition B, the factorized model gained **45.5 percentage points** over the learned-pair model. The 95% paired interval is **+43.5 to +47.8 points**, from 1,000 bootstrap resamples of images. Each resample keeps the comparisons from the same image together. The gap on condition A was **−5.1 points**. These intervals measure variation across evaluation images for the given checkpoints. [Condition A](reports/valA.json) · [First condition B](reports/valB.json) · [Disjoint condition B](reports/valB-offset1000.json) | |
| ### What changed under the shift | |
| | Variant | Color swap | Spatial flip | Joint, different shapes only | Joint, all comparisons (95% interval) | | |
| | :--- | ---: | ---: | ---: | ---: | | |
| | Global | 25.7% | 51.3% | 8.0% | 14.5% (13.3–15.7%) | | |
| | Unary | 33.4% | 49.8% | 12.7% | 17.3% (16.1–18.5%) | | |
| | Learned pair | 46.7% | 80.1% | 24.9% | 40.5% (38.6–42.3%) | | |
| | Factorized pair | **87.7%** | **94.4%** | **83.0%** | **86.1%** (84.6–87.5%) | | |
| - **Ordered regions helped with spatial flips.** Disjoint condition B accuracy rose from 49.8% for independent phrase matching to 80.1% for the learned-pair model. Color swaps remained the weaker comparison. | |
| - **Factorization made the largest difference on color swaps.** Accuracy on those comparisons increased from 46.7% to 87.7%. The model also reached 83.0% joint accuracy across 2,463 comparisons in which the objects had different shapes. When two objects share a shape, swapping their colors and reversing their positions can express the same alternative. [Disjoint results and paired comparisons](reports/valB-offset1000.json) | |
| ## Worked example | |
|  | |
| The ground-truth caption is **“a brown cylinder left of a purple cube.”** The learned-pair model ranks the color-swapped caption first in this scene. The factorized model ranks the true caption first. The markers are the model’s highest-scoring patch centers for the two phrases in the true caption. Rank within an image is the comparison here because the variants use different scoring functions. [Sample scene](examples/cogent-valB.png) · [Candidate captions](examples/captions.json) · [Factorized output](examples/factorized-ranking.json) · [Learned-pair output](examples/learned-pair-ranking.json) | |
| ## Method | |
| BindingCLIP takes its region-to-phrase motivation from PowerCLIP. This study focuses on two-object captions with explicit spatial relations and uses CLEVR scene annotations to supervise localization during training. At inference, models take only an image and the candidate captions. [PowerCLIP, CVPR 2026](https://openaccess.thecvf.com/content/CVPR2026/papers/Kawamura_PowerCLIP_Powerset_Alignment_for_Contrastive_Pre-Training_CVPR_2026_paper.pdf) | |
| | Checkpoint | How the score is computed | | |
| | :--- | :--- | | |
| | `global/` | Compare pooled visual features with the full caption embedding. | | |
| | `unary/` | Add independent per-phrase region scores to the global score. | | |
| | `pair/` | Add a joint score over ordered pairs of distinct regions. A learned function scores signed image offsets conditioned on the two phrases and the relation token. | | |
| | `factorized/` | Predict color from RGB patches and shape from grayscale patches. Combine the separate log probabilities for each phrase, then aggregate over ordered patch pairs that satisfy the caption’s left/right relation. | | |
| The first three models share a convolutional stem, a four-layer vision transformer, and a caption encoder. The factorized model uses a grayscale stem and four-layer transformer for shape, a small RGB convolutional branch for color, and an image-coordinate constraint for the relation. Grounded variants score a **6 × 6 grid**. The factorized constraint compares the horizontal coordinates of the two patch centers. [Embedding models](binding_clip/model.py) · [Factorized model](binding_clip/factorized.py) | |
| All models minimize cross-entropy over the three candidate captions. The grounded variants also match their phrase heatmaps to soft targets centered on the annotated objects. The factorized variant adds supervised color and shape losses around those centers. The unary-to-learned-pair comparison keeps the grounding objective fixed. The factorized comparison changes both the architecture and auxiliary supervision. [Training implementation](binding_clip/train.py) | |
| ### Data and protocol | |
| | Slice | Archived images sampled | Usable scenes | Caption comparisons | | |
| | :--- | ---: | ---: | ---: | | |
| | Train A | 6,000 | 5,616 | One per usable scene per epoch | | |
| | Validation A | 1,000 | 929 | 3,508 | | |
| | First validation B | 1,000 | 955 | 3,654 | | |
| | Disjoint validation B | 1,000 | 940 | 3,550 | | |
| CoGenT swaps the cube and cylinder color palettes between conditions A and B. Within each scene, the comparison generator takes left/right order from image-plane coordinates. It filters ambiguous object descriptions and excludes candidates that describe another valid pairing in the scene. Evaluation uses up to four deterministic comparisons per image. The two condition B samples use consecutive, non-overlapping 1,000-image slices in archive order. [Dataset](https://cs.stanford.edu/people/jcjohns/clevr/) · [Split manifests](reports/manifests) · [Protocol JSON](reports/protocol.json) | |
| ### Local training | |
|  | |
| | Setting | Release configuration | | |
| | :--- | :--- | | |
| | Hardware and framework | Apple M5 Max, 48 GB unified memory, PyTorch 2.13.0 on Metal/MPS | | |
| | Inputs | 96 × 96 RGB images, fixed vocabulary of eight colors, three shapes, and two relations | | |
| | Optimizer | AdamW, learning rate 0.0007, weight decay 0.04, 5% warmup followed by cosine decay | | |
| | Run | Seed 42, batch size 48, 12 epochs per variant | | |
| | Auxiliary loss weights | Grounded variants use 0.35 for localization. Factorized also uses 1.0 for attribute prediction. | | |
| | Checkpoint selection | Highest condition A validation joint accuracy. Epochs 10, 12, 12, and 11 for global, unary, learned pair, and factorized, respectively. | | |
| The training loops, including validation each epoch, took roughly **42–56 seconds per variant** on this machine. Those timings start after dataset loading. [Training histories and timing logs](reports) | |
| ## Reproduce the experiment | |
| ### Try the released model | |
| Use Python 3.11 or newer. The `v0.1.0` checkpoint tag fixes the exact weights. | |
| ```sh | |
| git clone https://github.com/Kiriti96-Ray/binding-clip.git | |
| cd binding-clip | |
| python -m venv .venv | |
| . .venv/bin/activate | |
| python -m pip install -e . | |
| python -m binding_clip.infer --hub Kiriti-Ray/binding-clip --revision v0.1.0 \ | |
| examples/cogent-valB.png \ | |
| 'a brown cylinder left of a purple cube' \ | |
| 'a purple cylinder left of a brown cube' \ | |
| 'a brown cylinder right of a purple cube' | |
| ``` | |
| The Hub command defaults to `factorized/`. Choose another variant with `--subfolder global`, `--subfolder unary`, or `--subfolder pair`. For local weights, provide `--checkpoint PATH` to a directory containing `config.json` and `model.safetensors`. The output ranks captions for the given image and includes normalized top-left-origin coordinates where region scores are available. [Hub checkpoints](https://huggingface.co/Kiriti-Ray/binding-clip/tree/v0.1.0) · [GitHub checkpoint archive](https://github.com/Kiriti96-Ray/binding-clip/releases/tag/v0.1.0) | |
| ### Train and evaluate | |
| ```sh | |
| python -m binding_clip.download data/cogent --train-images 6000 --validation-images 1000 | |
| python -m binding_clip.train data/cogent runs/v0.1 --device auto --epochs 12 \ | |
| --batch-size 48 --seed 42 --evaluate-val-b | |
| python -m binding_clip.evaluate data/cogent runs/v0.1 --split valA --device auto | |
| python -m binding_clip.evaluate data/cogent runs/v0.1 --split valB --device auto | |
| python -m binding_clip.download data/cogent-confirmation --train-images 0 \ | |
| --validation-images 1000 --validation-offset 1000 | |
| python -m binding_clip.evaluate data/cogent-confirmation runs/v0.1 --split valB --device auto | |
| python -m unittest discover -s tests -v | |
| ``` | |
| The downloader fetches byte ranges from the official ZIP and keeps both the cache and extracted files. The initial data transfer is about 1.6 GB and the disjoint evaluation command needs about 0.4 GB more. For an existing extracted archive, place the relevant released filename manifests at the archive root as `trainA.txt`, `valA.txt`, or `valB.txt` as appropriate. To reproduce the figures, install Matplotlib and run `python reports/render_figures.py`. [Manifests](reports/manifests) · [Figure code](reports/render_figures.py) | |
| ## Scope and limitations | |
| - This release measures ranking on synthetic CLEVR scenes with a fixed caption grammar. Performance on natural images, open-ended captions, and relations beyond left/right is unmeasured. | |
| - One training seed was used. The paired bootstrap measures image-level uncertainty in the released benchmark. Run-to-run variance is unmeasured. | |
| - The factorized variant combines RGB and grayscale branches, auxiliary attribute supervision, and explicit geometry. This experiment estimates their combined effect. The contribution of each individual design change is unmeasured. | |
| ## Credits | |
| BindingCLIP adapts ideas from *PowerCLIP: Powerset Alignment for Contrastive Pre-Training* by Masaki Kawamura, Nakamasa Inoue, Rintaro Yanagi, Hirokatsu Kataoka, and Rio Yokota. CLEVR and CLEVR-CoGenT are by Justin Johnson, Bharath Hariharan, Laurens van der Maaten, Li Fei-Fei, C. Lawrence Zitnick, and Ross Girshick. The worked example and annotated figure use CLEVR’s `CLEVR_valB_013012.png` under CC BY 4.0. BindingCLIP code and weights use the MIT license. [PowerCLIP paper](https://openaccess.thecvf.com/content/CVPR2026/papers/Kawamura_PowerCLIP_Powerset_Alignment_for_Contrastive_Pre-Training_CVPR_2026_paper.pdf) · [CLEVR project](https://cs.stanford.edu/people/jcjohns/clevr/) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · [MIT license](LICENSE) | |