> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/models/supported-models/roboflow-2.md).

# Roboflow 2.0

Use the Roboflow 2.0 semantic segmentation model through our Serverless Hosted API

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 Cloud API](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api).

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

## Roboflow 2.0 API

{% stepper %}
{% step %}

### Get your API Key

Create a Roboflow account, find your key on the [Roboflow API settings page](https://app.roboflow.com/settings/api) and make it available to your shell:

```bash
export ROBOFLOW_API_KEY="your-key-here"
```

{% endstep %}

{% step %}

### Install the dependencies

Install the [Inference SDK](https://docs.roboflow.com/deployment/self-hosted/self-hosted) and [supervision](https://supervision.roboflow.com/):

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

{% endstep %}

{% step %}

### Run the model

Run inference against a Roboflow 2.0 semantic segmentation model you have trained and write an annotated PNG. Call your model by its `{workspace}/{model-slug}` ID (see [Versions, Trainings, and Models](https://docs.roboflow.com/models/versions-trainings-and-models.md)).

`sv.Detections.from_inference` (supervision 0.32.0 or later) turns each class in the result into one detection whose mask covers every pixel of that class, named from the result's `class_map`. Class ID 0 (the background) is left out. Keep client-side downsizing disabled so the mask matches the input image size.

```python
import os
import cv2
import supervision as sv
from inference_sdk import InferenceHTTPClient, InferenceConfiguration

image = sv.load_image_from_url("https://media.roboflow.com/quickstart/traffic.jpg")

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["ROBOFLOW_API_KEY"],
).configure(InferenceConfiguration(
    api_key_transport="header",
    client_downsizing_disabled=True,
))
# No pretrained aliases: train your own model and replace "your-project/1" with your model ID.
result = client.infer(image, model_id="your-project/1")

detections = sv.Detections.from_inference(result)

annotated = sv.MaskAnnotator().annotate(image.copy(), detections)
annotated = sv.LabelAnnotator().annotate(annotated, detections)

cv2.imwrite("annotated.png", annotated)
print("Saved annotated.png")
```

{% endstep %}
{% endstepper %}

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

* `https://serverless.roboflow.com` for the Serverless Cloud API.
* `http://localhost:9001` for a local [Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted) server.
* Your [Dedicated Deployment](https://docs.roboflow.com/deployment/roboflow-cloud/dedicated-deployments) URL for a private endpoint.
  {% endhint %}
