> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vlm.run/llms.txt
> Use this file to discover all available pages before exploring further.

# Classifying Images

> Classify an image into custom categories with vlm-1.

`vlm-1` classifies an image into one label from a schema you define.

<div class="mermaid" style={{ width: '80%', margin: '0 auto', display: 'block' }}>
  ```mermaid theme={"theme":{"light":"github-light","dark":"dark-plus"}}
  flowchart TD
      A([Image]) --> B{Classify}
      B --> C1([News])
      B --> C2([Entertainment])
      B --> C3([Advertising])
      B --> C4([Other])

      style A fill:#eee,stroke:#333,stroke-width:1px
      style C1 fill:#fff,stroke:#333,stroke-width:1px
      style C2 fill:#fff,stroke:#333,stroke-width:1px
      style C3 fill:#fff,stroke:#333,stroke-width:1px
      style C4 fill:#fff,stroke:#333,stroke-width:1px
  ```
</div>

## Classifying TV Images

The example classifies a TV frame as `news`, `entertainment`, `advertising`, or `other`.

<Frame caption="TV news frame.">
  <img src="https://mintcdn.com/autonomiai/hv1ZFyEZ1wMYWx0b/guides/image-ai/images/example-tv-news.jpeg?fit=max&auto=format&n=hv1ZFyEZ1wMYWx0b&q=85&s=b6de18783e9e84eb4136ca8e59fa2b6c" width="80%" style={{ display: "block", margin: "0 auto" }} data-path="guides/image-ai/images/example-tv-news.jpeg" />
</Frame>

### Define a custom schema for image classification

```python theme={"theme":{"light":"github-light","dark":"dark-plus"}}
from typing import Literal
from pydantic import BaseModel, Field

class ImageClassification(BaseModel):
    rationale: str = Field(..., description="A rationale for the classification, based on the visual content and features of the image. Keep it short and concise, yet detailed enough to justify the classification.")
    image_type: Literal["news", "entertainment", "advertising", "other"] = Field(..., description="The type of image being processed")
    confidence: Literal["hi", "med", "lo"] = Field(..., description="Confidence score for the classification, based on the rationale provided and the visual features of the image. For ambiguous images, the confidence score should be `lo`.")
```

### Classify images

The response is validated against `ImageClassification`.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"dark-plus"}}
  from pathlib import Path
  from vlmrun.client import VLMRun
  from vlmrun.client.types import PredictionResponse, GenerationConfig

  # Initialize the client
  client = VLMRun(api_key="<VLMRUN_API_KEY>")

  # Classify a single image
  path = Path("path/to/image.jpg")
  prediction: PredictionResponse = client.image.generate(
      file=path,
      domain="image.classification",
      config=GenerationConfig(response_model=ImageClassification)
  )
  response_dict = prediction.response.model_dump()
  print(response_dict)
  ```
</CodeGroup>

### Sample Image Classification

```json theme={"theme":{"light":"github-light","dark":"dark-plus"}}
{
  "rationale": "The image contains financial market data and a news presenter from Bloomberg News, indicating a broadcast of financial news. The financial indices are highlighted, and stock performance is shown, which is typical for a news segment on economic updates.",
  "image_type": "news",
  "confidence": "hi"
}
```

| Field | Role |
| - | - |
| `rationale` | Why the image received this label. |
| `image_type` | One of `news`, `entertainment`, `advertising`, or `other`. |
| `confidence` | `hi`, `med`, or `lo`. Use `lo` when the image is ambiguous. |

## Fine-tuning Image Classification

<Warning>This feature is currently only available for our enterprise-tier customers. If you are interested in using this feature, please [contact us](mailto:support@vlm.run).</Warning>

Fine-tune on your own images, change the classification schema, or add image types. See the [fine-tuning guides](/guides/fine-tune), or contact [support@vlm.run](mailto:support@vlm.run).

## Try our Image -> JSON API today

Open [Image -> JSON](/api-reference/v1/post-image-generate) on [VLM Run](https://vlm.run). Sign up on the [platform](https://app.vlm.run).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.