Repository navigation
v0.32.1: BGRA scenes and metric fixes
A patch release: annotators now work on BGRA images, and several metric and dataset results are corrected.
- Annotators draw on BGRA scenes with an alpha channel instead of failing with shape errors.
ConfusionMatrix.plotwithnormalize=Truenow divides by true-class rows, so the diagonal is per-class recall.MeanAverageRecallreturns-1when there is nothing to recall, not a misleading0.0.- Dataset
splitkeeps the train item that float rounding used to drop. - Windows users can read and write images in folders with non-ASCII names.
- Edge cases found in review are fixed too: alpha-weighted resizing of translucent BGRA images, rich label text placement, and
np.float16split ratios.
Upgrading is safe and nothing breaks, but a few metric, split and rendering results shift, so skim the Migration guide.
✨ Spotlights / highlights
Annotators and drawing helpers work on BGRA scenes
Scenes shaped (H, W, 4), such as frames with an alpha channel, now work. sv.MaskAnnotator, sv.HaloAnnotator, sv.BackgroundOverlayAnnotator, sv.ComparisonAnnotator, sv.HeatMapAnnotator, sv.CropAnnotator, sv.IconAnnotator, sv.RichLabelAnnotator and sv.tint_image used to raise ValueError shape or broadcast errors on them. sv.draw_line, sv.draw_rectangle, sv.draw_filled_rectangle, sv.draw_polygon, sv.draw_filled_polygon and sv.draw_text did not raise, but drew fully transparent pixels on an opaque scene; they now draw opaque ones. Opaque scenes stay opaque, and annotators with an opacity setting cover pixels in proportion to it. (#2956, #2957, #2958, #2960, #2961)
import numpy as np
import supervision as sv
scene = np.zeros((100, 100, 4), dtype=np.uint8)
scene[..., 3] = 255 # fully opaque BGRA frame
mask = np.zeros((1, 100, 100), dtype=bool)
mask[0, 20:60, 20:60] = True
detections = sv.Detections(
xyxy=np.array([[20, 20, 60, 60]], dtype=float),
mask=mask,
class_id=np.array([0]),
)
annotated = sv.MaskAnnotator().annotate(scene.copy(), detections)
annotated.shape # (100, 100, 4), alpha stays 255A normalized confusion matrix reads as recall
sv.ConfusionMatrix.plot(normalize=True) now divides each row by its sum, so every ground-truth row with targets adds up to 1 and the diagonal is per-class recall, as in sklearn.metrics.confusion_matrix(normalize="true"). It used to divide by column sums, which did not match the True and Predicted axis labels. With 10 cats all found and 5 of 10 dogs predicted as cat, the plot showed 0.67 and 1.00 instead of 1.00 and 0.50. Normalized plots show different numbers than in v0.32.0. (#2954)
confusion_matrix.plot(normalize=True) # diagonal = per-class recallMeanAverageRecall says -1 when there is nothing to recall
When there are no targets, either for the whole run or for an empty small, medium or large size bucket, scores are now -1, matching what sv.metrics.MeanAveragePrecision and pycocotools AR report. They were 0.0, which made an empty bucket look like a model that found nothing. Skip negative values when you average mAR across runs or buckets; plots label undefined values N/A. (#2965)
import numpy as np
import supervision as sv
from supervision.metrics import MeanAverageRecall
predictions = sv.Detections(
xyxy=np.array([[0, 0, 10, 10]], dtype=float),
class_id=np.array([0]),
confidence=np.array([0.9]),
)
metric = MeanAverageRecall()
metric.update([predictions], [sv.Detections.empty()])
metric.compute().mAR_at_1 # -1.0, was 0.0Dataset split keeps every train item
sv.DetectionDataset.split, sv.ClassificationDataset.split and sv.KeyPointsDataset.split could drop one training item when the ratio times the number of images should be a whole number but float math rounded it down. 90 images at split_ratio=0.7 gave 62 train and 28 test images; they now give 63 and 27. The same seed can therefore produce a different split than in v0.32.0. A low-precision NumPy split_ratio such as np.float16(0.5) is now multiplied as its decimal value, so it no longer overcounts or raises OverflowError on large datasets. (#2969, #3058)
from supervision.dataset.utils import train_test_split
train, test = train_test_split(list(range(90)), train_ratio=0.7)
len(train), len(test) # (63, 27), v0.32.0 gave (62, 28)Windows paths and UTF-8 files load
On Windows, images in folders with accented, Cyrillic or CJK names can now be read and written, so sv.DetectionDataset loading, as_yolo, as_coco, as_pascal_voc and sv.ImageSink no longer fail with Could not read image from path or write garbled file names. (#2963) Label and annotation files that start with a UTF-8 byte order mark now load in from_yolo, from_coco and the other loaders, and the plain-text reader and writer use UTF-8 on every platform. (#2959)
ds = sv.DetectionDataset.from_yolo(
images_directory_path="données/images",
annotations_directory_path="données/labels",
data_yaml_path="données/data.yaml",
)🔄 Migration guide
No breaking changes in this release, and nothing was removed or newly deprecated. The deprecations announced in v0.32.0 are unchanged and still scheduled for v0.35.0.
Several fixes change returned, plotted or drawn values. If you compare results across versions, check these:
MeanAverageRecall: scores are-1instead of0.0without targets. Skip negative values when you average them, as with mAP. (#2965)ConfusionMatrix.plot(normalize=True): rows are normalized by true-class totals, so plotted numbers differ. (#2954)- Dataset
split: the train set gains one item when rounding used to drop it, and the same seed can split differently. A low-precision NumPysplit_ratiocan give one item fewer than before. Save a split if you need it stable. (#2969, #3058) sv.RichLabelAnnotator: text without capital-height glyphs, such ascar, is drawn about 2 px higher and a second line can sit 1 px lower, so pixel-exact label comparisons need a new baseline. (#3058)sv.scale_image,sv.resize_image,sv.letterbox_image: translucent BGRA images are resized with alpha-weighted colors, sosv.CropAnnotatorandsv.IconAnnotatoroutput changes along alpha edges and alpha can differ by one level. Uniform-alpha images are unchanged. (#3058)save_text_fileandread_txt_file: both use UTF-8, so files written on Windows with a non-UTF-8 locale change encoding, and existing files in a legacy locale encoding, such as Windows-1252, can fail withUnicodeDecodeErroruntil you transcode them to UTF-8. (#2959)
One dtype note: Detections.from_transformers and KeyPoints.from_transformers now accept bfloat16 outputs. Detections returns their boxes and scores as float32, KeyPoints keeps float32 coordinates and confidences, and other precisions are unchanged. (#2962)
📝 Notable changes
🔧 Fixed
- BGRA scenes: annotators no longer fail on
(H, W, 4)arrays: masks, halos, background overlay and comparison (#2956), heat map, crop and icon (#2958), rich labels (#2960) andsv.tint_image(#2961). The drawing helpers anddraw_textno longer draw transparent pixels on an opaque scene (#2957). - Metrics: the normalized confusion matrix plot and empty-target mAR scores gave misleading numbers (#2954, #2965). The normalized plot also hid small shares and mAP plots labeled an undefined score
-1.00; shares are now colored and the score readsN/A(#3058). - BGRA and image edge cases: translucent BGRA images resized with colored fringes,
sv.RichLabelAnnotatorplaced low glyphs outside a tight label background,sv.draw_filled_rectangleandsv.draw_filled_polygonraised on a zero-size scene, and the Windows non-ASCII image reader loaded whole files instead of mapping them (#3058). - Files and paths: Windows non-ASCII image paths failed to read or write, and BOM-prefixed text and JSON files failed to parse (#2963, #2959).
- Models:
Detections.from_transformersandKeyPoints.from_transformersraisedTypeError: Got unsupported ScalarType BFloat16onbfloat16outputs, andKeyPoints.from_transformersno longer fails on gradient-tracked pose tensors (#2962). - Boxes, images and datasets:
sv.xyxy_to_xcycarhoverflowed on integer boxes whose width or height exceeds the dtype's range,sv.resize_imageandsv.letterbox_imageoverflowed or failed on NumPy integer sizes such asint16, and dataset splits dropped a train item (#2966, #2967, #2969), andnp.float16split ratios miscounted items (#3058). - Documentation: added a semantic segmentation how-to guide and fixed dead links in the demo notebook (#3046, #3050).
🏆 Contributors
Thanks to everyone who worked on this release.
- Maidul Hasan Masum (@mh-masum6875) — made annotators and drawing helpers work on BGRA scenes, fixed non-ASCII image paths on Windows and read label files that start with a UTF-8 BOM.
- Owais (@owaiss21) — fixed row normalization in
ConfusionMatrix.plot. - Sohail Shaikh (@sohailshk, LinkedIn) — accepted
bfloat16outputs inDetections.from_transformersandKeyPoints.from_transformers. - Aditya Gupta (@MaiAditya, LinkedIn) — made
MeanAverageRecallreport-1for empty targets. - NIKHILA (@Nikhila-Dhevi-R, LinkedIn) — fixed integer overflow in
xyxy_to_xcycarhand NumPy integer sizes inresize_imageandletterbox_image. - Avanish Garg (@avanish-garg, LinkedIn) — fixed dataset
splitdropping a train item. - Emre Yoleri (@emreyoleridev) — fixed dead documentation links in the demo notebook.
Automated contributions: @dependabot
Full changelog: 0.32.0...0.32.1
Drafted by /oss:release, an AI skill in AI Rig. If it saved you time, a ⭐ helps others find it.