> 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/ko/supported-models/roboflow-2.md).

# Roboflow 2.0

Roboflow 2.0은 DeepLabv3 기반의 시맨틱 세그멘테이션 모델입니다. Roboflow 플랫폼에서 Roboflow 2.0 모델을 학습시키고, 이를 우리의 [서버리스 클라우드 API](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api).

자체 호스팅 배포는 다음을 참조하세요 [Roboflow Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted).

## Roboflow 2.0 API

{% stepper %}
{% step %}

### API 키 받기

Roboflow 계정을 만들고, [Roboflow API 설정 페이지](https://app.roboflow.com/settings/api) 에서 키를 찾아 셸에서 사용할 수 있게 하세요:

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

{% endstep %}

{% step %}

### 의존성을 설치하세요

설치하세요 [Inference SDK](https://docs.roboflow.com/deployment/self-hosted/self-hosted) 및 [supervision](https://supervision.roboflow.com/):

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

{% endstep %}

{% step %}

### 모델 실행

학습한 Roboflow 2.0 시맨틱 세그멘테이션 모델에 대해 추론을 실행하고, 픽셀별 클래스 맵을 디코딩한 다음, 주석이 달린 PNG를 씁니다. 모델은 그 `{workspace}/{model-slug}` ID(참조 [버전, 학습, 모델](/models/ko/versions-trainings-and-models.md)).

응답에는 `segmentation_mask` (각 픽셀 값이 클래스 ID인 base64로 인코딩된 그레이스케일 PNG이며 `0` 은 배경입니다)와 `class_map` 클래스 ID를 클래스 이름에 매핑합니다. 이 스크립트는 이를 하나의 `sv.Detections` 클래스당 한 행으로 분리하므로 `sv.MaskAnnotator` 가 원본 이미지 위에 마스크를 오버레이할 수 있습니다.

```python
import base64
import os
import cv2
import numpy as np
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"))
# 사전 학습된 별칭 없음: 직접 모델을 학습하고 "your-project/1"을 모델 ID로 바꾸세요.
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(image.copy(), detections)
    annotated = sv.LabelAnnotator().annotate(annotated, detections)
그렇지 않으면:
    annotated = image

cv2.imwrite("annotated.png", annotated)
print("annotated.png를 저장했습니다")
```

{% endstep %}
{% endstepper %}

{% hint style="info" %}
설정하세요 `api_url` 를 배포 대상에 맞게:

* `https://serverless.roboflow.com` 는 서버리스 클라우드 API용입니다.
* `http://localhost:9001` 로컬 [Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted) 서버용입니다.
* 귀하의 [전용 배포](https://docs.roboflow.com/deployment/roboflow-cloud/dedicated-deployments) 는 비공개 엔드포인트의 URL입니다.
  {% endhint %}
