# Roboflow 2.0

Roboflow 2.0 is a DeepLabv3-based semantic segmentation model. You train Roboflow 2.0 models on the Roboflow platform and deploy them through our [Serverless Hosted API](/deploy/serverless-hosted-api-v2.md).

For self-hosted deployment, see [Roboflow Inference](https://inference.roboflow.com/).

{% hint style="info" %}
Roboflow 2.0 has no public default models. You call your own trained model using its `project/version` identifier from your [Roboflow Project](https://app.roboflow.com/).
{% endhint %}

## Code sample

Install the [Inference SDK](https://inference.roboflow.com/) and [supervision](https://supervision.roboflow.com/):

```bash
pip install inference-sdk supervision
```

Run inference against a Roboflow 2.0 semantic segmentation model you have trained, decode the per-pixel class map, and write an annotated PNG. Replace `your-project/1` with your model URL and version. Pass your [Roboflow API Key](https://app.roboflow.com/settings/api) via the `API_KEY` environment variable.

The response contains a `segmentation_mask` (base64-encoded grayscale PNG where each pixel value is a class ID and `0` is background) and a `class_map` mapping class IDs to class names. The script splits that into one `sv.Detections` row per class so `sv.MaskAnnotator` can overlay the masks on the source image.

```python
import base64
import os
import urllib.request

import cv2
import numpy as np
import supervision as sv
from inference_sdk import InferenceHTTPClient

image_url = "https://storage.googleapis.com/com-roboflow-marketing/notebooks/examples/bicycle.png"
image_path = "bicycle.png"
urllib.request.urlretrieve(image_url, image_path)

image = cv2.imread(image_path)
OUTPUT_PATH = "annotated.png"

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.getenv("API_KEY"),
)
result = client.infer(image, model_id="your-project/1")
predictions = result["predictions"]

mask_bytes = base64.b64decode(predictions["segmentation_mask"])
class_map = predictions.get("class_map", {})
class_mask = cv2.imdecode(np.frombuffer(mask_bytes, np.uint8), cv2.IMREAD_GRAYSCALE)
class_mask = cv2.resize(class_mask, (image.shape[1], image.shape[0]), interpolation=cv2.INTER_NEAREST)

class_ids = [cid for cid in np.unique(class_mask).tolist() if cid != 0]
if class_ids:
    masks, xyxy, names = [], [], []
    for cid in class_ids:
        binary = class_mask == cid
        rows = np.where(np.any(binary, axis=1))[0]
        cols = np.where(np.any(binary, axis=0))[0]
        xyxy.append([cols[0], rows[0], cols[-1], rows[-1]])
        masks.append(binary)
        names.append(class_map.get(str(cid), str(cid)))

    detections = sv.Detections(
        xyxy=np.array(xyxy, dtype=np.float64),
        mask=np.array(masks),
        class_id=np.array(class_ids),
        data={"class_name": np.array(names)},
    )
    annotated = sv.MaskAnnotator().annotate(scene=image.copy(), detections=detections)
    annotated = sv.LabelAnnotator().annotate(scene=annotated, detections=detections)
else:
    annotated = image

cv2.imwrite(OUTPUT_PATH, annotated)
print(f"Saved {OUTPUT_PATH}")
```

{% hint style="info" %}
Set `api_url` to match your deployment target:

* `https://serverless.roboflow.com` for the Serverless Hosted API.
* `http://localhost:9001` for a local [Inference](https://inference.roboflow.com/) server.
* Your [Dedicated Deployment](/deploy/dedicated-deployments.md) URL for a private endpoint.
  {% endhint %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.roboflow.com/deploy/supported-models/roboflow-2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
