์ฝ˜ํ…์ธ ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

Ultralytics HUB ์ถ”๋ก  API

Ultralytics HUB ์ถ”๋ก  API๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด Ultralytics YOLO ํ™˜๊ฒฝ์„ ๋กœ์ปฌ์— ์„ค์น˜ ๋ฐ ์„ค์ •ํ•  ํ•„์š” ์—†์ด REST API๋ฅผ ํ†ตํ•ด ์ถ”๋ก ์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Ultralytics ๋ชจ๋ธ ํŽ˜์ด์ง€ ๋‚ด ๋ฐฐํฌ ํƒญ์˜ ํ—ˆ๋ธŒ ์Šคํฌ๋ฆฐ์ƒท( Ultralytics ์ถ”๋ก  API ์นด๋“œ๋ฅผ ๊ฐ€๋ฆฌํ‚ค๋Š” ํ™”์‚ดํ‘œ ํฌํ•จ)


Watch: Ultralytics HUB ์ถ”๋ก  API ์—ฐ์Šต

Python

Python ์„ ์‚ฌ์šฉํ•˜์—ฌ Ultralytics HUB ์ถ”๋ก  API์— ์•ก์„ธ์Šคํ•˜๋ ค๋ฉด ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค:

import requests

# API URL, use actual MODEL_ID
url = "https://api.ultralytics.com/v1/predict/MODEL_ID"

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

# Inference arguments (optional)
data = {"size": 640, "confidence": 0.25, "iou": 0.45}

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

print(response.json())

์ฐธ๊ณ 

๊ต์ฒด MODEL_ID ๋ฅผ ์›ํ•˜๋Š” ๋ชจ๋ธ ID์™€ ํ•จ๊ป˜ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค, API_KEY ์‹ค์ œ API ํ‚ค์™€ path/to/image.jpg ๋ฅผ ์ถ”๋ก ์„ ์‹คํ–‰ํ•˜๋ ค๋Š” ์ด๋ฏธ์ง€์˜ ๊ฒฝ๋กœ์™€ ํ•จ๊ป˜ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

cURL

cURL์„ ์‚ฌ์šฉํ•˜์—ฌ Ultralytics HUB ์ถ”๋ก  API์— ์•ก์„ธ์Šคํ•˜๋ ค๋ฉด ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค:

curl -X POST "https://api.ultralytics.com/v1/predict/MODEL_ID" \
    -H "x-api-key: API_KEY" \
    -F "image=@/path/to/image.jpg" \
    -F "size=640" \
    -F "confidence=0.25" \
    -F "iou=0.45"

์ฐธ๊ณ 

๊ต์ฒด MODEL_ID ๋ฅผ ์›ํ•˜๋Š” ๋ชจ๋ธ ID์™€ ํ•จ๊ป˜ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค, API_KEY ์‹ค์ œ API ํ‚ค์™€ path/to/image.jpg ๋ฅผ ์ถ”๋ก ์„ ์‹คํ–‰ํ•˜๋ ค๋Š” ์ด๋ฏธ์ง€์˜ ๊ฒฝ๋กœ์™€ ํ•จ๊ป˜ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

์ธ์ˆ˜

์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์ถ”๋ก  ์ธ์ˆ˜์˜ ์ „์ฒด ๋ชฉ๋ก์€ ์•„๋ž˜ ํ‘œ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

์ธ์ˆ˜ ๊ธฐ๋ณธ๊ฐ’ ์œ ํ˜• ์„ค๋ช…
image image ์ถ”๋ก ์— ์‚ฌ์šฉํ•  ์ด๋ฏธ์ง€ ํŒŒ์ผ์ž…๋‹ˆ๋‹ค.
url str ํŒŒ์ผ์„ ์ „๋‹ฌํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ ์ด๋ฏธ์ง€์˜ URL์ž…๋‹ˆ๋‹ค.
size 640 int ์ž…๋ ฅ ์ด๋ฏธ์ง€์˜ ํฌ๊ธฐ, ์œ ํšจํ•œ ๋ฒ”์œ„๋Š” 32 - 1280 ํ”ฝ์…€.
confidence 0.25 float ์˜ˆ์ธก์— ๋Œ€ํ•œ ์‹ ๋ขฐ๋„ ์ž„๊ณ„๊ฐ’, ์œ ํšจ ๋ฒ”์œ„ 0.01 - 1.0.
iou 0.45 float IoU(Union) ์ž„๊ณ„๊ฐ’์„ ์ดˆ๊ณผํ•˜๋Š” ๊ต์ฐจ์ , ์œ ํšจํ•œ ๋ฒ”์œ„ 0.0 - 0.95.

์‘๋‹ต

Ultralytics HUB ์ถ”๋ก  API๋Š” JSON ์‘๋‹ต์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

๋ถ„๋ฅ˜

๋ถ„๋ฅ˜ ๋ชจ๋ธ

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].tojson())
curl -X POST "https://api.ultralytics.com/v1/predict/MODEL_ID" \
    -H "x-api-key: API_KEY" \
    -F "image=@/path/to/image.jpg" \
    -F "size=640" \
    -F "confidence=0.25" \
    -F "iou=0.45"
import requests

# API URL, use actual MODEL_ID
url = "https://api.ultralytics.com/v1/predict/MODEL_ID"

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

# Inference arguments (optional)
data = {"size": 640, "confidence": 0.25, "iou": 0.45}

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

print(response.json())
{
  success: true,
  message: "Inference complete.",
  data: [
    {
      class: 0,
      name: "person",
      confidence: 0.92
    }
  ]
}

ํƒ์ง€

ํƒ์ง€ ๋ชจ๋ธ

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].tojson())
curl -X POST "https://api.ultralytics.com/v1/predict/MODEL_ID" \
    -H "x-api-key: API_KEY" \
    -F "image=@/path/to/image.jpg" \
    -F "size=640" \
    -F "confidence=0.25" \
    -F "iou=0.45"
import requests

# API URL, use actual MODEL_ID
url = "https://api.ultralytics.com/v1/predict/MODEL_ID"

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

# Inference arguments (optional)
data = {"size": 640, "confidence": 0.25, "iou": 0.45}

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

print(response.json())
{
  success: true,
  message: "Inference complete.",
  data: [
    {
      class: 0,
      name: "person",
      confidence: 0.92,
      width: 0.4893378019332886,
      height: 0.7437513470649719,
      xcenter: 0.4434437155723572,
      ycenter: 0.5198975801467896
    }
  ]
}

OBB

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://api.ultralytics.com/v1/predict/MODEL_ID" \
    -H "x-api-key: API_KEY" \
    -F "image=@/path/to/image.jpg" \
    -F "size=640" \
    -F "confidence=0.25" \
    -F "iou=0.45"
import requests

# API URL, use actual MODEL_ID
url = "https://api.ultralytics.com/v1/predict/MODEL_ID"

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

# Inference arguments (optional)
data = {"size": 640, "confidence": 0.25, "iou": 0.45}

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

print(response.json())
{
  success: true,
  message: "Inference complete.",
  data: [
    {
      class: 0,
      name: "person",
      confidence: 0.92,
      obb: [
        0.669310450553894,
        0.6247171759605408,
        0.9847468137741089,
        ...
      ]
    }
  ]
}

์„ธ๋ถ„ํ™”

์„ธ๋ถ„ํ™” ๋ชจ๋ธ

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://api.ultralytics.com/v1/predict/MODEL_ID" \
    -H "x-api-key: API_KEY" \
    -F "image=@/path/to/image.jpg" \
    -F "size=640" \
    -F "confidence=0.25" \
    -F "iou=0.45"
import requests

# API URL, use actual MODEL_ID
url = "https://api.ultralytics.com/v1/predict/MODEL_ID"

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

# Inference arguments (optional)
data = {"size": 640, "confidence": 0.25, "iou": 0.45}

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

print(response.json())
{
  success: true,
  message: "Inference complete.",
  data: [
    {
      class: 0,
      name: "person",
      confidence: 0.92,
      segment: [0.44140625, 0.15625, 0.439453125, ...]
    }
  ]
}

ํฌ์ฆˆ

ํฌ์ฆˆ ๋ชจ๋ธ

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://api.ultralytics.com/v1/predict/MODEL_ID" \
    -H "x-api-key: API_KEY" \
    -F "image=@/path/to/image.jpg" \
    -F "size=640" \
    -F "confidence=0.25" \
    -F "iou=0.45"
import requests

# API URL, use actual MODEL_ID
url = "https://api.ultralytics.com/v1/predict/MODEL_ID"

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

# Inference arguments (optional)
data = {"size": 640, "confidence": 0.25, "iou": 0.45}

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

print(response.json())
{
  success: true,
  message: "Inference complete.",
  data: [
    {
      class: 0,
      name: "person",
      confidence: 0.92,
      keypoints: [
        0.5290805697441101,
        0.20698919892311096,
        1.0,
        0.5263055562973022,
        0.19584226608276367,
        1.0,
        0.5094948410987854,
        0.19120082259178162,
        1.0,
        ...
      ]
    }
  ]
}


์ƒ์„ฑ 2024-01-23, ์—…๋ฐ์ดํŠธ 2024-06-22
์ž‘์„ฑ์ž: glenn-jocher (9), sergiuwaxmann (2), RizwanMunawar (1), priytosh-tripathi (1)

๋Œ“๊ธ€