> 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/get-started/ko/guides/run-a-model-locally.md).

# 로컬에서 모델 실행

Docker 추론 서버를 사용해 5분 만에 자신의 하드웨어에서 Roboflow 모델을 실행하세요.

[Roboflow Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted) 는 Roboflow의 호스팅 모델을 구동하는 무료 오픈 소스 엔진입니다. 같은 모델을 자신의 컴퓨터에서 실행할 수 있습니다. Docker 컨테이너에서 추론 서버를 시작한 다음, HTTP 또는 Python [Inference SDK](https://docs.roboflow.com/reference/inference/inference-sdk)를 사용해 이미지 전송하면 됩니다. 직접 실행하면 이미지가 자신의 컴퓨터에 저장되고 설정을 완전히 제어할 수 있습니다. 로컬 추론에는 크레딧이 사용되지 않습니다.

## 컴퓨터에서 모델 실행하기

{% tabs %}
{% tab title="HTTP(Python)" icon="webhook" %}
{% stepper %}
{% step %}

### 추론 서버 시작

`inference server start` 명령은 Docker 컨테이너에서 [Inference Server](https://docs.roboflow.com/deployment/self-hosted/inference-server) 를 실행하고 CPU, NVIDIA GPU 또는 Jetson 등 하드웨어에 맞는 버전을 선택합니다. [Docker](https://docs.docker.com/get-docker/) 가 설치되어 실행 중이어야 합니다.

```bash
pip install inference-cli && inference server start
```

서버는 `http://localhost:9001`에서 요청을 수신합니다. 장치별 설정 및 문제 해결 방법은 [Inference 설치 가이드](https://docs.roboflow.com/deployment/self-hosted/inference-server/install).
{% endstep %}

{% step %}

### 의존 항목 설치

`supervision` 은 결과를 그리고 `cv2` 와 `numpy`:

```bash
pip install -U supervision
```

{% endstep %}

{% step %}

### 모델 실행

이미지를 로컬 서버로 전송해 바로 사용할 수 있는 [RF-DETR](https://docs.roboflow.com/models/supported-models/rf-detr) 모델을 실행합니다. RF-DETR은 Apache 2.0 라이선스에 따라 제공되므로 라이선스 비용 없이 상용 제품에서 자체 호스팅할 수 있습니다. 이와 같은 사전 제작 모델에는 API 키가 필요하지 않습니다.

```python
import base64
import cv2
import requests
import supervision as sv

image = sv.load_image_from_url("https://media.roboflow.com/quickstart/cars.jpg")
image_b64 = base64.b64encode(content).decode("utf-8")

result = requests.post(
    "http://localhost:9001/coco/38",  # coco/38 == rfdetr-nano
    data=image_b64,  # raw base64 in the body
    headers={"Content-Type": "application/x-www-form-urlencoded"},
).json()
detections = sv.Detections.from_inference(result)
print(f"Found {len(detections)} objects")

annotated = sv.BoxAnnotator().annotate(image.copy(), detections)
annotated = sv.LabelAnnotator().annotate(annotated, detections)
cv2.imwrite("output.jpg", annotated)
```

{% endstep %}
{% endstepper %}
{% endtab %}

{% tab title="SDK(Python)" icon="python" %}
{% stepper %}
{% step %}

### 추론 서버 시작

`inference server start` 명령은 Docker 컨테이너에서 [Inference Server](https://docs.roboflow.com/deployment/self-hosted/inference-server) 를 실행하고 CPU, NVIDIA GPU 또는 Jetson 등 하드웨어에 맞는 버전을 선택합니다. [Docker](https://docs.docker.com/get-docker/) 가 설치되어 실행 중이어야 합니다.

```bash
pip install inference-cli && inference server start
```

서버는 `http://localhost:9001`에서 요청을 수신합니다. 장치별 설정 및 문제 해결 방법은 [Inference 설치 가이드](https://docs.roboflow.com/deployment/self-hosted/inference-server/install).
{% endstep %}

{% step %}

### SDK 설치

`supervision` 은 결과를 그리고 `cv2` 와 `numpy`:

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

{% endstep %}

{% step %}

### 모델 실행

클라이언트가 로컬 서버를 가리키도록 설정하고 바로 사용할 수 있는 [RF-DETR](https://docs.roboflow.com/models/supported-models/rf-detr) 모델입니다. RF-DETR은 Apache 2.0 라이선스를 따르므로 라이선스 비용 없이 상용 제품에서 자체 호스팅할 수 있습니다. 이 모델과 같은 사전 제작 모델은 API 키가 필요하지 않습니다:

```python
import cv2
import supervision as sv
from inference_sdk import InferenceHTTPClient

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

client = InferenceHTTPClient(api_url="http://localhost:9001")
result = client.infer(image, model_id="rfdetr-nano")

detections = sv.Detections.from_inference(result)
print(f"Found {len(detections)} objects")

annotated = sv.BoxAnnotator().annotate(image.copy(), detections)
annotated = sv.LabelAnnotator().annotate(annotated, detections)
cv2.imwrite("output.jpg", annotated)
```

{% endstep %}
{% endstepper %}
{% endtab %}
{% endtabs %}

첫 번째 요청에서는 모델을 다운로드하므로 몇 초 정도 걸릴 수 있습니다. 이후 요청은 빠르게 처리됩니다.

<figure><img src="https://83860450-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1YMZNIiZMBdlCHUDeZMP%2Fuploads%2Fgit-blob-1ce62bec3b043128af1074b0fc47398dafab2a78%2Flocal-rfdetr-out.jpg?alt=media" alt="RF-DETR car and truck bounding boxes on a road scene"><figcaption><p>로컬 추론 서버에서 얻은 RF-DETR 감지 결과</p></figcaption></figure>

## 동영상 처리

동영상에서 모델을 실행하려면 서버와 WebRTC 세션을 열고, 동영상이 재생되는 동안 처리된 프레임과 예측 결과를 받습니다. 컴퓨터가 처리 속도를 따라가지 못하면 서버가 실시간 처리를 유지하기 위해 프레임을 건너뜁니다. 동일한 SDK로 하나의 모델을 스트리밍하거나 [워크플로](https://docs.roboflow.com/workflows).

{% hint style="info" %}
위의 이미지 예제와 같은 방식으로 프레임을 한 번에 하나씩 전송해 HTTP를 통해 동영상에서 모델을 실행할 수도 있습니다(스트리밍 추가 기능 불필요). 이 방식은 더 느립니다. 다음 프레임 처리를 시작하기 전에 각 프레임을 전송하고 처리한 다음 그려야 하므로 중간에 대기 시간이 많이 발생합니다. SDK는 동영상 전체를 스트리밍하고 여러 프레임을 동시에 처리하므로 훨씬 더 원활하게 실행됩니다.
{% endhint %}

{% stepper %}
{% step %}

### SDK 설치

동영상 스트리밍에는 `webrtc` 추가 기능이 필요합니다:

```bash
pip install "inference-sdk[webrtc]"
```

{% endstep %}

{% step %}

### 동영상에서 모델 실행

```python
import cv2
from inference_sdk import InferenceHTTPClient
from inference_sdk.webrtc import VideoFileSource
import supervision as sv

client = InferenceHTTPClient.init(api_url="http://localhost:9001")

# 동영상 다운로드 및 캐시
source = VideoFileSource("https://media.roboflow.com/quickstart/cars.mp4")
# 최적화된 동영상 스트리밍에 webrtc 사용
session = client.webrtc.stream(
    source=source,
    model_id="rfdetr-nano"
)

# on_frame은 메인 스레드에서 실행되므로 cv2.imshow를 안전하게 사용할 수 있습니다
@session.on_frame
def show(frame, data):
    det = sv.Detections.from_inference(data)
    img = sv.BoxAnnotator().annotate(frame, det)
    img = sv.LabelAnnotator().annotate(img, det)
    cv2.imshow("RF-DETR", img)
    if cv2.waitKey(1) == ord("q"):
        session.close()

session.run()
cv2.destroyAllWindows()
```

{% endstep %}
{% endstepper %}

{% embed url="<https://media.roboflow.com/quickstart/cars-rfdetr-out.mp4>" %}

추적, 필터링, 구역, 알림을 포함한 더 풍부한 파이프라인을 [Workflows 편집기에서 시각적으로 구성한 다음](https://docs.roboflow.com/workflows/build/create-a-workflow), 동일한 WebRTC 클라이언트를 통해 실행할 수 있습니다. 자세한 내용은 [Workflows를 사용한 동영상 처리](https://docs.roboflow.com/workflows/deploy/video-processing).

## 다른 옵션

* 하드웨어를 직접 운영하지 않고 관리형 엔드포인트를 사용하고 싶으신가요? 다음을 이용하세요: [전용 배포](https://docs.roboflow.com/deployment/roboflow-cloud/dedicated-deployments) 또는 [서버리스 클라우드 API](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api).
* 온프레미스, 에어갭 또는 Kubernetes 배포가 필요하신가요? 자세한 내용은 [엔터프라이즈 배포](https://docs.roboflow.com/deployment/self-hosted/enterprise).
* 모든 옵션을 비교하려면 다음을 참조하세요: [모델 또는 워크플로 배포](https://docs.roboflow.com/deployment).
