Ultralytics HUB 推断应用程序接口
Ultralytics HUB Inference API 允许您通过我们的 REST API 运行推理,而无需在本地安装和设置Ultralytics YOLO 环境。
观看: Ultralytics HUB 推断应用程序接口演练
Python
要使用Python 访问Ultralytics HUB Inference 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
您的实际应用程序接口密钥,以及 path/to/image.jpg
的路径。
cURL
要使用 cURL 访问Ultralytics HUB Inference 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
您的实际应用程序接口密钥,以及 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) 阈值的交集,有效范围 0.0 - 0.95 . |
回应
Ultralytics HUB Inference API 返回一个 JSON 响应。
分类
分类模式
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())
检测
检测模型
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
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())
细分
细分模型
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())
姿势
姿势模型
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())
创建于 2024-01-23,更新于 2024-06-22
作者:glenn-jocher(9),sergiuwaxmann(2),RizwanMunawar(1),priytosh-tripathi(1)