Skip to main content
In-context learning gives Perceptron Mk1.5 examples of the visual concept you want to find. Supply a reference image, a label, and a box around the reference object, then ask for matching objects in a target image. The examples guide that request; they do not train or permanently update the model. Use one reference for a specific object or several labeled references to distinguish classes. This is useful when a visual example communicates the appearance more clearly than a description alone.

Detect from labeled examples

This example uses reviewed boxes around a cat and a dog in the sample reference images. It runs once with only the dog reference, then with both classes. The target image shows a dog; providing a cat reference does not mean a cat must appear in the answer. Install the perceptron>=0.4.0 Python package and set PERCEPTRON_API_KEY before running:
In the first call, the dog reference is asset 0 and the target is asset 1. In the second, the cat is asset 0, the dog is asset 1, and the target is asset 2. Each call has its own supplied conversation, so its numbering starts again at zero. See multiple assets before adapting this to a conversation with earlier media. The answer is annotation markup in message.content. Check that each returned box refers to the target asset before drawing it. The annotation reference explains coordinate conversion, collections, and validation. To draw the boxes, save one call’s returned string as response.txt, download the target image, and follow rendering annotations. Use --asset-idx 1 --last-asset-idx 1 for the single-reference answer or --asset-idx 2 --last-asset-idx 2 for the multiclass answer. Keep the two answers separate because their indices differ. When asset_idx is omitted and no selector is inherited, it defaults to the last asset available when that answer was produced, which is the target image in both examples.

Prepare your own references

Replace each reference URL, label, and box together. The sample coordinates belong only to the sample images. Use the normalized 0–1000 grid, with the top-left and bottom-right corners enclosing the object you intend to teach. If you obtain candidate boxes from a previous model response, inspect and correct them before using them as examples.
  • Choose references with a clear view of the object, including the features that distinguish it from similar objects.
  • Use consistent class labels across examples and the target request. Multiple views of one class should share a label.
  • Include confusing alternatives as separately labeled references when distinguishing them matters.
  • Keep the target image separate from the examples, and request output only for its asset_idx.
For the same reference-to-query pattern across time, see in-context learning for video. For ordinary detection without examples, see object detection.