Vertex AI에서 추론을 위해 Ultralytics를 사용하여 사전 학습된 YOLO 모델을 배포합니다.

이 가이드에서는 Ultralytics를 사용하여 사전 학습된 YOLO26 모델을 컨테이너화하고, 이를 위한 FastAPI 추론 서버를 빌드한 다음, Google Cloud Vertex AI에 추론 서버와 함께 모델을 배포하는 방법을 설명합니다. 예제 구현은 YOLO26에 대한 객체 탐지 사용 사례를 다루지만, 동일한 원칙이 다른 YOLO 모드를 사용할 때도 적용됩니다.

시작하기 전에 Google Cloud Platform (GCP) 프로젝트를 생성해야 합니다. 신규 사용자는 300달러의 GCP 크레딧을 무료로 사용할 수 있으며, 이 금액은 나중에 학습, 배치 및 스트리밍 추론을 포함한 다른 모든 YOLO26 사용 사례로 확장할 수 있는 실행 환경을 테스트하기에 충분합니다.

학습 내용

  1. FastAPI를 사용하여 Ultralytics YOLO26 모델을 위한 추론 백엔드를 생성합니다.
  2. Docker 이미지를 저장할 GCP Artifact Registry 리포지토리를 생성합니다.
  3. 모델이 포함된 Docker 이미지를 빌드하여 Artifact Registry에 푸시합니다.
  4. Vertex AI에서 모델을 가져옵니다.
  5. Vertex AI 엔드포인트를 생성하고 모델을 배포합니다.
왜 컨테이너화된 모델을 배포해야 할까요?
  • Ultralytics를 통한 완전한 모델 제어: 전처리, 후처리 및 응답 형식에 대한 완전한 제어 권한으로 사용자 지정 추론 로직을 사용할 수 있습니다.
  • Vertex AI가 나머지 처리: 자동 확장을 지원하면서도 컴퓨팅 리소스, 메모리 및 GPU 구성을 설정할 수 있는 유연성을 제공합니다.
  • 기본 GCP 통합 및 보안: Cloud Storage, BigQuery, Cloud Functions, VPC 제어, IAM 정책 및 감사 로그를 통한 원활한 설정이 가능합니다.

사전 요구 사항

  1. 머신에 Docker를 설치합니다.
  2. Google Cloud SDK를 설치하고 gcloud CLI 사용을 위한 인증을 수행합니다.
  3. 이 가이드를 따르는 동안 공식 Ultralytics Docker 이미지 중 하나를 확장해야 하므로 Ultralytics를 위한 Docker 빠른 시작 가이드를 먼저 살펴보는 것을 강력히 권장합니다.

FastAPI로 추론 백엔드 생성

먼저 YOLO26 모델 추론 요청을 처리할 FastAPI 애플리케이션을 생성해야 합니다. 이 애플리케이션은 모델 로딩, 이미지 전처리 및 추론(예측) 로직을 처리합니다.

Vertex AI 준수 기본 사항

Vertex AI는 컨테이너가 다음 두 가지 특정 엔드포인트를 구현할 것을 요구합니다.

  1. 상태(Health) 엔드포인트 (/health): 서비스가 준비되었을 때 HTTP 상태 200 OK를 반환해야 합니다.

  2. 예측(Predict) 엔드포인트 (/predict): base64로 인코딩된 이미지와 선택적 매개변수가 포함된 구조화된 예측 요청을 허용합니다. 페이로드 크기 제한은 엔드포인트 유형에 따라 적용됩니다.

    /predict 엔드포인트에 대한 요청 페이로드는 다음 JSON 구조를 따라야 합니다.

    {
        "instances": [{ "image": "base64_encoded_image" }],
        "parameters": { "confidence": 0.5 }
    }

프로젝트 폴더 구조

빌드의 대부분은 Docker 컨테이너 내부에서 수행되며, Ultralytics가 사전 학습된 YOLO26 모델을 로드하므로 로컬 폴더 구조를 간단하게 유지할 수 있습니다.

YOUR_PROJECT/
├── src/
│   ├── __init__.py
│   ├── app.py              # Core YOLO26 inference logic
│   └── main.py             # FastAPI inference server
├── tests/
├── .env                    # Environment variables for local development
├── Dockerfile              # Container configuration
├── LICENSE                 # AGPL-3.0 License
└── pyproject.toml          # Python dependencies and project config
중요 라이선스 참고 사항

Ultralytics YOLO26 모델과 프레임워크는 AGPL-3.0에 따라 라이선스가 부여되며, 이는 중요한 준수 요구 사항을 포함합니다. 라이선스 약관 준수 방법에 대한 Ultralytics 문서를 반드시 확인하십시오.

종속성이 포함된 pyproject.toml 생성

프로젝트를 편리하게 관리하기 위해 다음 종속성을 포함하는 pyproject.toml 파일을 생성하십시오.

[project]
name = "YOUR_PROJECT_NAME"
version = "0.0.1"
description = "YOUR_PROJECT_DESCRIPTION"
requires-python = ">=3.10,<3.13"
dependencies = [
   "ultralytics>=8.3.0",
   "fastapi[all]>=0.89.1",
   "uvicorn[standard]>=0.20.0",
   "pillow>=9.0.0",
]

[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
  • uvicorn은 FastAPI 서버를 실행하는 데 사용됩니다.
  • pillow는 이미지 처리에 사용되지만, PIL 이미지만 사용할 수 있는 것은 아닙니다. Ultralytics는 다른 많은 형식을 지원합니다.

Ultralytics YOLO26으로 추론 로직 생성

이제 프로젝트 구조와 종속성이 설정되었으므로 핵심 YOLO26 추론 로직을 구현할 수 있습니다. 모델 로딩, 이미지 처리 및 예측을 처리할 src/app.py 파일을 Ultralytics Python API를 사용하여 생성합니다.

# src/app.py

from ultralytics import YOLO

# Model initialization and readiness state
model_yolo = None
_model_ready = False

def _initialize_model():
    """Initialize the YOLO model."""
    global model_yolo, _model_ready

    try:
        # Use pretrained YOLO26n model from Ultralytics base image
        model_yolo = YOLO("yolo26n.pt")
        _model_ready = True

    except Exception as e:
        print(f"Error initializing YOLO model: {e}")
        _model_ready = False
        model_yolo = None

# Initialize model on module import
_initialize_model()

def is_model_ready() -> bool:
    """Check if the model is ready for inference."""
    return _model_ready and model_yolo is not None

이렇게 하면 컨테이너가 시작될 때 모델이 한 번 로드되며, 이 모델은 모든 요청 간에 공유됩니다. 모델이 많은 추론 부하를 처리해야 하는 경우, 나중에 Vertex AI에서 모델을 가져올 때 더 많은 메모리를 가진 머신 유형을 선택하는 것이 좋습니다.

다음으로 pillow를 사용한 입력 및 출력 이미지 처리를 위한 두 개의 유틸리티 함수를 생성합니다. YOLO26은 PIL 이미지를 기본적으로 지원합니다.

def get_image_from_bytes(binary_image: bytes) -> Image.Image:
    """Convert image from bytes to PIL RGB format."""
    input_image = Image.open(io.BytesIO(binary_image)).convert("RGB")
    return input_image
def get_bytes_from_image(image: Image.Image) -> bytes:
    """Convert PIL image to bytes."""
    return_image = io.BytesIO()
    image.save(return_image, format="JPEG", quality=85)
    return_image.seek(0)
    return return_image.getvalue()

마지막으로 객체 탐지를 처리할 run_inference 함수를 구현합니다. 이 예제에서는 모델 예측에서 경계 상자(BBox), 클래스 이름 및 신뢰도 점수를 추출합니다. 이 함수는 추가 처리나 주석을 위해 탐지 결과와 원시 결과를 포함하는 사전을 반환합니다.

def run_inference(input_image: Image.Image, confidence_threshold: float = 0.5) -> Dict[str, Any]:
    """Run inference on an image using YOLO26n model."""
    global model_yolo

    # Check if model is ready
    if not is_model_ready():
        print("Model not ready for inference")
        return {"detections": [], "results": None}

    try:
        # Make predictions and get raw results
        results = model_yolo.predict(
            imgsz=640, source=input_image, conf=confidence_threshold, save=False, augment=False, verbose=False
        )

        # Extract detections (bounding boxes, class names, and confidences)
        detections = []
        if results and len(results) > 0:
            result = results[0]
            if result.boxes is not None and len(result.boxes.xyxy) > 0:
                boxes = result.boxes

                # Convert tensors to numpy for processing
                xyxy = boxes.xyxy.cpu().numpy()
                conf = boxes.conf.cpu().numpy()
                cls = boxes.cls.cpu().numpy().astype(int)

                # Create detection dictionaries
                for i in range(len(xyxy)):
                    detection = {
                        "xmin": float(xyxy[i][0]),
                        "ymin": float(xyxy[i][1]),
                        "xmax": float(xyxy[i][2]),
                        "ymax": float(xyxy[i][3]),
                        "confidence": float(conf[i]),
                        "class": int(cls[i]),
                        "name": model_yolo.names.get(int(cls[i]), f"class_{int(cls[i])}"),
                    }
                    detections.append(detection)

        return {
            "detections": detections,
            "results": results,  # Keep raw results for annotation
        }
    except Exception as e:
        # If there's an error, return empty structure
        print(f"Error in YOLO detection: {e}")
        return {"detections": [], "results": None}

선택적으로, Ultralytics 내장 플롯 메서드를 사용하여 경계 상자와 라벨로 이미지에 주석을 달 수 있는 함수를 추가할 수 있습니다. 예측 응답에 주석이 달린 이미지를 반환하려는 경우 유용합니다.

def get_annotated_image(results: list) -> Image.Image:
    """Get annotated image using Ultralytics built-in plot method."""
    if not results or len(results) == 0:
        raise ValueError("No results provided for annotation")

    result = results[0]
    # Use Ultralytics built-in plot method with PIL output
    return result.plot(pil=True)

FastAPI로 HTTP 추론 서버 생성

이제 핵심 YOLO26 추론 로직이 준비되었으므로 이를 서비스할 FastAPI 애플리케이션을 생성할 수 있습니다. 여기에는 Vertex AI에서 요구하는 상태 확인 및 예측 엔드포인트가 포함됩니다.

먼저 임포트를 추가하고 Vertex AI를 위한 로깅을 구성합니다. Vertex AI는 stderr를 오류 출력으로 처리하므로 로그를 stdout으로 파이프하는 것이 좋습니다.

import sys

from loguru import logger

# Configure logger
logger.remove()
logger.add(
    sys.stdout,
    colorize=True,
    format="<green>{time:HH:mm:ss}</green> | <level>{message}</level>",
    level=10,
)
logger.add("log.log", rotation="1 MB", level="DEBUG", compression="zip")

완벽한 Vertex AI 준수를 위해 환경 변수에 필수 엔드포인트를 정의하고 요청 크기 제한을 설정합니다. 프로덕션 배포에는 비공개 Vertex AI 엔드포인트를 사용하는 것이 좋습니다. 이렇게 하면 공용 엔드포인트의 1.5MB 대신 10MB의 더 높은 요청 페이로드 제한을 가질 수 있으며, 강력한 보안 및 액세스 제어를 함께 누릴 수 있습니다.

# Vertex AI environment variables
AIP_HTTP_PORT = int(os.getenv("AIP_HTTP_PORT", "8080"))
AIP_HEALTH_ROUTE = os.getenv("AIP_HEALTH_ROUTE", "/health")
AIP_PREDICT_ROUTE = os.getenv("AIP_PREDICT_ROUTE", "/predict")

# Request size limit (10 MB for private endpoints, 1.5 MB for public)
MAX_REQUEST_SIZE = 10 * 1024 * 1024  # 10 MB in bytes

요청 및 응답을 검증하기 위한 두 개의 Pydantic 모델을 추가합니다.

# Pydantic models for request/response
class PredictionRequest(BaseModel):
    instances: list
    parameters: Optional[Dict[str, Any]] = None

class PredictionResponse(BaseModel):
    predictions: list

모델 준비 상태를 확인하기 위해 상태 확인 엔드포인트를 추가합니다. 이는 Vertex AI에 중요합니다. 전용 상태 확인 없이는 오케스트레이터가 임의의 소켓에 핑을 보내고 모델이 추론 준비가 되었는지 판단할 수 없기 때문입니다. 성공 시 200 OK, 실패 시 503 Service Unavailable을 반환해야 합니다.

# Health check endpoint
@app.get(AIP_HEALTH_ROUTE, status_code=status.HTTP_200_OK)
def health_check():
    """Health check endpoint for Vertex AI."""
    if not is_model_ready():
        raise HTTPException(status_code=503, detail="Model not ready")
    return {"status": "healthy"}

이제 추론 요청을 처리할 예측 엔드포인트를 구현할 모든 준비가 되었습니다. 이미지 파일을 받아 추론을 실행하고 결과를 반환합니다. 이미지는 base64로 인코딩되어야 하며, 이는 페이로드 크기를 최대 33%까지 증가시킵니다.

@app.post(AIP_PREDICT_ROUTE, response_model=PredictionResponse)
async def predict(request: PredictionRequest):
    """Prediction endpoint for Vertex AI."""
    try:
        predictions = []

        for instance in request.instances:
            if isinstance(instance, dict):
                if "image" in instance:
                    image_data = base64.b64decode(instance["image"])
                    input_image = get_image_from_bytes(image_data)
                else:
                    raise HTTPException(status_code=400, detail="Instance must contain 'image' field")
            else:
                raise HTTPException(status_code=400, detail="Invalid instance format")

            # Extract YOLO26 parameters if provided
            parameters = request.parameters or {}
            confidence_threshold = parameters.get("confidence", 0.5)
            return_annotated_image = parameters.get("return_annotated_image", False)

            # Run inference with YOLO26n model
            result = run_inference(input_image, confidence_threshold=confidence_threshold)
            detections_list = result["detections"]

            # Format predictions for Vertex AI
            detections = []
            for detection in detections_list:
                formatted_detection = {
                    "class": detection["name"],
                    "confidence": detection["confidence"],
                    "bbox": {
                        "xmin": detection["xmin"],
                        "ymin": detection["ymin"],
                        "xmax": detection["xmax"],
                        "ymax": detection["ymax"],
                    },
                }
                detections.append(formatted_detection)

            # Build prediction response
            prediction = {"detections": detections, "detection_count": len(detections)}

            # Add annotated image if requested and detections exist
            if (
                return_annotated_image
                and result["results"]
                and result["results"][0].boxes is not None
                and len(result["results"][0].boxes) > 0
            ):
                import base64

                annotated_image = get_annotated_image(result["results"])
                img_bytes = get_bytes_from_image(annotated_image)
                prediction["annotated_image"] = base64.b64encode(img_bytes).decode("utf-8")

            predictions.append(prediction)

        logger.info(
            f"Processed {len(request.instances)} instances, found {sum(len(p['detections']) for p in predictions)} total detections"
        )

        return PredictionResponse(predictions=predictions)

    except HTTPException:
        # Re-raise HTTPException as-is (don't catch and convert to 500)
        raise
    except Exception as e:
        logger.error(f"Prediction error: {e}")
        raise HTTPException(status_code=500, detail=f"Prediction failed: {e}")

마지막으로 FastAPI 서버를 실행하기 위한 애플리케이션 진입점을 추가합니다.

if __name__ == "__main__":
    import uvicorn

    logger.info(f"Starting server on port {AIP_HTTP_PORT}")
    logger.info(f"Health check route: {AIP_HEALTH_ROUTE}")
    logger.info(f"Predict route: {AIP_PREDICT_ROUTE}")
    uvicorn.run(app, host="0.0.0.0", port=AIP_HTTP_PORT)

이제 YOLO26 추론 요청을 처리할 수 있는 완전한 FastAPI 애플리케이션이 준비되었습니다. 종속성을 설치하고 예를 들어 uv와 같은 도구로 서버를 실행하여 로컬에서 테스트할 수 있습니다.

# Install dependencies
uv pip install -e .

# Run the FastAPI server directly
uv run src/main.py

서버를 테스트하려면 cURL을 사용하여 /health/predict 엔드포인트를 모두 쿼리할 수 있습니다. tests 폴더에 테스트 이미지를 넣으십시오. 그런 다음 터미널에서 다음 명령을 실행합니다.

# Test health endpoint
curl http://localhost:8080/health

# Test predict endpoint with base64 encoded image
curl -X POST -H "Content-Type: application/json" -d "{\"instances\": [{\"image\": \"$(base64 -i tests/test_image.jpg)\"}]}" http://localhost:8080/predict

탐지된 객체가 포함된 JSON 응답을 받아야 합니다. 첫 번째 요청 시 Ultralytics가 YOLO26 모델을 가져와 로드해야 하므로 약간의 지연이 발생할 수 있습니다.

애플리케이션과 함께 Ultralytics Docker 이미지 확장

Ultralytics는 애플리케이션 이미지의 기반으로 사용할 수 있는 여러 Docker 이미지를 제공합니다. Docker가 Ultralytics와 필요한 GPU 드라이버를 설치합니다.

Ultralytics YOLO 모델의 모든 기능을 사용하려면 GPU 추론을 위한 CUDA 최적화 이미지를 선택해야 합니다. 하지만 CPU 추론으로도 충분하다면 CPU 전용 이미지를 선택하여 컴퓨팅 리소스를 절약할 수 있습니다.

  • Dockerfile: YOLO26 단일/멀티 GPU 학습 및 추론을 위한 CUDA 최적화 이미지.
  • Dockerfile-cpu: YOLO26 추론을 위한 CPU 전용 이미지.

애플리케이션을 위한 Docker 이미지 생성

다음 내용으로 프로젝트 루트에 Dockerfile을 생성합니다.

# Extends official Ultralytics Docker image for YOLO26
FROM ultralytics/ultralytics:latest

ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1

# Install FastAPI and dependencies
RUN uv pip install fastapi[all] uvicorn[standard] loguru

WORKDIR /app
COPY src/ ./src/
COPY pyproject.toml ./

# Install the application package
RUN uv pip install -e .

RUN mkdir -p /app/logs
ENV PYTHONPATH=/app/src

# Port for Vertex AI
EXPOSE 8080

# Start the inference server
ENTRYPOINT ["python", "src/main.py"]

예제에서는 공식 Ultralytics Docker 이미지 ultralytics:latest가 베이스 이미지로 사용됩니다. 이 이미지에는 이미 YOLO26 모델과 필요한 모든 종속성이 포함되어 있습니다. 서버의 진입점은 로컬에서 FastAPI 애플리케이션을 테스트할 때 사용한 것과 동일합니다.

Docker 이미지 빌드 및 테스트

이제 다음 명령으로 Docker 이미지를 빌드할 수 있습니다.

docker build --platform linux/amd64 -t IMAGE_NAME:IMAGE_VERSION .

IMAGE_NAMEIMAGE_VERSIONyolo26-fastapi:0.1과 같이 원하는 값으로 바꿉니다. Vertex AI에 배포하는 경우 linux/amd64 아키텍처용으로 이미지를 빌드해야 합니다. Apple Silicon Mac이나 다른 비 x86 아키텍처에서 이미지를 빌드하는 경우 --platform 매개변수를 명시적으로 설정해야 합니다.

이미지 빌드가 완료되면 로컬에서 Docker 이미지를 테스트할 수 있습니다.

docker run --platform linux/amd64 -p 8080:8080 IMAGE_NAME:IMAGE_VERSION

Docker 컨테이너가 이제 포트 8080에서 FastAPI 서버를 실행하며 추론 요청을 받을 준비가 되었습니다. 이전과 동일한 cURL 명령으로 /health/predict 엔드포인트를 모두 테스트할 수 있습니다.

# Test health endpoint
curl http://localhost:8080/health

# Test predict endpoint with base64 encoded image
curl -X POST -H "Content-Type: application/json" -d "{\"instances\": [{\"image\": \"$(base64 -i tests/test_image.jpg)\"}]}" http://localhost:8080/predict

GCP Artifact Registry에 Docker 이미지 업로드

컨테이너화된 모델을 Vertex AI로 가져오려면 Docker 이미지를 Google Cloud Artifact Registry에 업로드해야 합니다. 아직 Artifact Registry 리포지토리가 없다면 먼저 생성해야 합니다.

Google Cloud Artifact Registry에 리포지토리 생성

Google Cloud Console에서 Artifact Registry 페이지를 엽니다. Artifact Registry를 처음 사용하는 경우 먼저 Artifact Registry API를 활성화하라는 메시지가 표시될 수 있습니다.

Google Cloud Artifact Registry repository creation

  1. 리포지토리 생성을 선택합니다.
  2. 리포지토리 이름을 입력합니다. 원하는 리전을 선택하고, 특별히 변경해야 할 경우가 아니면 다른 옵션은 기본 설정을 사용합니다.
참고

리전 선택은 머신의 가용성 및 엔터프라이즈가 아닌 사용자에 대한 특정 컴퓨팅 제한에 영향을 줄 수 있습니다. 자세한 내용은 Vertex AI 공식 문서인 Vertex AI 할당량 및 제한에서 확인할 수 있습니다.

  1. 리포지토리가 생성되면 PROJECT_ID, 위치(리전) 및 리포지토리 이름을 비밀 저장소나 .env 파일에 저장합니다. 나중에 도커 이미지를 태그 지정하고 Artifact Registry로 푸시할 때 필요합니다.

Artifact Registry에 Docker 인증

방금 생성한 Artifact Registry 리포지토리에 Docker 클라이언트를 인증합니다. 터미널에서 다음 명령을 실행합니다.

gcloud auth configure-docker YOUR_REGION-docker.pkg.dev

이미지 태그 지정 및 Artifact Registry로 푸시

Docker 이미지를 Google Artifact Registry에 태그 지정하고 푸시합니다.

이미지에 고유 태그 사용

이미지를 업데이트할 때마다 고유한 태그를 사용하는 것이 좋습니다. Vertex AI를 포함한 대부분의 GCP 서비스는 자동 버전 관리 및 확장을 위해 이미지 태그에 의존하므로 시맨틱 버전 관리나 날짜 기반 태그를 사용하는 것이 좋은 방법입니다.

Artifact Registry 리포지토리 URL로 이미지에 태그를 지정합니다. 자리 표시자를 이전에 저장한 값으로 바꿉니다.

docker tag IMAGE_NAME:IMAGE_VERSION YOUR_REGION-docker.pkg.dev/YOUR_PROJECT_ID/YOUR_REPOSITORY_NAME/IMAGE_NAME:IMAGE_VERSION

태그가 지정된 이미지를 Artifact Registry 리포지토리에 푸시합니다.

docker push YOUR_REGION-docker.pkg.dev/YOUR_PROJECT_ID/YOUR_REPOSITORY_NAME/IMAGE_NAME:IMAGE_VERSION

프로세스가 완료될 때까지 기다립니다. 이제 Artifact Registry 리포지토리에서 이미지를 볼 수 있습니다.

Artifact Registry에서 이미지 작업에 대한 자세한 지침은 Artifact Registry 문서인 이미지 푸시 및 풀을 참조하십시오.

Vertex AI에서 모델 가져오기

방금 푸시한 Docker 이미지를 사용하여 이제 Vertex AI에서 모델을 가져올 수 있습니다.

  1. Google Cloud 탐색 메뉴에서 Vertex AI > 모델 레지스트리로 이동합니다. 또는 Google Cloud Console 상단의 검색창에서 "Vertex AI"를 검색합니다.

Vertex AI Model Registry import interface

1. Click Import. 1. Select Import as a new model. 1. Select the region. You can choose the same region as your Artifact Registry repository, but your selection should be dictated by the availability of machine types and quotas in your region. 1. Select Import an existing model container.

Vertex AI import model dialog

1. In the Container image field, browse the Artifact Registry repository you created earlier and select the image you just pushed. 1. Scroll down to the Environment variables section and enter the predict and health endpoints, and the port that you defined in your FastAPI application.

Vertex AI environment variables configuration

1. Click Import. Vertex AI will take several minutes to register the model and prepare it for deployment. You will receive an email notification once the import is complete.

Vertex AI 엔드포인트 생성 및 모델 배포

Vertex AI의 엔드포인트 vs 모델

Vertex AI 용어에서 엔드포인트는 추론 요청을 보내는 HTTP 종단점을 나타내므로 배포된 모델을 의미하며, 모델은 모델 레지스트리에 저장된 학습된 ML 아티팩트입니다.

모델을 배포하려면 Vertex AI에서 엔드포인트를 생성해야 합니다.

  1. Vertex AI 탐색 메뉴에서 엔드포인트로 이동합니다. 모델을 가져올 때 사용한 리전을 선택합니다. 만들기를 클릭합니다.

Vertex AI create endpoint interface

1. Enter the Endpoint name. 1. For Access, Vertex AI recommends using private Vertex AI endpoints. Apart from security benefits, you get a higher payload limit if you select a private endpoint, however you will need to configure your VPC network and firewall rules to allow access to the endpoint. Refer to the Vertex AI documentation for more instructions on [private endpoints](https://docs.cloud.google.com/vertex-ai/docs/predictions/choose-endpoint-type). 1. Click Continue. 1. On the Model settings dialog, select the model you imported earlier. Now you can configure the machine type, memory, and GPU settings for your model. Allow for ample memory if you are expecting high inference loads to ensure there are no I/O bottlenecks for the proper YOLO26 performance. 1. In Accelerator type, select the GPU type you want to use for inference. If you are not sure which GPU to select, you can start with NVIDIA T4, which is CUDA-supported.
리전 및 머신 유형 할당량

특정 리전에는 컴퓨팅 할당량이 매우 제한되어 있으므로 해당 리전에서 특정 머신 유형이나 GPU를 선택할 수 없을 수도 있습니다. 이것이 중요하다면 배포 리전을 더 큰 할당량이 있는 곳으로 변경하십시오. 자세한 내용은 Vertex AI 공식 문서인 Vertex AI 할당량 및 제한에서 확인할 수 있습니다.

  1. 머신 유형이 선택되면 계속을 클릭할 수 있습니다. 이 시점에서 모델의 성능을 추적하고 동작에 대한 통찰력을 제공하는 추가 서비스인 Vertex AI 모델 모니터링을 활성화할 수 있습니다. 이는 선택 사항이며 추가 비용이 발생하므로 필요에 따라 선택하십시오. 만들기를 클릭합니다.

Vertex AI가 모델을 배포하는 데 몇 분(일부 리전에서는 최대 30분)이 소요됩니다. 배포가 완료되면 이메일 알림을 받게 됩니다.

배포된 모델 테스트

배포가 완료되면 Vertex AI에서 모델을 테스트할 수 있는 샘플 API 인터페이스를 제공합니다.

원격 추론을 테스트하려면 제공된 cURL 명령을 사용하거나 배포된 모델로 요청을 보낼 다른 Python 클라이언트 라이브러리를 생성할 수 있습니다. /predict 엔드포인트로 이미지를 보내기 전에 base64로 인코딩해야 함을 기억하십시오.

Vertex AI endpoint testing with cURL

첫 번째 요청 시 약간의 지연 예상

로컬 테스트와 마찬가지로, Ultralytics가 실행 중인 컨테이너에서 YOLO26 모델을 가져와 로드해야 하므로 첫 번째 요청 시 약간의 지연이 발생할 수 있습니다.

Google Cloud Vertex AI에 Ultralytics를 사용하여 사전 학습된 YOLO26 모델을 성공적으로 배포했습니다.

FAQ

Docker 없이 Vertex AI에서 Ultralytics YOLO 모델을 사용할 수 있나요?

네, 가능합니다. 하지만 먼저 모델을 TensorFlow, Scikit-learn 또는 XGBoost와 같이 Vertex AI와 호환되는 형식으로 내보내야 합니다. Google Cloud는 .pt 모델을 Vertex에서 실행하는 방법에 대한 변환 과정의 전체 개요를 제공하는 가이드를 보유하고 있습니다: Vertex AI에서 PyTorch 모델 실행.

결과 설정은 Vertex AI 표준 서빙 레이어에만 의존하며 고급 Ultralytics 프레임워크 기능은 지원하지 않는다는 점에 유의하십시오. Vertex AI는 컨테이너화된 모델을 완벽하게 지원하고 배포 구성에 따라 자동으로 확장할 수 있으므로, 다른 형식으로 변환할 필요 없이 Ultralytics YOLO 모델의 모든 기능을 활용할 수 있습니다.

FastAPI가 YOLO26 추론 서비스를 제공하는 데 좋은 선택인 이유는 무엇입니까?

FastAPI는 추론 워크로드에 대해 높은 처리량을 제공합니다. 비동기(Async) 지원을 통해 메인 스레드를 차단하지 않고 다수의 동시 요청을 처리할 수 있으며, 이는 컴퓨터 비전 모델을 서비스할 때 중요합니다.

FastAPI의 자동 요청/응답 유효성 검사는 프로덕션 추론 서비스에서 런타임 오류를 줄여줍니다. 이는 입력 형식의 일관성이 중요한 객체 탐지 API에서 특히 유용합니다.

FastAPI는 추론 파이프라인에 최소한의 컴퓨팅 오버헤드만을 추가하므로, 모델 실행 및 이미지 처리 작업에 더 많은 리소스를 할당할 수 있습니다.

또한 FastAPI는 스트리밍 추론 시나리오에 유용한 SSE(Server-Sent Events)를 지원합니다.

왜 리전을 여러 번 선택해야 합니까?

이는 Google Cloud Platform의 범용성을 위한 기능으로, 사용하는 모든 서비스마다 리전을 선택해야 합니다. Vertex AI에 컨테이너화된 모델을 배포하는 작업의 경우, 가장 중요한 리전 선택은 Model Registry에 대한 것입니다. 이는 모델 배포 시 사용할 수 있는 머신 유형과 할당량(quota)을 결정합니다.

또한 향후 설정을 확장하여 예측 데이터나 결과를 Cloud Storage 또는 BigQuery에 저장할 경우, 데이터 액세스의 지연 시간을 최소화하고 높은 처리량을 보장하기 위해 Model Registry와 동일한 리전을 사용해야 합니다.

댓글