> For the complete documentation index, see [llms.txt](https://docs.eyepop.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.eyepop.ai/platform/abilities/open-vocabulary/classify-a-detected-object.md). Agents can also search and read this documentation through its [MCP server](https://docs.eyepop.ai/~gitbook/mcp).

# Classify a detected object

Classify each object a detector finds with CLIP or SigLIP2, by cropping it first

[CLIP and SigLIP2](https://docs.eyepop.ai/platform/abilities/open-vocabulary/classify-the-whole-image.md) score how well a prompt describes the **entire** picture. On a whole scene, a question about one object competes with everything else in view: the other objects, the background, the light. Crop the object first, and the classifier compares the prompt against that object alone. In practice this is often the more useful way to use them: a cropped, detected object has far less distraction than the whole scene.

### How it works

A [crop forward](https://docs.eyepop.ai/platform/pop/pop-forwarding.md) chains a detector to a classifier inside one Pop:

1. The detector — a fixed-class one such as `eyepop.person`, or an [open-vocabulary](https://docs.eyepop.ai/platform/abilities/open-vocabulary/detect-and-segment.md) one such as `eyepop.sam3.detect` — finds the objects.
2. The forward cuts each detection out of the frame, and hands every crop to its targets. `boxPadding` widens each crop by a factor before cutting, when the classifier needs a little context around the object.
3. The classifier runs once per crop. `topKClasses` caps how many of its classes each object keeps; `1` keeps only the best.
4. The classes land on the object they were cropped from, as described in [Classes and Texts](https://docs.eyepop.ai/platform/response-format/predictions/classes-and-texts.md#for-one-object).

Nothing round-trips to your code between the two stages. The outputs below were captured from production; your numbers will differ slightly.

### Whole image against each crop

`group.png` is a photo of seven people standing in a row, each in a different top. Ask CLIP about shirt colours on the whole photo, and every colour is true of someone, so none of them describes the picture:

```json
{
  "components": [
    {
      "type": "inference",
      "ability": "eyepop.clipv2.classify:latest",
      "params": {
        "prompts": [
          { "prompt": "a photo of a person in a pink shirt", "label": "pink" },
          { "prompt": "a photo of a person in a blue shirt", "label": "blue" },
          { "prompt": "a photo of a person in a green shirt", "label": "green" },
          { "prompt": "a photo of a person in a lilac shirt", "label": "lilac" },
          { "prompt": "a photo of a person in a white shirt", "label": "white" }
        ]
      }
    }
  ]
}
```

```json
"classes": [
  { "classLabel": "pink", "confidence": 0.0057 },
  { "classLabel": "blue", "confidence": 0.0185 },
  { "classLabel": "green", "confidence": 0.0128 },
  { "classLabel": "lilac", "confidence": 0.0071 },
  { "classLabel": "white", "confidence": 0.0026 }
]
```

<figure><img src="https://1072321683-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDoCvfjveqiJFmk0cnXCp%2Fuploads%2Fgit-blob-17e3f0c84dd52634c0a482b794fea0ecf943ee2e%2Fopen-vocabulary-classify-detected-whole.jpg?alt=media" alt="The group photo with a bar chart below it: every shirt colour scores under 0.02" width="500"><figcaption><p>On the whole photo, no colour scores above 0.02.</p></figcaption></figure>

Put a person detector in front of the same classifier, and each person gets an answer of their own:

{% tabs %}
{% tab title="JSON" %}

```json
{
  "components": [
    {
      "type": "inference",
      "ability": "eyepop.person:latest",
      "forward": {
        "operator": { "type": "crop" },
        "targets": [
          {
            "type": "inference",
            "ability": "eyepop.clipv2.classify:latest",
            "topKClasses": 1,
            "params": {
              "prompts": [
              { "prompt": "a photo of a person in a pink shirt", "label": "pink" },
              { "prompt": "a photo of a person in a blue shirt", "label": "blue" },
              { "prompt": "a photo of a person in a green shirt", "label": "green" },
              { "prompt": "a photo of a person in a lilac shirt", "label": "lilac" },
              { "prompt": "a photo of a person in a white shirt", "label": "white" }
              ]
            }
          }
        ]
      }
    }
  ]
}
```

{% endtab %}

{% tab title="Python" %}

```python
from eyepop import EyePopSdk
from eyepop.worker.worker_types import CropForward, InferenceComponent, Pop

pop = Pop(components=[
    InferenceComponent(
        ability="eyepop.person:latest",
        forward=CropForward(targets=[
            InferenceComponent(
                ability="eyepop.clipv2.classify:latest",
                params={"prompts": [
                    {"prompt": "a photo of a person in a pink shirt", "label": "pink"},
                    {"prompt": "a photo of a person in a blue shirt", "label": "blue"},
                    {"prompt": "a photo of a person in a green shirt", "label": "green"},
                    {"prompt": "a photo of a person in a lilac shirt", "label": "lilac"},
                    {"prompt": "a photo of a person in a white shirt", "label": "white"},
                ]},
                topKClasses=1,
            ),
        ]),
    ),
])

with EyePopSdk.sync_worker(pop=pop) as endpoint:
    result = endpoint.upload("group.png").predict()

for person in sorted(result.get("objects", []), key=lambda p: p["x"]):
    for best in person.get("classes", []):
        print(f"person at x={person['x']:.0f}: {best['classLabel']} ({best['confidence']:.2f})")
```

{% endtab %}

{% tab title="Node" %}

```typescript
import { EyePop, ForwardOperatorType, PopComponentType } from '@eyepop.ai/eyepop'

const endpoint = await EyePop.workerEndpoint({
    pop: {
        components: [
            {
                type: PopComponentType.INFERENCE,
                ability: 'eyepop.person:latest',
                forward: {
                    operator: { type: ForwardOperatorType.CROP },
                    targets: [
                        {
                            type: PopComponentType.INFERENCE,
                            ability: 'eyepop.clipv2.classify:latest',
                            params: {
                                prompts: [
                                    { prompt: 'a photo of a person in a pink shirt', label: 'pink' },
                                    { prompt: 'a photo of a person in a blue shirt', label: 'blue' },
                                    { prompt: 'a photo of a person in a green shirt', label: 'green' },
                                    { prompt: 'a photo of a person in a lilac shirt', label: 'lilac' },
                                    { prompt: 'a photo of a person in a white shirt', label: 'white' },
                                ],
                            },
                            topKClasses: 1,
                        },
                    ],
                },
            },
        ],
    },
}).connect()

try {
    const results = await endpoint.process({ source: { path: 'group.png' } })
    for await (const result of results) {
        const people = [...(result.objects ?? [])].sort((a, b) => a.x - b.x)
        for (const person of people) {
            for (const best of person.classes ?? []) {
                console.log(`person at x=${person.x.toFixed(0)}: ${best.classLabel} (${best.confidence?.toFixed(2)})`)
            }
        }
    }
} finally {
    await endpoint.disconnect()
}
```

{% endtab %}
{% endtabs %}

```
person at x=60: blue (0.96)
person at x=206: pink (0.85)
person at x=361: blue (0.98)
person at x=481: green (0.95)
person at x=602: blue (0.77)
person at x=698: white (0.93)
person at x=810: blue (0.88)
```

<figure><img src="https://1072321683-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDoCvfjveqiJFmk0cnXCp%2Fuploads%2Fgit-blob-ca978a80e55dda72dd105a770a17028f8ba3a2a0%2Fopen-vocabulary-classify-detected-shirts.jpg?alt=media" alt="The group photo with a box around each of the seven people and the colour CLIP gave their crop: blue, pink, blue, green, blue, white, blue"><figcaption><p>One colour per person, scored between 0.77 and 0.98.</p></figcaption></figure>

The scores go from under 0.02 to between 0.77 and 0.98. The answers are about the whole crop, though, not about the shirt alone: the woman in the lilac top, at x=602, is answered `blue`, because her blue jeans fill more of the crop than the top does. Ask about what the crop shows most of, or crop closer to the part you mean.

### Detect, then classify each crop

Do the people on the [street photo](https://docs.eyepop.ai/platform/abilities/open-vocabulary.md#running-the-examples) wear sunglasses? On the full photo, `a person wearing sunglasses` competes with the bus, the building and the pavement. On a crop of one person, that person is the entire picture, and the question is about them.

{% tabs %}
{% tab title="Python" %}

```python
from eyepop import EyePopSdk
from eyepop.worker.worker_types import CropForward, InferenceComponent, Pop

pop = Pop(components=[
    InferenceComponent(
        ability="eyepop.sam3.detect:latest",
        params={"prompts": [{"prompt": "person"}]},
        forward=CropForward(targets=[
            InferenceComponent(
                ability="eyepop.clipv2.classify:latest",
                params={"prompts": [
                    {"prompt": "a photo of a person wearing sunglasses", "label": "sunglasses"},
                    {"prompt": "a photo of a person with bare eyes", "label": "no sunglasses"},
                ]},
                topKClasses=1,
            ),
        ]),
    ),
])

with EyePopSdk.sync_worker(pop=pop) as endpoint:
    result = endpoint.upload("street.jpg").predict()

for person in result.get("objects", []):
    for best in person.get("classes", []):
        print(f"person at x={person['x']:.0f}: {best['classLabel']} ({best['confidence']:.2f})")
```

{% endtab %}

{% tab title="Node" %}

```typescript
import { EyePop, ForwardOperatorType, PopComponentType } from '@eyepop.ai/eyepop'

const endpoint = await EyePop.workerEndpoint({
    pop: {
        components: [
            {
                type: PopComponentType.INFERENCE,
                ability: 'eyepop.sam3.detect:latest',
                params: { prompts: [{ prompt: 'person' }] },
                forward: {
                    operator: { type: ForwardOperatorType.CROP },
                    targets: [
                        {
                            type: PopComponentType.INFERENCE,
                            ability: 'eyepop.clipv2.classify:latest',
                            params: {
                                prompts: [
                                    { prompt: 'a photo of a person wearing sunglasses', label: 'sunglasses' },
                                    { prompt: 'a photo of a person with bare eyes', label: 'no sunglasses' },
                                ],
                            },
                            topKClasses: 1,
                        },
                    ],
                },
            },
        ],
    },
}).connect()

try {
    const results = await endpoint.process({ source: { path: 'street.jpg' } })
    for await (const result of results) {
        for (const person of result.objects ?? []) {
            for (const best of person.classes ?? []) {
                console.log(`person at x=${person.x.toFixed(0)}: ${best.classLabel} (${best.confidence?.toFixed(2)})`)
            }
        }
    }
} finally {
    await endpoint.disconnect()
}
```

{% endtab %}
{% endtabs %}

```
person at x=671: sunglasses (0.33)
person at x=0: no sunglasses (0.23)
person at x=51: sunglasses (0.83)
person at x=225: sunglasses (0.57)
```

<figure><img src="https://1072321683-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDoCvfjveqiJFmk0cnXCp%2Fuploads%2Fgit-blob-7e97444a08a78855d733dd498680d0dccfe32344%2Fopen-vocabulary-crop-classify.jpg?alt=media" alt="The street photo with a box around each of the four people and the class CLIP gave that person&#x27;s crop: sunglasses 0.83 and 0.57 for the two men facing the camera, no sunglasses 0.23 for the person cut off at the left edge, sunglasses 0.33 for the man walking away on the right" width="400"><figcaption><p>CLIP answers about each person's crop, not about the street.</p></figcaption></figure>

The two men facing the camera wear sunglasses, and CLIP says so. The man on the right walks away from the camera, so his face is out of view, and the person at the left edge is cut off: neither caption fits them well, which their low scores show. `topKClasses=1` keeps only the better of the two answers on each person. The classes land on the person they were cropped from, as described in [Classes and Texts](https://docs.eyepop.ai/platform/response-format/predictions/classes-and-texts.md#for-one-object).

### Next steps

* [Classify the whole image](https://docs.eyepop.ai/platform/abilities/open-vocabulary/classify-the-whole-image.md) — CLIP and SigLIP2 on a whole scene
* [Detect and segment](https://docs.eyepop.ai/platform/abilities/open-vocabulary/detect-and-segment.md) — open-vocabulary detectors to crop from
* [Forwarding](https://docs.eyepop.ai/platform/pop/pop-forwarding.md) — every crop forward option
* [Recipes](https://docs.eyepop.ai/platform/abilities/open-vocabulary/recipes.md#ask-a-vlm-instead) — ask a VLM about each crop instead

Questions about building a Pop? Reach us at <help@eyepop.ai>.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.eyepop.ai/platform/abilities/open-vocabulary/classify-a-detected-object.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
