Paper commentary
Conditional Prompt Learning for Vision-Language Models
Conditional prompt learning fixes CoOp's poor generalization to unseen classes
- Problem CoOp's learned prompts overfit base classes and fail on unseen classes.
- Method CoCoOp adds an image-conditioned vector to each of CoOp's shared context vectors. A small Meta-Net built from the image encoder's features produces that vector, and only the context vectors and Meta-Net are trained while CLIP stays frozen.
- Results CoCoOp reaches a 75.83 harmonic mean over 11 datasets in base-to-new evaluation, against 71.66 for CoOp and 71.70 for CLIP with manual prompts.
Why a fixed learned prompt fails on new classes
CoOp replaces the hand-written words of a CLIP prompt with learnable context vectors, so a few labeled images can tune the prompt instead of manual trial and error. The authors find that these context vectors do not generalize to classes that were absent from training but belong to the same dataset, which indicates that CoOp fits the base classes it saw during training.
Averaged over 11 datasets under 16 shots, CoOp's base accuracy is 82.69 while its new-class accuracy is 63.22, so the gain on base classes is largely lost on unseen classes.
Making the prompt depend on the image
CoCoOp keeps CoOp's M shared context vectors and adds an input-dependent part to each of them, so the prompt for a given image is no longer fixed. Giving each context token its own network would multiply the network size by M, so the authors instead train a single lightweight network, Meta-Net, that outputs one conditional vector for each image.
Meta-Net is a two-layer bottleneck with a Linear-ReLU-Linear structure whose hidden layer cuts the input dimension by 16 times, and its input is simply the features the image encoder produces. Each context token becomes \( v_m(x) = v_m + \pi \) with \( \pi = h_\theta(x) \), where \( h_\theta \) is Meta-Net with parameters \( \theta \), so the prompt for class i is conditioned on the input image x.
What is trained and how prediction works
Training updates only the context vectors and Meta-Net's parameters, using a cross-entropy objective, while the CLIP model stays fixed. At prediction time, the prompt for every class is built from the same image's conditional vector, passed through the text encoder, and compared with the image feature by cosine similarity to give class probabilities.
Because each image yields its own set of prompts, the text encoder must process prompts per image rather than once per mini-batch, which is the source of the cost discussed under limitations.
Experimental setup and fixed choices
CoCoOp is trained with a batch size of 1 for 10 epochs, because the instance-conditional design needs much more GPU memory and time than CoOp.
Base-to-new results over 11 datasets
Each dataset's classes are split into equal base and new halves, CoOp and CoCoOp are trained on base classes only, and both are tested on each half. Averaged over the 11 datasets, CoCoOp's new-class accuracy is 71.69, up from 63.22 for CoOp, while its base accuracy falls from 82.69 to 80.47. Its harmonic mean is 75.83, compared with 71.66 for CoOp and 71.70 for CLIP with manual prompts, so the balance between base and new classes is better than either baseline.
Base losses and where new-class gains come from
On ImageNet, new-class accuracy rises from 67.88 for CoOp to 70.43 for CoCoOp, which is above CLIP's 68.14. CoCoOp's base accuracy is below CoOp's on 9 datasets, and on 6 of those 9 the drop is under 3 percent. The largest base drop is on StanfordCars, at -7.63, but its new-class gain of +13.19 gives the authors a net improvement of 5.56 for CoCoOp on that dataset.
CoCoOp's new-class accuracy is higher than CLIP's on 4 of the 11 datasets, namely ImageNet, OxfordPets, Food101 and SUN397, and the gap remains large on FGVCAircraft.
Transfer from ImageNet to other datasets
Prompts learned on ImageNet with all 1,000 classes are applied directly to the other 10 datasets, and only prompt-learning methods are compared in this setting. The average over the 10 target datasets is 65.74 for CoCoOp and 63.88 for CoOp, with the source ImageNet accuracy at 71.02 and 71.51 respectively.
Domain generalization on ImageNet variants
The prompt is learned on ImageNet and tested on ImageNetV2, ImageNet-Sketch, ImageNet-A and ImageNet-R, with manual CLIP prompts as the zero-shot reference. CoCoOp scores 64.07 on ImageNetV2 against 64.20 for CoOp, which is slightly lower, and it scores higher on the other three: 48.75 against 47.99 on ImageNet-Sketch, 50.63 against 49.71 on ImageNet-A, and 76.18 against 75.21 on ImageNet-R.
Both learned methods are above the CLIP row on all four targets.
Initialization, context length and parameter count
The initialization study compares word-embedding initialization with random initialization from a zero-mean Gaussian with 0.02 standard deviation, while keeping the other parameters the same. Averaged over the 11 datasets, proper initialization helps both base and new classes, and the authors note that individual datasets may differ. With random initialization, context lengths of 4, 8 and 16 are compared; longer contexts mainly help the new classes, and 8 random tokens are marginally better than 4 properly initialized ones.
On ImageNet, a 60-token CoOp with 30,720 parameters reaches 70.34 harmonic mean, against 71.92 for the 4-token CoOp with 2,048 parameters and 73.10 for the 4-token CoCoOp with Meta-Net and 34,816 parameters.
DOSCO-2k results across four backbones
DOSCO-2k has seven datasets whose domain labels come from a network pre-trained on Places, and each dataset has 2,000 images in total, split 1,600 for training and 400 for validation. Both CoOp and CoCoOp use four learnable context tokens, and the checkpoint with the best validation performance is used for the test in unseen domains. With ViT-B/16, CLIP averages 67.2, CoOp averages 73.3 and CoCoOp averages 72.7, so CoCoOp is lower on average.
Limitations
CoCoOp is slow to train and uses a large amount of GPU memory when the batch size exceeds one, because each image needs its own forward pass of instance-specific prompts through the text encoder. CoOp needs only one forward pass for a mini-batch of any size, so the per-image cost is the central efficiency gap between the two methods. On 7 of the 11 datasets, CoCoOp's new-class accuracy still lags behind CLIP's, so the gap to manual prompts is not closed.
Paper info
- Authors
- Kaiyang Zhou, Jingkang Yang, Chen Change Loy, Ziwei Liu
- Venue
- arXiv · Preprint
- First published
- 2022-3-10
- Added
- 2026-11-12
- Updated
- 2022-10-6
- Version
- v2
- arXiv
- 2203.05557
- Category
- cs.CV · cs.AI · cs.CL · cs.LG
- Original paper terms
- arXiv non-exclusive 1.0
- What we show
- Paper info and commentary
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Quote from the paper
Kaiyang Zhou, Jingkang Yang, Chen Change Loy, Ziwei Liu (2022). Conditional Prompt Learning for Vision-Language Models. arXiv:2203.05557v2. https://arxiv.org/abs/2203.05557v2
BibTeX
@misc{zhou2022conditional,
title = {{Conditional Prompt Learning for Vision-Language Models}},
author = {Kaiyang Zhou and Jingkang Yang and Chen Change Loy and Ziwei Liu},
year = {2022},
eprint = {2203.05557},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2203.05557v2}
}