Gradient-Free Few-Shot Adaptation of Vision Models via Agentic Coding
Organizations: Computational Engineering Division, Lawrence Livermore National Laboratory, 7000 East Avenue, Livermore, CA 94550, USA
Abstract
Adapting a vision model to new classes from a few labeled images usually relies on gradient fine-tuning, which is unstable with so few images. We ask whether a coding agent can replace gradient descent for this task. We propose the Agent edit, a method in which a coding agent writes a program that sets the new class weights in the class head of a frozen COCO-trained detector, with no gradient step. The agent runs the detector on the labeled images a limited number of times and sees how much its edit lowers COCO mAP; the program rebuilds the weights without the agent. In the same head and with the same labels, the Agent edit outperforms full-decoder fine-tuning at five shots on 2 of four fine-grained sets, by 11.2 and 12.3 F1 points, and ties on the rest. At ten shots, fine-tuning ties with or outperforms it. Moreover, when the new classes are scored jointly with the COCO classes, the AP of the COCO class to which they belong falls by up to 33.3 points, and limiting that loss lowers F1 on the new classes. Most of the agent's programs share three parts, which we write as a formula that needs no agent. A classifier on frozen backbone features reaches a higher F1 than every method inside the head on every set. Hence a coding agent can replace gradient descent only in part: inside the head and at five shots.
Figures & tables
| Cars | CUB | Pets | Aircraft | |||||||||
| Method | AP | AP50 | Top-1 | AP | AP50 | Top-1 | AP | AP50 | Top-1 | AP | AP50 | Top-1 |
| Stock head | 1.2 | 1.2 | 10.0 | 7.7 | 8.6 | 8.3 | 1.5 | 2.2 | 8.3 | 2.0 | 2.0 | 8.3 |
| Linear probe (LP) | 33.2 | 36.5 | 40.2 | 17.1 | 19.6 | 22.5 | 17.0 | 24.0 | 30.8 | 24.1 | 25.6 | 25.3 |
| Cosine head | 41.7 | 46.4 | 47.2 | 19.2 | 21.9 | 26.1 | 17.4 | 24.1 | 31.1 | 25.0 | 26.2 | 24.2 |
| Fine-tuning (FT), mean of 3 orders | 56.3 | 72.7 | 66.1 | 20.0 | 29.6 | 28.4 | 50.0 | 55.5 | 48.3 | 23.1 | 26.8 | 21.6 |
| FT, best order ‡ | 62.2 | 81.5 | 74.5 | 25.5 | 38.0 | 35.8 | 56.4 | 63.6 | 54.8 | 25.7 | 29.0 | 23.3 |
| Method | Grid |
|---|---|
| Prototype | Row scale, as a multiple of the stock row norm, in , and two target rules (all queries with IoU at least 0.5, or one query per object). |
| LP | L-BFGS, cross-entropy over the classes and the no-object row, no-object weight 0.1, one query per object as target: weight decay 0 and 15 log-spaced values from to . |
| Tip-Adapter | On top of the Prototype rows: and . |
| Cosine head | Imprinted initial rows, full-batch Adam, no-object weight 0.1: scale , learning rate , steps . |
| FT | AdamW (weight decay 0.05) on the whole decoder, started from the stock weights plus the LP rows: learning rate and epochs . |
| LwF | FT with a distillation term of weight 0.01. |
| Set | In-context | Zero-shot | Hidden names |
|---|---|---|---|
| Cars | 100.0 | 99.7 | 99.7 |
| CUB | 81.1 | 80.0 | 84.4 |
| Pets | 98.3 | 94.7 | 98.6 |
| Aircraft | 96.1 | 93.3 | 97.2 |
| Ships | 46.7 | 40.8 | 40.6 |
| LIVECell | 45.6 | 15.6 | 32.1 |
Few-Shot Object Detection
Few-shot object detection adapts detectors to recognize and localize new object classes from only a handful of labeled examples.
See all 32 papers