> 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/reference/ko/inference/inference-python.md).

# 추론 Python 패키지

해당 `추론` Python 패키지는 Roboflow의 컴퓨터 비전 배포 스택을 구동하는 핵심 오픈 소스 라이브러리입니다. 모델 로딩, 전처리/후처리, GPU/CPU 최적화, 그리고 [워크플로](https://docs.roboflow.com/workflows) 실행을 제공하며, Python에서 직접 호출할 수 있습니다.

해당 [Inference Server](https://docs.roboflow.com/deployment/self-hosted/inference-server) 이 패키지를 감싸 HTTP로 노출하며(모든 종속성이 설치된 Docker 이미지로 배포됨), 하지만 또한 `추론` 자신의 스크립트와 애플리케이션에서 직접 사용할 수도 있습니다.

## 각 구성 요소가 어떻게 맞물리는가

Inference에는 컴퓨터 비전 모델을 서비스하기 위해 함께 동작하는 여러 구성 요소가 있습니다:

* [**추론**](/reference/ko/inference/inference-python.md) - 모델 로딩, 추론, Workflows 실행을 위한 핵심 Python 패키지.
* [**inference-sdk**](/reference/ko/inference/inference-sdk.md) - HTTP를 통해 Inference Server와 통신하는 경량 Python 클라이언트.
* [**inference-cli**](/reference/ko/inference/inference-cli.md) - Inference Server를 관리하고 일반적인 작업을 실행하는 명령줄 도구.
* [**Inference Server**](https://docs.roboflow.com/deployment/self-hosted/inference-server) - 다음을 감싸는 HTTP 서버(Docker): `추론` 패키지를 REST API로 제공합니다.

이 구성 요소들이 런타임에서 어떻게 동작하는지(요청 라우팅, 병렬화, 마이크로서비스 및 어플라이언스 패턴)는 다음을 참조하세요: [추론 아키텍처](https://docs.roboflow.com/deployment/self-hosted/inference-server/architecture).

## 다중 백엔드 지원

Inference 1.0은 여러 추론 런타임 백엔드(ONNX, TensorRT, Hugging Face, PyTorch)를 지원합니다. 하드웨어에 대해 사용 가능한 가장 빠른 백엔드를 자동으로 선택합니다. 예를 들어 NVIDIA GPU를 사용 중이거나 Jetson 장치에서 실행 중이고, 플랫폼에서 해당 모델에 사용할 수 있는 TensorRT 엔진이 있다면 Inference는 기본적으로 TensorRT를 사용합니다.

## 설치

다음을 사용하는 것을 권장합니다. [Python 가상 환경(venv)](https://docs.python.org/3/tutorial/venv.html) 를 사용해 Inference의 종속성을 분리하세요.

pip을 통해 Inference를 설치하려면:

```bash
pip install inference
```

NVIDIA GPU가 있다면, 다음으로 추론을 가속할 수 있습니다:

```bash
pip install --extra-index-url https://download.pytorch.org/whl/cu124 inference-gpu
# 설치된 OS의 CUDA 버전에 맞게 --extra-index-url을 조정하세요
# https://download.pytorch.org/whl/cu<major><minor>, 예를 들어 CUDA 13.0의 경우 https://download.pytorch.org/whl/cu130
```

## 간단한 예시

HTTP를 통해 Inference Server를 대상으로 추론을 실행할 수 있습니다( `inference-sdk`) 또는 네이티브 `추론` 패키지). 네이티브 `get_model()` 호출은 모델을 스크립트에 로드하고, 호출할 수 있는 객체를 반환합니다 `.infer()` 에서 사용합니다; HTTP 클라이언트는 이미지를 동일한 작업을 수행하는 서버로 보냅니다.

{% tabs %}
{% tab title="추론(네이티브)" %}

```python
from inference import get_model

model = get_model(model_id="rfdetr-small")
results = model.infer("https://media.roboflow.com/inference/people-walking.jpg")
```

{% endtab %}

{% tab title="inference-sdk(HTTP 클라이언트)" %}

```python
from inference_sdk import InferenceHTTPClient

client = InferenceHTTPClient(
    # api_url="http://localhost:9001",  # 자체 호스팅용
    api_url="https://serverless.roboflow.com",
    api_key="ROBOFLOW_API_KEY",
)
results = client.infer(
    "https://media.roboflow.com/inference/people-walking.jpg",
    model_id="rfdetr-small",
)
```

{% endtab %}
{% endtabs %}

API 키가 필요한 모델을 사용하려면 다음을 설정하세요 `ROBOFLOW_API_KEY` 환경 변수를 사용하거나 직접 전달하세요:

```python
model = get_model(model_id="my-project/1", api_key="ROBOFLOW_API_KEY")
```

다음을 참조하세요 [네이티브 Python API](/reference/ko/inference/inference-python/native-python-api.md) 시각화가 포함된 더 자세한 안내는 페이지를 참조하고, [모델 실행](https://docs.roboflow.com/deployment/self-hosted/self-hosted#run-a-model) 서버 기반 경로에 대한 내용입니다.

## 추론 파이프라인

`InferencePipeline` 비디오를 다음과 동일한 Python 프로세스 내에서 실행합니다 `추론` 패키지. 직접 Inference Library 실행을 선택하고 해당 사용자 정의 로직 또는 sink 인터페이스에 접근해야 할 때만 사용하세요. Inference Server 또는 Serverless를 사용하는 애플리케이션은 [WebRTC 스트리밍](/reference/ko/inference/inference-sdk/webrtc.md).

```python
from inference import InferencePipeline
from inference.core.interfaces.stream.sinks import render_boxes

pipeline = InferencePipeline.init(
    model_id="rfdetr-large",
    video_reference="https://storage.googleapis.com/com-roboflow-marketing/inference/people-walking.mp4",
    on_prediction=render_boxes,
    api_key="ROBOFLOW_API_KEY",
)

pipeline.start()
pipeline.join()
```

위 코드는 객체 감지 주석을 직접 수행합니다(다음을 통해 `render_boxes` sink). 자세한 내용은 다음을 참조하세요 [추론 파이프라인](/reference/ko/inference/inference-python/inference-pipeline.md) 페이지.

## 기여

Inference는 오픈 소스입니다. 소스 코드, 이슈 추적기, 기여 가이드는 다음에 있습니다 [roboflow/inference](https://github.com/roboflow/inference) 저장소에 있으며, 다음을 참조하세요 [CONTRIBUTING.md](https://github.com/roboflow/inference/blob/main/CONTRIBUTING.md) 시작하려면.

## 다음 단계

* [네이티브 Python API](/reference/ko/inference/inference-python/native-python-api.md) - 자신의 프로세스에서 모델을 로드하고 추론을 실행합니다.
* [추론 파이프라인](/reference/ko/inference/inference-python/inference-pipeline.md) - 비디오 스트림에서 모델을 실행합니다.
* [모델 가중치 다운로드](/reference/ko/inference/inference-python/offline-weights.md) - 가중치 캐싱 및 영구 저장.
* [벤치마크](/reference/ko/inference/inference-python/benchmarks.md) - 일반적인 하드웨어에서 측정한 처리량.
