Ultralytics API suy luận HUB
Các Ultralytics HUB Inference API cho phép bạn chạy suy luận thông qua REST API của chúng tôi mà không cần cài đặt và thiết lập Ultralytics YOLO môi trường tại địa phương.
Xem: Ultralytics Hướng dẫn về API suy luận HUB
Python
Để truy cập Ultralytics API suy luận HUB sử dụng Python, sử dụng mã sau:
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())
Ghi
Thay thế MODEL_ID
với ID mô hình mong muốn, API_KEY
với khóa API thực 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.
uốn
Để truy cập Ultralytics API suy luận HUB sử dụng cURL, sử dụng mã sau:
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"
Ghi
Thay thế MODEL_ID
với ID mô hình mong muốn, API_KEY
với khóa API thực 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.
Lập luận
Xem bảng dưới đây để biết danh sách đầy đủ các đối số suy luận có sẵn.
Lý lẽ | Mặc định | Kiểu | Sự miêu tả |
---|---|---|---|
image |
image |
Tệp hình ảnh được sử dụng để suy luận. | |
url |
str |
URL của hình ảnh nếu không chuyển tệp. | |
size |
640 |
int |
Kích thước của hình ảnh đầu vào, phạm vi hợp lệ là 32 - 1280 Pixel. |
confidence |
0.25 |
float |
Ngưỡng tin cậy cho dự đoán, phạm vi hợp lệ 0.01 - 1.0 . |
iou |
0.45 |
float |
Giao lộ trên ngưỡng Union (IoU), phạm vi hợp lệ 0.0 - 0.95 . |
Phản ứng
Các Ultralytics API suy luận HUB trả về phản hồi JSON.
Phân loại
Mô hình phân loại
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())
Detection
Mô hình phát hiện
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())
OBB
Mô hình OBB
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())
Phân đoạn
Mô hình phân khúc
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())
Tư thế
Mô hình tạo dáng
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())
Đã tạo 2024-01-23, Cập nhật 2024-06-22
Tác giả: glenn-jocher (9), sergiuwaxmann (2), RizwanMunawar (1), priytosh-tripathi (1)