👋 你好
我们是您计算机视觉的核心工具包。 从数据加载到实时区域计数,我们提供构建模块,让您能够专注于围绕模型构建应用程序。🤝
💻 安装
在 Python>=3.10 环境中通过 Pip 安装 supervision 包。
pip install supervision
在我们的指南中阅读更多关于 conda、mamba 以及从源码安装的内容。
🔥 快速入门
模型
Supervision 被设计为模型无关。只需接入任何分类、检测或分割模型。为了方便起见,我们为 Ultralytics、Transformers、MMDetection 或 Inference 等最流行的库创建了连接器。其他集成,如 rfdetr,已经直接返回 sv.Detections。
使用 pip install pillow rfdetr 安装此示例的可选依赖项。
import supervision as sv
from PIL import Image
from rfdetr import RFDETRSmall
image = Image.open("path/to/image.jpg")
model = RFDETRSmall()
detections = model.predict(image, threshold=0.5)
len(detections)
# 5
👉 更多模型连接器
-
inference
使用 Inference 需要 Roboflow API KEY。
import supervision as sv from PIL import Image from inference import get_model image = Image.open("path/to/image.jpg") model = get_model(model_id="rfdetr-small", api_key="ROBOFLOW_API_KEY") result = model.infer(image)[0] detections = sv.Detections.from_inference(result) len(detections) # 5
标注器
Supervision 提供了大量高度可定制的 标注器,允许您为特定用例组合出完美的可视化效果。
import cv2
import supervision as sv
image = cv2.imread("path/to/image.jpg")
# Assuming detections are obtained from a model
detections = sv.Detections(...)
box_annotator = sv.BoxAnnotator()
annotated_frame = box_annotator.annotate(scene=image.copy(), detections=detections)
https://github.com/roboflow/supervision/assets/26109316/691e219c-0565-4403-9218-ab5644f39bce
Datasets
Supervision 提供了一组 utils,允许你以受支持的格式之一加载、拆分、合并和保存数据集。
import supervision as sv
from roboflow import Roboflow
project = Roboflow().workspace("WORKSPACE_ID").project("PROJECT_ID")
dataset = project.version("PROJECT_VERSION").download("coco")
ds = sv.DetectionDataset.from_coco(
images_directory_path=f"{dataset.location}/train",
annotations_path=f"{dataset.location}/train/_annotations.coco.json",
)
path, image, annotation = ds[0]
# loads image on demand
for path, image, annotation in ds:
# loads image on demand
pass
👉 更多数据集工具
-
load
dataset = sv.DetectionDataset.from_yolo( images_directory_path=..., annotations_directory_path=..., data_yaml_path=..., ) dataset = sv.DetectionDataset.from_pascal_voc( images_directory_path=..., annotations_directory_path=..., ) dataset = sv.DetectionDataset.from_coco( images_directory_path=..., annotations_path=..., ) -
拆分
train_dataset, test_dataset = dataset.split(split_ratio=0.7) test_dataset, valid_dataset = test_dataset.split(split_ratio=0.5) len(train_dataset), len(test_dataset), len(valid_dataset) # (700, 150, 150) -
合并
ds_1 = sv.DetectionDataset(...) len(ds_1) # 100 ds_1.classes # ['dog', 'person'] ds_2 = sv.DetectionDataset(...) len(ds_2) # 200 ds_2.classes # ['cat'] ds_merged = sv.DetectionDataset.merge([ds_1, ds_2]) len(ds_merged) # 300 ds_merged.classes # ['cat', 'dog', 'person'] -
保存
dataset.as_yolo( images_directory_path=..., annotations_directory_path=..., data_yaml_path=..., ) dataset.as_pascal_voc( images_directory_path=..., annotations_directory_path=..., ) dataset.as_coco( images_directory_path=..., annotations_path=..., ) -
转换
sv.DetectionDataset.from_yolo( images_directory_path=..., annotations_directory_path=..., data_yaml_path=..., ).as_pascal_voc( images_directory_path=..., annotations_directory_path=..., )
🎬 教程
想学习如何使用 Supervision?探索我们的操作指南、端到端示例、速查表和食谱!
Dwell Time Analysis with Computer Vision | Real-Time Stream Processing
了解如何使用计算机视觉分析等待时间并优化流程。本教程涵盖目标检测、跟踪以及在指定区域内计算停留时间。利用这些技术可改善零售、交通管理或其他场景中的客户体验。
Speed Estimation & Vehicle Tracking | Computer Vision | Open Source
学习如何使用 YOLO、ByteTrack 和 Roboflow Inference 来跟踪车辆并估算其速度。本综合教程涵盖目标检测、多目标跟踪、检测过滤、透视变换、速度估算、可视化改进等内容。
💜 Built with Supervision
Did you build something cool using supervision? Let us know!
https://github.com/roboflow/supervision/assets/26109316/c9436828-9fbf-4c25-ae8c-60e9c81b3900
https://github.com/roboflow/supervision/assets/26109316/3ac6982f-4943-4108-9b7f-51787ef1a69f
📚 Documentation
Visit our documentation page to learn how supervision can help you build computer vision applications faster and more reliably.
🏆 Contribution
We love your input! Please see our contributing guide to get started. Thank you 🙏 to all our contributors!