> 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).

# 로컬에서 모델 실행

[Roboflow 인퍼런스](https://docs.roboflow.com/deployment/self-hosted/self-hosted) Roboflow의 호스팅 모델 뒤에서 작동하는 무료 오픈 소스 엔진입니다. 동일한 모델을 자신의 컴퓨터에서 실행할 수 있습니다. Docker 컨테이너에서 inference server를 시작한 다음, HTTP 또는 Python으로 이미지를 보낼 수 있습니다 [인퍼런스 SDK](https://docs.roboflow.com/reference/inference/inference-sdk). 직접 실행하면 이미지를 자신의 머신에 보관할 수 있고 설정을 완전히 제어할 수 있습니다.

## 자신의 머신에서 모델 실행

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

### 인퍼런스 서버 시작

`inference server start` 실행합니다 [인퍼런스 서버](https://docs.roboflow.com/deployment/self-hosted/inference-server) Docker 컨테이너에서 실행되며 하드웨어에 맞는 올바른 버전(CPU, NVIDIA GPU 또는 Jetson)을 선택합니다. [Docker](https://docs.docker.com/get-docker/) 설치되어 있고 실행 중이어야 합니다.

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

서버는 다음에서 수신 대기합니다 `http://localhost:9001`. 장치별 설정 및 문제 해결은 다음을 참조하세요: [인퍼런스 설치 가이드](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) 모델을 실행합니다. 이와 같은 미리 만들어진 모델은 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"{len(detections)}개의 객체를 찾았습니다")

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` 실행합니다 [인퍼런스 서버](https://docs.roboflow.com/deployment/self-hosted/inference-server) Docker 컨테이너에서 실행되며 하드웨어에 맞는 올바른 버전(CPU, NVIDIA GPU 또는 Jetson)을 선택합니다. [Docker](https://docs.docker.com/get-docker/) 설치되어 있고 실행 중이어야 합니다.

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

서버는 다음에서 수신 대기합니다 `http://localhost:9001`. 장치별 설정 및 문제 해결은 다음을 참조하세요: [인퍼런스 설치 가이드](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) 모델을 실행합니다. 이와 같은 미리 만들어진 모델은 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"{len(detections)}개의 객체를 찾았습니다")

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="/files/c999ed349e4225bd7c88961eab95e68d6b937625" 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>" %}

추적, 필터링, 구역, 알림이 포함된 더 풍부한 파이프라인을 시각적으로 다음에서 구축하세요: [워크플로 편집기](https://docs.roboflow.com/workflows/build/create-a-workflow), 그런 다음 동일한 WebRTC 클라이언트로 실행하세요. 다음을 참조하세요: [워크플로를 사용한 비디오 처리](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).
