跳至内容

更新日志

0.25.0 2024年11月12日

  • 本次发布中没有移除或弃用的内容!

  • LineZone的重要更新:在计算线交叉时,抖动的检测可能会被重复计数(或更多)。现在可以通过minimum_crossing_threshold参数解决这个问题。如果将其设置为2或更高,将使用额外的帧来确认交叉,显著提高准确性。(#1540)

  • 现在可以追踪被检测为KeyPoints的对象。完整的分步指南请参阅Object Tracking Guide。(#1658)

import numpy as np
import supervision as sv
from ultralytics import YOLO

model = YOLO("yolov8m-pose.pt")
tracker = sv.ByteTrack()
trace_annotator = sv.TraceAnnotator()

def callback(frame: np.ndarray, _: int) -> np.ndarray:
    results = model(frame)[0]
    key_points = sv.KeyPoints.from_ultralytics(results)

    detections = key_points.as_detections()
    detections = tracker.update_with_detections(detections)

    annotated_image = trace_annotator.annotate(frame.copy(), detections)
    return annotated_image

sv.process_video(
    source_path="input_video.mp4",
    target_path="output_video.mp4",
    callback=callback
)
  • KeyPoints添加了is_empty方法,用于检查对象中是否存在任何关键点。(#1658)

  • KeyPoints添加了as_detections方法,可将KeyPoints转换为Detections。(#1658)

  • supervision[assets] 添加了新视频。(#1657)

from supervision.assets import download_assets, VideoAssets

path_to_video = download_assets(VideoAssets.SKIING)
  • Supervision 现在可以与 Python 3.13 一起使用。最著名的更新是能够在不使用全局解释器锁(GIL)的情况下运行 Python。我们预计依赖项对此的支持会不一致,但如果您尝试了 - 请告诉我们结果! (#1595)

  • 新增了Mean Average Recall mAR指标,该指标返回一个召回分数,该分数在IoU阈值、检测到的对象类别以及对最大考虑检测的限制上进行了平均。(#1661)

import supervision as sv
from supervision.metrics import MeanAverageRecall

predictions = sv.Detections(...)
targets = sv.Detections(...)

map_metric = MeanAverageRecall()
map_result = map_metric.update(predictions, targets).compute()

map_result.plot()
  • 新增了PrecisionRecall指标,为比较模型输出与真实值或其他模型提供了基准(#1609)
import supervision as sv
from supervision.metrics import Recall

predictions = sv.Detections(...)
targets = sv.Detections(...)

recall_metric = Recall()
recall_result = recall_metric.update(predictions, targets).compute()

recall_result.plot()
  • 所有指标现在都支持定向边界框(OBB) (#1593)
import supervision as sv
from supervision.metrics import F1_Score

predictions = sv.Detections(...)
targets = sv.Detections(...)

f1_metric = MeanAverageRecall(metric_target=sv.MetricTarget.ORIENTED_BOUNDING_BOXES)
f1_result = f1_metric.update(predictions, targets).compute()
import supervision as sv
from ultralytics import YOLO

image = cv2.imread("image.jpg")

label_annotator = sv.LabelAnnotator(smart_position=True)

model = YOLO("yolo11m.pt")
results = model(image)[0]
detections = sv.Detections.from_ultralytics(results)

annotated_frame = label_annotator.annotate(first_frame.copy(), detections)
sv.plot_image(annotated_frame)
  • Detections中新增了metadata变量。该变量允许您按图像存储自定义数据,而不是像data变量那样按检测对象存储。例如,metadata可用于存储源视频路径、相机型号或相机参数。(#1589)
import supervision as sv
from ultralytics import YOLO

model = YOLO("yolov8m")

result = model("image.png")[0]
detections = sv.Detections.from_ultralytics(result)

# Items in `data` must match length of detections
object_ids = [num for num in range(len(detections))]
detections.data["object_number"] = object_ids

# Items in `metadata` can be of any length.
detections.metadata["camera_model"] = "Luxonis OAK-D"
  • 添加了一个py.typed类型提示元文件。它应该能向类型注释器和IDE提供更明确的信号,表明类型支持是可用的。(#1586)

  • ByteTrack 不再要求 detections 必须包含 class_id (#1637)

  • draw_line, draw_rectangle, draw_filled_rectangle, draw_polygon, draw_filled_polygonPolygonZoneAnnotator 现在都带有默认颜色 (#1591)
  • 在合并多个数据集时,Dataset类被视为区分大小写。(#1643)
  • 扩展了metrics documentation,包含示例图表和打印结果 (#1660)
  • 添加了多边形区域的使用示例 (#1608)
  • 对多边形错误处理的小改进:(#1602)

  • 更新了ByteTrack,移除了共享变量。之前,多个ByteTrack实例会共享某些数据,需要频繁使用tracker.reset()。(#1603), (#1528)

  • 修复了MeanAveragePrecisionclass_agnostic设置无效的问题。(#1577) hacktoberfest
  • 从我们的CI系统中移除了欢迎工作流。(#1596)

  • ByteTrack进行大规模重构:将STrack移至单独的类,移除了冗余的BaseTrack类,删除了未使用的变量(#1603)

  • RichLabelAnnotator进行了大规模重构,使其内容与LabelAnnotator保持一致。(#1625)

0.24.0 2024年10月4日

import supervision as sv
from supervision.metrics import F1Score

predictions = sv.Detections(...)
targets = sv.Detections(...)

f1_metric = F1Score()
f1_result = f1_metric.update(predictions, targets).compute()

print(f1_result)
print(f1_result.f1_50)
print(f1_result.small_objects.f1_50)
import supervision as sv
import cv2

image = cv2.imread("<SOURCE_IMAGE_PATH>")

line_zone = sv.LineZone(
    start=sv.Point(0, 100),
    end=sv.Point(50, 200)
)
line_zone_annotator = sv.LineZoneAnnotator(
    text_orient_to_line=True,
    display_text_box=False,
    text_centered=False
)

annotated_frame = line_zone_annotator.annotate(
    frame=image.copy(), line_counter=line_zone
)

sv.plot_image(frame)
  • LineZone添加了按类别计数功能,并引入了LineZoneAnnotatorMulticlass用于可视化每个类别的计数。该功能允许跟踪穿过线条的各个类别,增强了交通监控或人群分析等用例的灵活性。#1555
import supervision as sv
import cv2

image = cv2.imread("<SOURCE_IMAGE_PATH>")

line_zone = sv.LineZone(
    start=sv.Point(0, 100),
    end=sv.Point(50, 200)
)
line_zone_annotator = sv.LineZoneAnnotatorMulticlass()

frame = line_zone_annotator.annotate(
    frame=frame, line_zones=[line_zone]
)

sv.plot_image(frame)
  • 新增 from_easyocr 功能,支持将OCR识别结果集成到supervision框架中。EasyOCR 是一个开源的光学字符识别(OCR)库,能够从图像中读取文本。#1515
import supervision as sv
import easyocr
import cv2

image = cv2.imread("<SOURCE_IMAGE_PATH>")

reader = easyocr.Reader(["en"])
result = reader.readtext("<SOURCE_IMAGE_PATH>", paragraph=True)
detections = sv.Detections.from_easyocr(result)

box_annotator = sv.BoxAnnotator(color_lookup=sv.ColorLookup.INDEX)
label_annotator = sv.LabelAnnotator(color_lookup=sv.ColorLookup.INDEX)

annotated_image = image.copy()
annotated_image = box_annotator.annotate(scene=annotated_image, detections=detections)
annotated_image = label_annotator.annotate(scene=annotated_image, detections=detections)

sv.plot_image(annotated_image)
  • detection.utils中新增了oriented_box_iou_batch函数。该函数用于计算定向或旋转边界框(OBB)的交并比(IoU)。#1502
import numpy as np

boxes_true = np.array([[[1, 0], [0, 1], [3, 4], [4, 3]]])
boxes_detection = np.array([[[1, 1], [2, 0], [4, 2], [3, 3]]])
ious = sv.oriented_box_iou_batch(boxes_true, boxes_detection)
print("IoU between true and detected boxes:", ious)
  • 扩展了PolygonZoneAnnotator功能,允许在绘制区域时设置不透明度,通过填充具有可调节透明度的区域来提供增强的可视化效果。#1527
import cv2
from ncnn.model_zoo import get_model
import supervision as sv

image = cv2.imread("<SOURCE_IMAGE_PATH>")
model = get_model(
    "yolov8s",
    target_size=640,
    prob_threshold=0.5,
    nms_threshold=0.45,
    num_threads=4,
    use_gpu=True,
)
result = model(image)
detections = sv.Detections.from_ncnn(result)

已移除

PolygonZone中的frame_resolution_wh参数已被移除。

已移除

Supervision的安装方法"headless""desktop"已被移除,因为它们不再需要。pip install supervision[headless]将安装基础库并无害地警告不存在的额外功能。

  • Supervision 现在依赖 opencv-python 而非 opencv-python-headless#1530

  • 修复了COCO 101点平均精度算法,使其能正确插值精度,从而提供更精确的平均精度计算而无需对中间值进行平均处理。#1500

  • 解决了构建文档时突出的各种问题。主要包括空白调整和类型不一致。更新文档以提高清晰度并修复格式问题。为mkdocstrings-python添加了明确版本。#1549

  • 启用并修复了Ruff代码格式化规则,包括避免不必要的可迭代对象分配和使用Optional作为默认可变参数等变更。#1526

0.23.0 2024年8月28日

  • 新增 #930: IconAnnotator,这是一个新的标注工具,可以在每个检测目标上绘制图标。如果您想为每个类别绘制特定图标,这将非常有用。
import supervision as sv
from inference import get_model

image = <SOURCE_IMAGE_PATH>
icon_dog = <DOG_PNG_PATH>
icon_cat = <CAT_PNG_PATH>

model = get_model(model_id="yolov8n-640")
results = model.infer(image)[0]
detections = sv.Detections.from_inference(results)

icon_paths = []
for class_name in detections.data["class_name"]:
    if class_name == "dog":
        icon_paths.append(icon_dog)
    elif class_name == "cat":
        icon_paths.append(icon_cat)
    else:
        icon_paths.append("")

icon_annotator = sv.IconAnnotator()
annotated_frame = icon_annotator.annotate(
    scene=image.copy(),
    detections=detections,
    icon_path=icon_paths
)
import supervision as sv
from inference import get_model

image = <SOURCE_IMAGE_PATH>

model = get_model(model_id="yolov8n-640")
results = model.infer(image)[0]
detections = sv.Detections.from_inference(results)

background_overlay_annotator = sv.BackgroundOverlayAnnotator()
annotated_frame = background_overlay_annotator.annotate(
    scene=image.copy(),
    detections=detections
)
  • 新增 #1386: 在 sv.Detections.from_transformers 中支持 Transformers v5 函数。这包括 DetrImageProcessor 方法 post_process_object_detection, post_process_panoptic_segmentation, post_process_semantic_segmentationpost_process_instance_segmentation
import torch
import supervision as sv
from PIL import Image
from transformers import DetrImageProcessor, DetrForObjectDetection

processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")

image = Image.open(<SOURCE_IMAGE_PATH>)
inputs = processor(images=image, return_tensors="pt")

with torch.no_grad():
    outputs = model(**inputs)

width, height = image.size
target_size = torch.tensor([[height, width]])
results = processor.post_process_object_detection(
    outputs=outputs, target_sizes=target_size)[0]
detections = sv.Detections.from_transformers(
    transformers_results=results,
    id2label=model.config.id2label)
import supervision as sv
from segment_anything import (
    sam_model_registry,
    SamAutomaticMaskGenerator
)
sam_model_reg = sam_model_registry[MODEL_TYPE]
sam = sam_model_reg(checkpoint=CHECKPOINT_PATH).to(device=DEVICE)
mask_generator = SamAutomaticMaskGenerator(sam)
sam_result = mask_generator.generate(IMAGE)
detections = sv.Detections.from_sam(sam_result=sam_result)
  • 新增 #1458: 为 TriangleAnnotatorDotAnnotator 添加了 outline_color 选项。

  • 新增 #1409: 为关键点标注工具VertexLabelAnnotator添加了text_color选项。

  • 更改 #1434: InferenceSlicer 现在新增了一个 overlap_wh 参数,使得在处理重叠切片时更容易计算切片尺寸。

  • 修复 #1448: 已解决多种标注器类型问题,支持扩展的错误处理功能。

  • 修复 #1348: 引入了一种定位到特定视频帧的新方法,解决了传统定位方法失效的情况。可以通过设置 iterative_seek=True 来启用此功能。

import supervision as sv

for frame in sv.get_video_frames_generator(
    source_path=<SOURCE_VIDEO_PATH>,
    start=60,
    iterative_seek=True
):
    ...
  • 修复 #1424: plot_image 函数现在明确表示尺寸单位是英寸。

已移除

ByteTrack中的track_buffertrack_threshmatch_thresh参数已被弃用,并从supervision-0.23.0版本开始移除。请改用lost_track_buffertrack_activation_thresholdminimum_matching_threshold参数。

已移除

supervision-0.23.0 版本开始,sv.PolygonZone 中的 triggering_position 参数已被移除。请改用 triggering_anchors

已弃用

overlap_filter_strategyInferenceSlicer.__init__ 中已被弃用,将在 supervision-0.27.0 版本中移除。请改用 overlap_strategy

已弃用

overlap_ratio_whInferenceSlicer.__init__ 中已被弃用,将在 supervision-0.27.0 中移除。请改用 overlap_wh

0.22.0 2024年7月12日

已弃用

使用参数images作为Dict[str, np.ndarray]来构建DetectionDataset已被弃用,并将在supervision-0.26.0中移除。请改用路径列表List[str]

已弃用

DetectionDataset.images 属性已弃用,并将在 supervision-0.26.0 中移除。请改用 for path, image, annotation in dataset: 循环遍历图像,这样无需将所有图像加载到内存中。

import roboflow
from roboflow import Roboflow
import supervision as sv

roboflow.login()
rf = Roboflow()

project = rf.workspace(<WORKSPACE_ID>).project(<PROJECT_ID>)
dataset = project.version(<PROJECT_VERSION>).download("coco")

ds_train = sv.DetectionDataset.from_coco(
    images_directory_path=f"{dataset.location}/train",
    annotations_path=f"{dataset.location}/train/_annotations.coco.json",
)

path, image, annotation = ds_train[0]
    # loads image on demand

for path, image, annotation in ds_train:
    # loads image on demand
import supervision as sv
from detectron2 import model_zoo
from detectron2.engine import DefaultPredictor
from detectron2.config import get_cfg
import cv2

image = cv2.imread(<SOURCE_IMAGE_PATH>)
cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")
predictor = DefaultPredictor(cfg)

result = predictor(image)
detections = sv.Detections.from_detectron2(result)

mask_annotator = sv.MaskAnnotator()
annotated_frame = mask_annotator.annotate(scene=image.copy(), detections=detections)
  • 新增 #1277:如果您提供的字体支持某种语言的符号,sv.RichLabelAnnotator 将在您的图像上绘制这些符号。
  • 其他各种标注器已进行修订,以确保与numpy数组一起使用时具备正确的原地操作功能。此外,我们还修复了一个错误,即当原地使用sv.ColorAnnotator时,会用纯色填充方框。
import cv2
import supervision as sv
import

image = cv2.imread(<SOURCE_IMAGE_PATH>)

model = get_model(model_id="yolov8n-640")
results = model.infer(image)[0]
detections = sv.Detections.from_inference(results)

rich_label_annotator = sv.RichLabelAnnotator(font_path=<TTF_FONT_PATH>)
annotated_image = rich_label_annotator.annotate(scene=image.copy(), detections=detections)
  • 新增 #1227: 增加了对以YOLO格式加载定向边界框(Oriented Bounding Boxes)数据集的支持。
import supervision as sv

train_ds = sv.DetectionDataset.from_yolo(
    images_directory_path="/content/dataset/train/images",
    annotations_directory_path="/content/dataset/train/labels",
    data_yaml_path="/content/dataset/data.yaml",
    is_obb=True,
)

_, image, detections in train_ds[0]

obb_annotator = OrientedBoxAnnotator()
annotated_image = obb_annotator.annotate(scene=image.copy(), detections=detections)

已移除

BoxAnnotator已被移除,但BoundingBoxAnnotator已重命名为BoxAnnotator。使用BoxAnnotatorLabelAnnotator的组合来模拟旧的BoundingBox行为。

已弃用

名称 BoundingBoxAnnotator 已被弃用,并将在 supervision-0.26.0 中移除。它已重命名为 BoxAnnotator

  • 新增 #975 📝 新食谱:将检测结果序列化为 jsoncsv

  • 新增 #1290: 主要是内部变更,我们的文件工具函数现在同时支持 strpathlib 路径。

  • 新增 #1340: 两种边界框格式转换的新方法 - xywh_to_xyxyxcycwh_to_xyxy

已移除

from_roboflow 方法由于已弃用而被移除。请改用 from_inference

已移除

Color.white() 由于已弃用而被移除。请改用 color.WHITE

已移除

Color.black() 由于已弃用而被移除。请改用 color.BLACK

已移除

Color.red() 由于已弃用而被移除。请改用 color.RED

已移除

Color.green() 由于已弃用而被移除。请改用 color.GREEN

已移除

Color.blue() 由于已弃用而被移除。请改用 color.BLUE

已移除

ColorPalette.default() 由于已弃用而被移除。请改用 ColorPalette.DEFAULT

已移除

FPSMonitor.__call__ 由于已弃用而被移除。请改用属性 FPSMonitor.fps

0.21.0 2024年6月5日

import supervision as sv

paligemma_result = "<loc0256><loc0256><loc0768><loc0768> cat"
detections = sv.Detections.from_lmm(
    sv.LMM.PALIGEMMA,
    paligemma_result,
    resolution_wh=(1000, 1000),
    classes=["cat", "dog"],
)
detections.xyxy
# array([[250., 250., 750., 750.]])

detections.class_id
# array([0])
import supervision as sv

image = ...
key_points = sv.KeyPoints(...)

edge_annotator = sv.EdgeAnnotator(
    color=sv.Color.GREEN,
    thickness=5
)
annotated_frame = edge_annotator.annotate(
    scene=image.copy(),
    key_points=key_points
)
import cv2
import numpy as np
import supervision as sv
from inference import get_model

model = get_model(model_id="yolov8x-seg-640")
image = cv2.imread(<SOURCE_IMAGE_PATH>)

def callback(image_slice: np.ndarray) -> sv.Detections:
    results = model.infer(image_slice)[0]
    return sv.Detections.from_inference(results)

slicer = sv.InferenceSlicer(callback = callback)
detections = slicer(image)

mask_annotator = sv.MaskAnnotator()
label_annotator = sv.LabelAnnotator()

annotated_image = mask_annotator.annotate(
    scene=image, detections=detections)
annotated_image = label_annotator.annotate(
    scene=annotated_image, detections=detections)

0.20.0 2024年4月24日

import cv2
import supervision as sv
from ultralytics import YOLO

image = cv2.imread(<SOURCE_IMAGE_PATH>)
model = YOLO('yolov8l-pose')

result = model(image, verbose=False)[0]
keypoints = sv.KeyPoints.from_ultralytics(result)

edge_annotators = sv.EdgeAnnotator(color=sv.Color.GREEN, thickness=5)
annotated_image = edge_annotators.annotate(image.copy(), keypoints)
  • 变更 #1037: sv.LabelAnnotator 通过新增 corner_radius 参数实现边界框圆角功能。

  • 修改 #1109: 调整 sv.PolygonZone 使得初始化 sv.PolygonZone 时不再需要 frame_resolution_wh 参数。

已弃用

sv.PolygonZone中的frame_resolution_wh参数已被弃用,将在supervision-0.24.0版本中移除。

import torch
import supervision as sv
from PIL import Image
from transformers import DetrImageProcessor, DetrForSegmentation

processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50-panoptic")
model = DetrForSegmentation.from_pretrained("facebook/detr-resnet-50-panoptic")

image = Image.open(<SOURCE_IMAGE_PATH>)
inputs = processor(images=image, return_tensors="pt")

with torch.no_grad():
    outputs = model(**inputs)

width, height = image.size
target_size = torch.tensor([[height, width]])
results = processor.post_process_segmentation(
    outputs=outputs, target_sizes=target_size)[0]
detections = sv.Detections.from_transformers(results, id2label=model.config.id2label)

mask_annotator = sv.MaskAnnotator()
label_annotator = sv.LabelAnnotator(text_position=sv.Position.CENTER)

annotated_image = mask_annotator.annotate(
    scene=image, detections=detections)
annotated_image = label_annotator.annotate(
    scene=annotated_image, detections=detections)

0.19.0 2024年3月15日

  • 新增 #818: sv.CSVSink 功能,支持将图像、视频或流式推理结果直接保存到 .csv 文件中。
import supervision as sv
from ultralytics import YOLO

model = YOLO(<SOURCE_MODEL_PATH>)
csv_sink = sv.CSVSink(<RESULT_CSV_FILE_PATH>)
frames_generator = sv.get_video_frames_generator(<SOURCE_VIDEO_PATH>)

with csv_sink:
    for frame in frames_generator:
        result = model(frame)[0]
        detections = sv.Detections.from_ultralytics(result)
        csv_sink.append(detections, custom_data={<CUSTOM_LABEL>:<CUSTOM_DATA>})
  • 新增 #819: sv.JSONSink 功能,支持将图像、视频或流式推理结果直接保存为 .json 文件。
import supervision as sv
from ultralytics import YOLO

model = YOLO(<SOURCE_MODEL_PATH>)
json_sink = sv.JSONSink(<RESULT_JSON_FILE_PATH>)
frames_generator = sv.get_video_frames_generator(<SOURCE_VIDEO_PATH>)

with json_sink:
    for frame in frames_generator:
        result = model(frame)[0]
        detections = sv.Detections.from_ultralytics(result)
        json_sink.append(detections, custom_data={<CUSTOM_LABEL>:<CUSTOM_DATA>})
import cv2
import supervision as sv
from inference import get_model

image = cv2.imread(<SOURCE_IMAGE_PATH>)
model = get_model(model_id="yolov8n-640")

result = model.infer(image)[0]
detections = sv.Detections.from_inference(result)

crop_annotator = sv.CropAnnotator()
annotated_frame = crop_annotator.annotate(
    scene=image.copy(),
    detections=detections
)
  • 更改 #827: sv.ByteTrack.reset 允许用户清除跟踪器状态,从而能够按顺序处理多个视频文件。

  • 变更 #802: sv.LineZoneAnnotator 现在可以通过 display_in_countdisplay_out_count 属性来隐藏进出计数。

  • 变更 #787: sv.ByteTrack 输入参数和文档字符串已更新,以提高可读性和易用性。

已弃用

sv.ByteTrack中的track_buffertrack_threshmatch_thresh参数已弃用,将在supervision-0.23.0中移除。请改用lost_track_buffertrack_activation_thresholdminimum_matching_threshold

  • 修改 #910sv.PolygonZone 现在可以接收一个特定的锚点框列表,只有当检测目标位于这些锚点框内时才会被计数。

已弃用

sv.PolygonZone中的triggering_position参数已被弃用,将在supervision-0.23.0中移除。请改用triggering_anchors

  • 更改 #875: 标注器新增对Pillow图像的支持。现在所有supervision标注器都可以接受numpy数组或Pillow图像作为输入。它们会自动检测图像类型,绘制标注,并以与输入相同的格式返回输出结果。

  • 修复了 #944: sv.DetectionsSmoothersv.Detections 中移除 tracking_id 的问题。

0.18.0 2024年1月25日

>>> import supervision as sv

>>> image = ...
>>> detections = sv.Detections(...)

>>> percentage_bar_annotator = sv.PercentageBarAnnotator()
>>> annotated_frame = percentage_bar_annotator.annotate(
...     scene=image.copy(),
...     detections=detections
... )
import cv2
import supervision as sv
from ultralytics import YOLO

image = cv2.imread(<SOURCE_IMAGE_PATH>)
model = YOLO("yolov8n-obb.pt")

result = model(image)[0]
detections = sv.Detections.from_ultralytics(result)

oriented_box_annotator = sv.OrientedBoxAnnotator()
annotated_frame = oriented_box_annotator.annotate(
    scene=image.copy(),
    detections=detections
)
>>> import supervision as sv

>>> sv.ColorPalette.from_matplotlib('viridis', 5)
ColorPalette(colors=[Color(r=68, g=1, b=84), Color(r=59, g=82, b=139), ...])
  • 修改 #770: sv.Detections.from_ultralytics 添加了对OBB(定向边界框)的支持。

  • 更改 #735: sv.LineZone 现在可以接受一个特定的边界框锚点列表,只有当这些锚点穿过线时才会计数检测。这个更新标志着相比之前需要所有四个角点的重要改进。用户现在可以指定单个锚点,例如 sv.Position.BOTTOM_CENTER,或者任何其他定义为 List[sv.Position] 的锚点组合。

  • 修改 #756: 将 sv.Colorsv.ColorPalette 访问预定义颜色的方式从基于函数的调用 (sv.Color.red()) 改为更直观传统的基于属性的方式 (sv.Color.RED)。

已弃用

sv.ColorPalette.default() 已弃用,将在 supervision-0.22.0 中移除。请改用 sv.ColorPalette.DEFAULT

已弃用

Detections.from_roboflow() 已弃用,将在 supervision-0.22.0 中移除。请改用 Detections.from_inference

  • 修复了#735sv.LineZone功能,现在当物体从任意方向(包括侧面)穿过线条时能准确更新计数器。这项改进实现了更精确的跟踪分析功能,例如计算道路上每条车道的单独进出数量。

0.17.0 2023年12月06日

>>> import supervision as sv

>>> image = ...
>>> detections = sv.Detections(...)

>>> polygon_annotator = sv.PolygonAnnotator()
>>> annotated_frame = polygon_annotator.annotate(
...     scene=image.copy(),
...     detections=detections
... )
  • 新增 #476: sv.assets 功能,允许下载视频文件用于演示。
>>> from supervision.assets import download_assets, VideoAssets
>>> download_assets(VideoAssets.VEHICLES)
"vehicles.mp4"

0.16.0 2023年10月19日

>>> import supervision as sv

>>> image = ...
>>> detections = sv.Detections(...)

>>> halo_annotator = sv.HaloAnnotator()
>>> annotated_frame = halo_annotator.annotate(
...     scene=image.copy(),
...     detections=detections
... )
  • 新增 #466: sv.HeatMapAnnotator 支持使用热力图对视频进行标注。

  • 新增 #492: sv.DotAnnotator 功能,支持用点标注图像和视频。

  • 新增 #449: sv.draw_image 功能,允许以指定的透明度和尺寸将图像绘制到给定场景上。

  • 新增 #280: sv.FPSMonitor 用于监控每秒帧数(FPS)以评估延迟性能。

  • 新增 #454: 🤗 Hugging Face 标注工具 space.

  • 变更 #482: sv.LineZone.trigger 现在返回 Tuple[np.ndarray, np.ndarray]。第一个数组表示哪些检测从外向内越过了线。第二个数组表示哪些检测从内向外越过了线。

  • 更改 #465: 将注释器参数名称从 color_map: str 改为 color_lookup: ColorLookup 枚举以提高类型安全性。

  • 变更 #426: sv.MaskAnnotator 现在支持2倍速的标注。

  • 修复 #477: Poetry 环境定义允许正确的本地安装。

  • 修复 #430: sv.ByteTrack 现在会在 svDetections 为空时返回 np.array([], dtype=int)

已弃用

sv.Detections.from_yolov8sv.Classifications.from_yolov8 已被替换为 sv.Detections.from_ultralyticssv.Classifications.from_ultralytics

0.15.0 2023年10月5日

>>> import supervision as sv

>>> image = ...
>>> detections = sv.Detections(...)

>>> bounding_box_annotator = sv.BoundingBoxAnnotator()
>>> annotated_frame = bounding_box_annotator.annotate(
...     scene=image.copy(),
...     detections=detections
... )

0.14.0 2023年8月31日

>>> import cv2
>>> import supervision as sv
>>> from ultralytics import YOLO

>>> image = cv2.imread(SOURCE_IMAGE_PATH)
>>> model = YOLO(...)

>>> def callback(image_slice: np.ndarray) -> sv.Detections:
...     result = model(image_slice)[0]
...     return sv.Detections.from_ultralytics(result)

>>> slicer = sv.InferenceSlicer(callback = callback)

>>> detections = slicer(image)

已弃用

sv.Detections.from_yolov8sv.Classifications.from_yolov8 现已弃用,将在 supervision-0.16.0 版本发布时移除。

0.13.0 2023年8月8日

>>> import supervision as sv
>>> from ultralytics import YOLO

>>> dataset = sv.DetectionDataset.from_yolo(...)

>>> model = YOLO(...)
>>> def callback(image: np.ndarray) -> sv.Detections:
...     result = model(image)[0]
...     return sv.Detections.from_yolov8(result)

>>> mean_average_precision = sv.MeanAveragePrecision.benchmark(
...     dataset = dataset,
...     callback = callback
... )

>>> mean_average_precision.map50_95
0.433

已弃用

sv.Detections.from_yolov8 现已弃用,并将在 supervision-0.15.0 版本发布时移除。

0.12.0 2023年7月24日

Python 3.7. 支持已终止

随着supervision-0.12.0版本的发布,我们将终止对Python 3.7的官方支持。

>>> import supervision as sv
>>> from ultralytics import YOLO

>>> dataset = sv.DetectionDataset.from_yolo(...)

>>> model = YOLO(...)
>>> def callback(image: np.ndarray) -> sv.Detections:
...     result = model(image)[0]
...     return sv.Detections.from_yolov8(result)

>>> confusion_matrix = sv.ConfusionMatrix.benchmark(
...     dataset = dataset,
...     callback = callback
... )

>>> confusion_matrix.matrix
array([
    [0., 0., 0., 0.],
    [0., 1., 0., 1.],
    [0., 1., 1., 0.],
    [1., 1., 0., 0.]
])

0.11.1 2023年6月29日

0.11.0 2023年6月28日

>>> import supervision as sv

>>> ds = sv.DetectionDataset.from_coco(
...     images_directory_path='...',
...     annotations_path='...'
... )

>>> ds.as_coco(
...     images_directory_path='...',
...     annotations_path='...'
... )
>>> import supervision as sv

>>> 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']
  • 新增 #162: 为 sv.get_video_frames_generator 添加了额外的 startend 参数,允许仅生成视频选定部分的帧。

  • 修复 #157: 从 data.yaml 加载 YOLO 数据集类名不正确的问题。

0.10.0 2023年6月14日

>>> import supervision as sv

>>> cs = sv.ClassificationDataset.from_folder_structure(
...     root_directory_path='...'
... )

>>> cs.as_folder_structure(
...     root_directory_path='...'
... )
  • 新增 #125: 支持 sv.ClassificationDataset.split 功能,允许将 sv.ClassificationDataset 分割为两部分。

  • 新增 #110: 能够通过 sv.Detections.from_roboflow 从 Roboflow API 结果中提取掩码。

  • 新增 commit hash:Supervision 快速入门 notebook,您可以在其中了解更多关于 Detection、Dataset 和 Video API 的内容。

  • 修改 #135: 优化了 sv.get_video_frames_generator 文档以更准确地描述实际行为。

0.9.0 2023年6月7日

  • 新增 #118: 支持通过索引、索引列表或切片来选择 sv.Detections。以下示例展示了新的选择方法。
>>> import supervision as sv

>>> detections = sv.Detections(...)
>>> len(detections[0])
1
>>> len(detections[[0, 1]])
2
>>> len(detections[0:2])
2
  • 新增 #101: 支持通过 sv.Detections.from_yolov8 从 YOLOv8 结果中提取掩码。以下示例演示了如何从 YOLOv8 模型推理结果中提取布尔掩码。

  • 新增 #122: 支持通过 sv.crop 裁剪图像。以下示例展示如何为 sv.Detections 中的每个检测结果获取单独的裁剪区域。

  • 新增 #120: 通过 sv.ImageSink 实现便捷地将多张图像保存至目录的功能。以下示例展示如何将视频每十帧保存为单独图像。

>>> import supervision as sv

>>> with sv.ImageSink(target_dir_path='target/directory/path') as sink:
...     for image in sv.get_video_frames_generator(source_path='source_video.mp4', stride=10):
...         sink.save_image(image=image)
  • 修复 #106: 改进了 sv.PolygonZone 坐标的不便处理方式。现在 sv.PolygonZone 接受 [[x1, y1], [x2, y2], ...] 格式的坐标,这些坐标可以是整数也可以是浮点数。

0.8.0 2023年5月17日

  • 新增 #100: 支持数据集继承。当前的 Dataset 已重命名为 DetectionDataset。现在 DetectionDataset 继承自 BaseDataset。此项变更是为了确保未来不同类型计算机视觉数据集API的一致性。
  • 新增 #100: 支持通过 DetectionDataset.as_yolo 将数据集保存为YOLO格式。
>>> import roboflow
>>> from roboflow import Roboflow
>>> import supervision as sv

>>> roboflow.login()

>>> rf = Roboflow()

>>> project = rf.workspace(WORKSPACE_ID).project(PROJECT_ID)
>>> dataset = project.version(PROJECT_VERSION).download("yolov5")

>>> ds = sv.DetectionDataset.from_yolo(
...     images_directory_path=f"{dataset.location}/train/images",
...     annotations_directory_path=f"{dataset.location}/train/labels",
...     data_yaml_path=f"{dataset.location}/data.yaml"
... )

>>> ds.classes
['dog', 'person']
>>> import supervision as sv

>>> ds = sv.DetectionDataset(...)
>>> train_ds, test_ds = ds.split(split_ratio=0.7, random_state=42, shuffle=True)

>>> len(train_ds), len(test_ds)
(700, 300)
  • 修改 #100:将 DetectionDataset.as_yoloDetectionDataset.as_pascal_vocapproximation_percentage 参数的默认值从 0.75 改为 0.0

0.7.0 2023年5月11日

  • 新增 #91: Detections.from_yolo_nas 功能,实现与 YOLO-NAS 模型的无缝集成。
  • 新增 #86: 支持通过 Dataset.from_yolo 加载 YOLO 格式的数据集。
  • 新增 #84: Detections.merge 功能,用于合并多个 Detections 对象。
  • 修复 #81: LineZoneAnnotator.annotate 没有返回标注后的帧。
  • 修改 #44: LineZoneAnnotator.annotate 现在允许为进出标签使用自定义文本。

0.6.0 2023年4月19日

  • 新增 #71: 初步支持 Dataset 功能,并能够将 Detections 以 Pascal VOC XML 格式保存。
  • 新增 #71: 新增 mask_to_polygons, filter_polygons_by_area, polygon_to_xyxyapproximate_polygon 实用工具。
  • 新增 #72: 支持将 Pascal VOC XML 目标检测数据集加载为 Dataset
  • 修改 #70:调整了 Detections 属性的顺序,使其与 __iter__ 元组中对象的顺序保持一致。
  • 修改 #71: 将 generate_2d_mask 更名为 polygon_to_mask

0.5.2 2023年4月13日

  • 修复 #63: LineZone.trigger 函数预期接收4个值而非5个。

0.5.1 2023年4月12日

  • 修复了Detections.__getitem__方法未返回所选项目的掩码的问题。
  • 修复了Detections.area在处理掩码检测时崩溃的问题。

0.5.0 2023年4月10日

  • 新增 #58: Detections.mask 以支持分割功能。
  • 新增 #58: MaskAnnotator 用于简化 Detections.mask 标注。
  • 新增 #58: Detections.from_sam 以支持原生Segment Anything Model (SAM)功能。
  • 修改 #58: Detections.area 功能使其不仅适用于边界框,也适用于掩码。

0.4.0 2023年4月5日

  • 新增 #46: Detections.empty 功能,便于创建空的 Detections 对象。
  • 新增 #56: Detections.from_roboflow 功能,支持从Roboflow API推理结果轻松创建Detections对象。
  • 新增 #56: plot_images_grid 功能,支持在单个图表中轻松绘制多张图像。
  • 新增 #56: 通过 detections_to_voc_xml 方法初步支持 Pascal VOC XML 格式。
  • 变更 #56: show_frame_in_notebook 重构并重命名为 plot_image

0.3.2 2023年3月23日

  • 修改 #50: 允许 Detections.class_idNone

0.3.1 2023年3月6日

  • 修复 #41: PolygonZone 当物体触碰到图像底部边缘时会抛出异常。
  • 修复 #42: 当 Detections 为空时,Detections.wth_nms 方法会抛出异常。
  • 修改 #36: Detections.wth_nms 支持类别无关和非类别无关的情况。

0.3.0 2023年3月6日

  • 变更:允许Detections.confidenceNone
  • 新增:Detections.from_transformersDetections.from_detectron2 功能,实现与Transformers和Detectron2模型的无缝集成。
  • 新增: Detections.area 用于动态计算边界框面积。
  • 新增: Detections.wth_nms 用于通过NMS过滤重复检测。初始实现仅支持类别无关模式。

0.2.0 2023年2月2日

  • 新增:使用类似pandas的API进行高级Detections过滤。
  • 新增: Detections.from_yolov5Detections.from_yolov8 功能,实现与YOLOv5和YOLOv8模型的无缝集成。

0.1.0 2023年1月19日

向 Supervision 问好 👋