Ultralytics HUB Inference API
Nachdem Sie ein Modell trainiert haben, können Sie die Shared Inference API kostenlos nutzen. Wenn Sie ein Pro-Benutzer sind, können Sie auf die Dedicated Inference API zugreifen. Mit der Ultralytics HUB Inference API können Sie Inferenzen über unsere REST API durchführen, ohne die Ultralytics YOLO lokal installieren und einrichten zu müssen.

Ansehen: Ultralytics HUB Inference API Komplettlösung
Dedizierte Inference API
Als Reaktion auf die große Nachfrage und das breite Interesse freuen wir uns, die Ultralytics HUB Dedicated Inference API vorzustellen, die unseren Pro-Benutzern eine Ein-Klick-Bereitstellung in einer dedizierten Umgebung bietet!
Hinweis
Wir freuen uns, diese Funktion während unserer öffentlichen Beta-Phase als Teil des Pro Plans KOSTENLOS anzubieten, wobei in Zukunft kostenpflichtige Stufen möglich sind.
- Globale Abdeckung: Bereitgestellt in 38 Regionen weltweit, um einen latenzarmen Zugriff von jedem Standort aus zu gewährleisten. Sehen Sie sich die vollständige Liste der Google Cloud-Regionen an.
- Unterstützung durch Google Cloud Run: Unterstützt durch Google Cloud Run, das eine unendlich skalierbare und hochzuverlässige Infrastruktur bietet.
- Hohe Geschwindigkeit: Eine Latenz von unter 100 ms ist für die YOLOv8n-Inferenz bei einer Auflösung von 640 aus naheliegenden Regionen basierend auf Ultralytics-Tests möglich.
- Erhöhte Sicherheit: Bietet robuste Sicherheitsfunktionen, um Ihre Daten zu schützen und die Einhaltung von Industriestandards sicherzustellen. Erfahren Sie mehr über die Sicherheit von Google Cloud.
Um die Ultralytics HUB Dedicated Inference API zu verwenden, klicken Sie auf die Schaltfläche Start Endpoint. Verwenden Sie dann die eindeutige Endpunkt-URL wie in den nachstehenden Anleitungen beschrieben.

Tipp
Wählen Sie die Region mit der geringsten Latenz für die beste Leistung, wie in der Dokumentation beschrieben.
Um den dedizierten Endpunkt herunterzufahren, klicken Sie auf die Schaltfläche Endpunkt stoppen.

Gemeinsame Inference API
Um die Ultralytics HUB Shared Inference API zu verwenden, folgen Sie den nachstehenden Anleitungen.
Für die Ultralytics HUB Shared Inference API gelten die folgenden Nutzungsgrenzen:
- 100 Anrufe / Stunde
Python
Um mit Python auf die Ultralytics HUB Inference API zuzugreifen, verwenden Sie den folgenden Code:
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())
Hinweis
Ersetzen Sie MODEL_ID mit der gewünschten Modell-ID, API_KEY mit Ihrem tatsächlichen API-Schlüssel und path/to/image.jpg mit dem Pfad zu dem Bild, auf dem Sie Inferenz ausführen möchten.
Wenn du unsere Dedizierte Inference APIersetzen Sie die/den/das url auch.
cURL
Um mit cURL auf die Ultralytics HUB Inference API zuzugreifen, verwenden Sie den folgenden Code:
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"
Hinweis
Ersetzen Sie MODEL_ID mit der gewünschten Modell-ID, API_KEY mit Ihrem tatsächlichen API-Schlüssel und path/to/image.jpg mit dem Pfad zu dem Bild, auf dem Sie Inferenz ausführen möchten.
Wenn du unsere Dedizierte Inference APIersetzen Sie die/den/das url auch.
Argumente
Eine vollständige Liste der verfügbaren Inferenzargumente finden Sie in der folgenden Tabelle.
| Argument | Standard | Typ | Beschreibung |
|---|---|---|---|
file | file | Bild- oder Videodatei, die für die Inferenz verwendet werden soll. | |
imgsz | 640 | int | Größe des Eingangsbildes, gültiger Bereich ist 32 - 1280 Pixel. |
conf | 0.25 | float | Konfidenzschwellwert für Vorhersagen, gültiger Bereich 0.01 - 1.0. |
iou | 0.45 | float | Intersection over Union (Schnittmenge über Vereinigung) (IoU)-Schwellenwert, gültiger Bereich 0.0 - 0.95. |
Antwort
Die Ultralytics HUB Inference API gibt eine JSON-Antwort zurück.
Klassifizierung
Klassifikationsmodell
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": ...
}
Erkennung
Erkennungsmodell
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
OBB-Modell
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": ...
}
Segmentation
Segmentierungsmodell
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
Pose-Modell
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": ...
}