Chuyển đến nội dung

Ultralytics TRUNG TÂM Inference API

Sau khi huấn luyện mô hình , bạn có thể sử dụng Inference API Chia sẻ miễn phí. Nếu bạn là người dùng Pro , bạn có thể truy cập Inference API Chuyên dụng . Trung tâm Ultralytics Inference API cho phép bạn chạy suy luận thông qua REST API không cần phải cài đặt và thiết lập Ultralytics YOLO môi trường tại địa phương.

Ultralytics Ảnh chụp màn hình HUB của tab Triển khai bên trong trang Mô hình với mũi tên trỏ đến Dành riêng Inference API thẻ và một thẻ cho mục Chia sẻ Inference API thẻ


Xem: Ultralytics TRUNG TÂM Inference API Hướng dẫn

Tận tụy Inference API

Để đáp ứng nhu cầu cao và sự quan tâm rộng rãi, chúng tôi rất vui mừng được giới thiệu Ultralytics HUB dành riêng Inference API , cung cấp khả năng triển khai chỉ bằng một cú nhấp chuột trong môi trường chuyên dụng dành cho người dùng Pro của chúng tôi!

Lưu ý

Chúng tôi rất vui mừng được cung cấp tính năng này MIỄN PHÍ trong giai đoạn beta công khai như một phần của Gói Pro, với các cấp trả phí có thể có trong tương lai.

  • Phạm vi toàn cầu: Được triển khai trên 38 khu vực trên toàn thế giới, đảm bảo truy cập với độ trễ thấp từ mọi vị trí. Xem danh sách đầy đủ các khu vực của Google Cloud.
  • Được hỗ trợ bởi Google Cloud Run: Được hỗ trợ bởi Google Cloud Run, cung cấp cơ sở hạ tầng có khả năng mở rộng vô hạn và độ tin cậy cao.
  • Tốc độ cao: Độ trễ dưới 100ms có thể đạt được để suy luận YOLOv8n ở độ phân giải 640 từ các khu vực lân cận dựa trên thử nghiệm của Ultralytics.
  • Nâng cao tính bảo mật: Cung cấp các tính năng bảo mật mạnh mẽ để bảo vệ dữ liệu của bạn và đảm bảo tuân thủ các tiêu chuẩn ngành. Tìm hiểu thêm về bảo mật trên Google Cloud.

Để sử dụng Ultralytics HUB chuyên dụng Inference API , nhấp vào nút Bắt đầu Điểm cuối . Tiếp theo, sử dụng URL điểm cuối duy nhất như được mô tả trong hướng dẫn bên dưới.

Ultralytics Ảnh chụp màn hình HUB của tab Triển khai bên trong trang Mô hình với mũi tên trỏ đến nút Bắt đầu điểm cuối trong Dành riêng Inference API thẻ

Mẹo

Chọn khu vực có độ trễ thấp nhất để có hiệu suất tốt nhất như được mô tả trong tài liệu.

Để tắt endpoint chuyên dụng, hãy nhấp vào nút Dừng Endpoint.

Ultralytics Ảnh chụp màn hình HUB của tab Triển khai bên trong trang Mô hình với mũi tên trỏ đến nút Dừng điểm cuối trong Chuyên dụng Inference API thẻ

Chia sẻ Inference API

Để sử dụng Ultralytics HUB Shared Inference API , hãy làm theo hướng dẫn bên dưới.

Trung tâm chia sẻ Ultralytics Inference API có các giới hạn sử dụng sau:

  • 100 cuộc gọi / giờ

Python

Để truy cập Ultralytics HUB Inference API sử dụng Python , sử dụng mã sau:

import requests

# API URL
url = "https://predict.ultralytics.com"

# Headers, use actual API_KEY
headers = {"x-api-key": "API_KEY"}

# Inference arguments (use actual MODEL_ID)
data = {"model": "https://hub.ultralytics.com/models/MODEL_ID", "imgsz": 640, "conf": 0.25, "iou": 0.45}

# Load image and send request
with open("path/to/image.jpg", "rb") as image_file:
    files = {"file": image_file}
    response = requests.post(url, headers=headers, files=files, data=data)

print(response.json())

Lưu ý

Thay thế MODEL_ID với ID mô hình mong muốn, API_KEY với khóa API thực tế của bạn và path/to/image.jpg với đường dẫn đến hình ảnh bạn muốn chạy suy luận.

Nếu bạn đang sử dụng Tận tụy Inference API, hãy thay thế url nữa.

cURL

Để truy cập Ultralytics HUB Inference API sử dụng cURL, hãy sử dụng mã sau:

curl -X POST "https://predict.ultralytics.com" \
  -H "x-api-key: API_KEY" \
  -F "model=https://hub.ultralytics.com/models/MODEL_ID" \
  -F "file=@/path/to/image.jpg" \
  -F "imgsz=640" \
  -F "conf=0.25" \
  -F "iou=0.45"

Lưu ý

Thay thế MODEL_ID với ID mô hình mong muốn, API_KEY với khóa API thực tế của bạn và path/to/image.jpg với đường dẫn đến hình ảnh bạn muốn chạy suy luận.

Nếu bạn đang sử dụng Tận tụy Inference API, hãy thay thế url nữa.

Các đối số

Xem bảng dưới đây để có danh sách đầy đủ các đối số suy luận có sẵn.

Đối sốMặc địnhLoạiMô tả
filefileTệp hình ảnh hoặc video được sử dụng để suy luận.
imgsz640intKích thước của ảnh đầu vào, phạm vi hợp lệ là 32 - 1280 pixel.
conf0.25floatNgưỡng tin cậy cho các dự đoán, phạm vi hợp lệ 0.01 - 1.0.
iou0.45floatIntersection over Union ngưỡng (IoU), phạm vi hợp lệ 0.0 - 0.95.

Phản hồi

Trung tâm Ultralytics Inference API trả về phản hồi JSON.

Phân loại (Classification)

Mô hình phân loại

from ultralytics import YOLO

# Load model
model = YOLO("yolov8n-cls.pt")

# Run inference
results = model("image.jpg")

# Print image.jpg results in JSON format
print(results[0].to_json())
curl -X POST "https://predict.ultralytics.com" \
  -H "x-api-key: API_KEY" \
  -F "model=https://hub.ultralytics.com/models/MODEL_ID" \
  -F "file=@/path/to/image.jpg" \
  -F "imgsz=640" \
  -F "conf=0.25" \
  -F "iou=0.45"
import requests

# API URL
url = "https://predict.ultralytics.com"

# Headers, use actual API_KEY
headers = {"x-api-key": "API_KEY"}

# Inference arguments (use actual MODEL_ID)
data = {"model": "https://hub.ultralytics.com/models/MODEL_ID", "imgsz": 640, "conf": 0.25, "iou": 0.45}

# Load image and send request
with open("path/to/image.jpg", "rb") as image_file:
    files = {"file": image_file}
    response = requests.post(url, headers=headers, files=files, data=data)

print(response.json())
{
  "images": [
    {
      "results": [
        {
          "class": 0,
          "name": "person",
          "confidence": 0.92
        }
      ],
      "shape": [
        750,
        600
      ],
      "speed": {
        "inference": 200.8,
        "postprocess": 0.8,
        "preprocess": 2.8
      }
    }
  ],
  "metadata": ...
}

Phát hiện vật thể

Mô hình phát hiện

from ultralytics import YOLO

# Load model
model = YOLO("yolov8n.pt")

# Run inference
results = model("image.jpg")

# Print image.jpg results in JSON format
print(results[0].to_json())
curl -X POST "https://predict.ultralytics.com" \
  -H "x-api-key: API_KEY" \
  -F "model=https://hub.ultralytics.com/models/MODEL_ID" \
  -F "file=@/path/to/image.jpg" \
  -F "imgsz=640" \
  -F "conf=0.25" \
  -F "iou=0.45"
import requests

# API URL
url = "https://predict.ultralytics.com"

# Headers, use actual API_KEY
headers = {"x-api-key": "API_KEY"}

# Inference arguments (use actual MODEL_ID)
data = {"model": "https://hub.ultralytics.com/models/MODEL_ID", "imgsz": 640, "conf": 0.25, "iou": 0.45}

# Load image and send request
with open("path/to/image.jpg", "rb") as image_file:
    files = {"file": image_file}
    response = requests.post(url, headers=headers, files=files, data=data)

print(response.json())
{
  "images": [
    {
      "results": [
        {
          "class": 0,
          "name": "person",
          "confidence": 0.92,
          "box": {
            "x1": 118,
            "x2": 416,
            "y1": 112,
            "y2": 660
          }
        }
      ],
      "shape": [
        750,
        600
      ],
      "speed": {
        "inference": 200.8,
        "postprocess": 0.8,
        "preprocess": 2.8
      }
    }
  ],
  "metadata": ...
}

OBB

Mô hình OBB

from ultralytics import YOLO

# Load model
model = YOLO("yolov8n-obb.pt")

# Run inference
results = model("image.jpg")

# Print image.jpg results in JSON format
print(results[0].tojson())
curl -X POST "https://predict.ultralytics.com" \
  -H "x-api-key: API_KEY" \
  -F "model=https://hub.ultralytics.com/models/MODEL_ID" \
  -F "file=@/path/to/image.jpg" \
  -F "imgsz=640" \
  -F "conf=0.25" \
  -F "iou=0.45"
import requests

# API URL
url = "https://predict.ultralytics.com"

# Headers, use actual API_KEY
headers = {"x-api-key": "API_KEY"}

# Inference arguments (use actual MODEL_ID)
data = {"model": "https://hub.ultralytics.com/models/MODEL_ID", "imgsz": 640, "conf": 0.25, "iou": 0.45}

# Load image and send request
with open("path/to/image.jpg", "rb") as image_file:
    files = {"file": image_file}
    response = requests.post(url, headers=headers, files=files, data=data)

print(response.json())
{
  "images": [
    {
      "results": [
        {
          "class": 0,
          "name": "person",
          "confidence": 0.92,
          "box": {
            "x1": 374.85565,
            "x2": 392.31824,
            "x3": 412.81805,
            "x4": 395.35547,
            "y1": 264.40704,
            "y2": 267.45728,
            "y3": 150.0966,
            "y4": 147.04634
          }
        }
      ],
      "shape": [
        750,
        600
      ],
      "speed": {
        "inference": 200.8,
        "postprocess": 0.8,
        "preprocess": 2.8
      }
    }
  ],
  "metadata": ...
}

Phân đoạn

Mô hình phân đoạn

from ultralytics import YOLO

# Load model
model = YOLO("yolov8n-seg.pt")

# Run inference
results = model("image.jpg")

# Print image.jpg results in JSON format
print(results[0].tojson())
curl -X POST "https://predict.ultralytics.com" \
  -H "x-api-key: API_KEY" \
  -F "model=https://hub.ultralytics.com/models/MODEL_ID" \
  -F "file=@/path/to/image.jpg" \
  -F "imgsz=640" \
  -F "conf=0.25" \
  -F "iou=0.45"
import requests

# API URL
url = "https://predict.ultralytics.com"

# Headers, use actual API_KEY
headers = {"x-api-key": "API_KEY"}

# Inference arguments (use actual MODEL_ID)
data = {"model": "https://hub.ultralytics.com/models/MODEL_ID", "imgsz": 640, "conf": 0.25, "iou": 0.45}

# Load image and send request
with open("path/to/image.jpg", "rb") as image_file:
    files = {"file": image_file}
    response = requests.post(url, headers=headers, files=files, data=data)

print(response.json())
{
  "images": [
    {
      "results": [
        {
          "class": 0,
          "name": "person",
          "confidence": 0.92,
          "box": {
            "x1": 118,
            "x2": 416,
            "y1": 112,
            "y2": 660
          },
          "segments": {
            "x": [
              266.015625,
              266.015625,
              258.984375,
              ...
            ],
            "y": [
              110.15625,
              113.67188262939453,
              120.70311737060547,
              ...
            ]
          }
        }
      ],
      "shape": [
        750,
        600
      ],
      "speed": {
        "inference": 200.8,
        "postprocess": 0.8,
        "preprocess": 2.8
      }
    }
  ],
  "metadata": ...
}

Pose (Dáng điệu/Tư thế)

Mô Hình Tư Thế

from ultralytics import YOLO

# Load model
model = YOLO("yolov8n-pose.pt")

# Run inference
results = model("image.jpg")

# Print image.jpg results in JSON format
print(results[0].tojson())
curl -X POST "https://predict.ultralytics.com" \
  -H "x-api-key: API_KEY" \
  -F "model=https://hub.ultralytics.com/models/MODEL_ID" \
  -F "file=@/path/to/image.jpg" \
  -F "imgsz=640" \
  -F "conf=0.25" \
  -F "iou=0.45"
import requests

# API URL
url = "https://predict.ultralytics.com"

# Headers, use actual API_KEY
headers = {"x-api-key": "API_KEY"}

# Inference arguments (use actual MODEL_ID)
data = {"model": "https://hub.ultralytics.com/models/MODEL_ID", "imgsz": 640, "conf": 0.25, "iou": 0.45}

# Load image and send request
with open("path/to/image.jpg", "rb") as image_file:
    files = {"file": image_file}
    response = requests.post(url, headers=headers, files=files, data=data)

print(response.json())
{
  "images": [
    {
      "results": [
        {
          "class": 0,
          "name": "person",
          "confidence": 0.92,
          "box": {
            "x1": 118,
            "x2": 416,
            "y1": 112,
            "y2": 660
          },
          "keypoints": {
            "visible": [
              0.9909399747848511,
              0.8162999749183655,
              0.9872099757194519,
              ...
            ],
            "x": [
              316.3871765136719,
              315.9374694824219,
              304.878173828125,
              ...
            ],
            "y": [
              156.4207763671875,
              148.05775451660156,
              144.93240356445312,
              ...
            ]
          }
        }
      ],
      "shape": [
        750,
        600
      ],
      "speed": {
        "inference": 200.8,
        "postprocess": 0.8,
        "preprocess": 2.8
      }
    }
  ],
  "metadata": ...
}


📅 Đã tạo 1 năm trước ✏️ Cập nhật 8 tháng trước
glenn-jochersergiuwaxmannMatthewNoycejk4eUltralyticsAssistantRizwanMunawarpriytosh-tripathi

Bình luận