Skip to content

Commit 27c68f2

Browse files
authored
Merge pull request #1486 from roboflow/develop
`supervision-0.23.0` release
2 parents 93c1b94 + ee3d176 commit 27c68f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+4440
-1608
lines changed

.github/workflows/notebook-bot.yml

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Notebook Check Pull Request
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, reopened]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
comment-welcome:
12+
permissions:
13+
contents: read
14+
pull-requests: write
15+
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Fetch pull request branch
19+
uses: actions/checkout@v4
20+
with:
21+
repository: ${{ github.event.pull_request.head.repo.full_name }}
22+
ref: ${{ github.event.pull_request.head.sha }}
23+
- name: Fetch base develop branch
24+
run: git fetch -u "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" develop:develop
25+
- name: Create message
26+
env:
27+
HEAD_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name }}
28+
HEAD_REF: ${{ github.event.pull_request.head.ref }}
29+
PR_NUM: ${{ github.event.pull_request.number }}
30+
run: |
31+
# Preview links and tool usage only needed for notebook changes.
32+
readarray -t changed_notebooks < <(git diff --name-only develop | grep '\.ipynb$' || true)
33+
if [[ ${#changed_notebooks[@]} == 0 ]]; then
34+
echo "No notebooks modified in this pull request."
35+
else
36+
msg="<h4>Preview</h4>\n"
37+
msg+="Preview and run these notebook edits with Google Colab:\n<ul>\n"
38+
# Link to PR branch in user's fork that is always current.
39+
for fp in "${changed_notebooks[@]}"; do
40+
gh_path="${HEAD_REPOSITORY}/blob/${HEAD_REF}/${fp}"
41+
colab_url="https://colab.research.google.com/github/${gh_path}"
42+
msg+="<li><a href='${colab_url}'>${fp}</a></li>\n"
43+
done
44+
msg+="</ul>\n"
45+
46+
reviewnb_url="https://app.reviewnb.com/${GITHUB_REPOSITORY}/pull/${PR_NUM}/files/"
47+
msg+="Rendered <a href='${reviewnb_url}'>notebook diffs</a> available on ReviewNB.com.\n"
48+
49+
msg+="If commits are added to the pull request, synchronize your local branch: <code>git pull origin $HEAD_REF</code>\n"
50+
fi
51+
echo "MESSAGE=$msg" >> $GITHUB_ENV
52+
- name: Post comment
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
ISSUE_URL: ${{ github.event.pull_request.issue_url }}
56+
run: |
57+
# Env var defined in previous step. Escape string for JSON.
58+
body="$(echo -n -e $MESSAGE | python3 -c 'import json,sys; print(json.dumps(sys.stdin.read()))')"
59+
# Add comment to pull request.
60+
curl -X POST \
61+
-H "Accept: application/vnd.github.v3+json" \
62+
-H "Authorization: token $GITHUB_TOKEN" \
63+
"${ISSUE_URL}/comments" \
64+
--data "{\"body\": $body}"

.github/workflows/test-doc.yml

+5-18
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,8 @@ jobs:
1414
uses: actions/setup-python@v5
1515
with:
1616
python-version: '3.10'
17-
- name: 📦 Install mkdocs-material
18-
run: pip install "mkdocs-material[all]"
19-
- name: 📦 Install mkdocstrings[python]
20-
run: pip install "mkdocstrings[python]"
21-
- name: 📦 Install mkdocs-material[imaging]
22-
run: pip install "mkdocs-material[imaging]"
23-
- name: 📦 Install mike
24-
run: pip install "mike"
25-
- name: 📦 Install mkdocs-git-revision-date-localized-plugin
26-
run: pip install "mkdocs-git-revision-date-localized-plugin"
27-
- name: 📦 Install JupyterLab
28-
run: pip install jupyterlab
29-
- name: 📦 Install mkdocs-jupyter
30-
run: pip install mkdocs-jupyter
31-
- name: 📦 Install mkdocs-git-committers-plugin-2
32-
run: pip install mkdocs-git-committers-plugin-2
33-
- name: 🧪 Test documentation build
34-
run: mkdocs build --verbose
17+
- name: 🏗️ Install dependencies and Test Docs Build
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install "mkdocs-material" "mkdocstrings[python]" "mkdocs-material[imaging]" mike "mkdocs-git-revision-date-localized-plugin" jupyterlab mkdocs-jupyter mkdocs-git-committers-plugin-2
21+
mkdocs build --verbose

.pre-commit-config.yaml

+1-14
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ repos:
99
- repo: https://github.com/pre-commit/pre-commit-hooks
1010
rev: v4.6.0
1111
hooks:
12-
- id: end-of-file-fixer
1312
- id: trailing-whitespace
1413
exclude: test/.*\.py
1514
- id: check-yaml
@@ -19,33 +18,21 @@ repos:
1918
- id: check-case-conflict
2019
- id: check-added-large-files
2120
- id: detect-private-key
22-
- id: forbid-new-submodules
2321
- id: pretty-format-json
2422
exclude: demo.ipynb
2523
args: ['--autofix', '--no-sort-keys', '--indent=4']
2624
- id: end-of-file-fixer
2725
- id: mixed-line-ending
2826

29-
3027
- repo: https://github.com/PyCQA/bandit
3128
rev: '1.7.9'
3229
hooks:
3330
- id: bandit
3431
args: ["-c", "pyproject.toml"]
3532
additional_dependencies: ["bandit[toml]"]
3633

37-
- repo: https://github.com/pycqa/isort
38-
rev: 5.13.2
39-
hooks:
40-
- id: isort
41-
name: isort (python)
42-
- id: isort
43-
name: isort (pyi)
44-
types: [pyi]
45-
46-
4734
- repo: https://github.com/astral-sh/ruff-pre-commit
48-
rev: v0.5.1
35+
rev: v0.6.2
4936
hooks:
5037
- id: ruff
5138
args: [--fix, --exit-non-zero-on-fix]

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ Furthermore, we have integrated a pre-commit GitHub Action into our workflow. Th
173173

174174
To run the pre-commit tool, follow these steps:
175175

176-
1. Install pre-commit by running the following command: `poetry install`. It will not only install pre-commit but also install all the deps and dev-deps of project
176+
1. Install pre-commit by running the following command: `poetry install --with dev`. It will not only install pre-commit but also install all the deps and dev-deps of project
177177

178178
2. Once pre-commit is installed, navigate to the project's root directory.
179179

README.md

+12-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
[![version](https://badge.fury.io/py/supervision.svg)](https://badge.fury.io/py/supervision)
1818
[![downloads](https://img.shields.io/pypi/dm/supervision)](https://pypistats.org/packages/supervision)
19+
[![snyk](https://snyk.io/advisor/python/supervision/badge.svg)](https://snyk.io/advisor/python/supervision)
1920
[![license](https://img.shields.io/pypi/l/supervision)](https://github.com/roboflow/supervision/blob/main/LICENSE.md)
2021
[![python-version](https://img.shields.io/pypi/pyversions/supervision)](https://badge.fury.io/py/supervision)
2122
[![colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/roboflow/supervision/blob/main/demo.ipynb)
@@ -110,18 +111,21 @@ Supervision provides a set of [utils](https://supervision.roboflow.com/latest/da
110111

111112
```python
112113
import supervision as sv
114+
from roboflow import Roboflow
113115

114-
dataset = sv.DetectionDataset.from_yolo(
115-
images_directory_path=...,
116-
annotations_directory_path=...,
117-
data_yaml_path=...
116+
project = Roboflow().workspace(<WORKSPACE_ID>).project(<PROJECT_ID>)
117+
dataset = project.version(<PROJECT_VERSION>).download("coco")
118+
119+
ds = sv.DetectionDataset.from_coco(
120+
images_directory_path=f"{dataset.location}/train",
121+
annotations_path=f"{dataset.location}/train/_annotations.coco.json",
118122
)
119123

120-
dataset.classes
121-
['dog', 'person']
124+
path, image, annotation = ds[0]
125+
# loads image on demand
122126

123-
len(dataset)
124-
# 1000
127+
for path, image, annotation in ds:
128+
# loads image on demand
125129
```
126130

127131
<details close>

demo.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@
972972
}
973973
],
974974
"source": [
975-
"from supervision.assets import download_assets, VideoAssets\n",
975+
"from supervision.assets import VideoAssets, download_assets\n",
976976
"\n",
977977
"download_assets(VideoAssets.VEHICLES)\n",
978978
"VIDEO_PATH = VideoAssets.VEHICLES.value"

docs/changelog.md

+134-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,136 @@
1+
### 0.23.0 <small>Aug 28, 2024</small>
2+
3+
- Added [#930](https://github.com/roboflow/supervision/pull/930): `IconAnnotator`, a [new annotator](https://supervision.roboflow.com/latest/detection/annotators/#supervision.annotators.core.IconAnnotator) that allows drawing icons on each detection. Useful if you want to draw a specific icon for each class.
4+
5+
```python
6+
import supervision as sv
7+
from inference import get_model
8+
9+
image = <SOURCE_IMAGE_PATH>
10+
icon_dog = <DOG_PNG_PATH>
11+
icon_cat = <CAT_PNG_PATH>
12+
13+
model = get_model(model_id="yolov8n-640")
14+
results = model.infer(image)[0]
15+
detections = sv.Detections.from_inference(results)
16+
17+
icon_paths = []
18+
for class_name in detections.data["class_name"]:
19+
if class_name == "dog":
20+
icon_paths.append(icon_dog)
21+
elif class_name == "cat":
22+
icon_paths.append(icon_cat)
23+
else:
24+
icon_paths.append("")
25+
26+
icon_annotator = sv.IconAnnotator()
27+
annotated_frame = icon_annotator.annotate(
28+
scene=image.copy(),
29+
detections=detections,
30+
icon_path=icon_paths
31+
)
32+
```
33+
34+
- Added [#1385](https://github.com/roboflow/supervision/pull/1385): [`BackgroundColorAnnotator`](https://supervision.roboflow.com/latest/detection/annotators/#supervision.annotators.core.BackgroundColorAnnotator), that draws an overlay on the background images of the detections.
35+
36+
```python
37+
import supervision as sv
38+
from inference import get_model
39+
40+
image = <SOURCE_IMAGE_PATH>
41+
42+
model = get_model(model_id="yolov8n-640")
43+
results = model.infer(image)[0]
44+
detections = sv.Detections.from_inference(results)
45+
46+
background_overlay_annotator = sv.BackgroundOverlayAnnotator()
47+
annotated_frame = background_overlay_annotator.annotate(
48+
scene=image.copy(),
49+
detections=detections
50+
)
51+
```
52+
53+
- Added [#1386](https://github.com/roboflow/supervision/pull/1386): Support for Transformers v5 functions in [`sv.Detections.from_transformers`](https://supervision.roboflow.com/latest/detection/core/#supervision.detection.core.Detections.from_transformers). This includes the `DetrImageProcessor` methods `post_process_object_detection`, `post_process_panoptic_segmentation`, `post_process_semantic_segmentation`, and `post_process_instance_segmentation`.
54+
55+
```python
56+
import torch
57+
import supervision as sv
58+
from PIL import Image
59+
from transformers import DetrImageProcessor, DetrForObjectDetection
60+
61+
processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
62+
model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
63+
64+
image = Image.open(<SOURCE_IMAGE_PATH>)
65+
inputs = processor(images=image, return_tensors="pt")
66+
67+
with torch.no_grad():
68+
outputs = model(**inputs)
69+
70+
width, height = image.size
71+
target_size = torch.tensor([[height, width]])
72+
results = processor.post_process_object_detection(
73+
outputs=outputs, target_sizes=target_size)[0]
74+
detections = sv.Detections.from_transformers(
75+
transformers_results=results,
76+
id2label=model.config.id2label)
77+
```
78+
79+
- Added [#1354](https://github.com/roboflow/supervision/pull/1354): Ultralytics SAM (Segment Anything Model) support in [`sv.Detections.from_ultralytics`](https://supervision.roboflow.com/latest/detection/core/#supervision.detection.core.Detections.from_ultralytics). [SAM2](https://sam2.metademolab.com/) was released during this update, and is already supported via [`sv.Detections.from_sam`](https://supervision.roboflow.com/latest/detection/core/#supervision.detection.core.Detections.from_sam).
80+
81+
```python
82+
import supervision as sv
83+
from segment_anything import (
84+
sam_model_registry,
85+
SamAutomaticMaskGenerator
86+
)
87+
88+
sam_model_reg = sam_model_registry[MODEL_TYPE]
89+
sam = sam_model_reg(checkpoint=CHECKPOINT_PATH).to(device=DEVICE)
90+
mask_generator = SamAutomaticMaskGenerator(sam)
91+
sam_result = mask_generator.generate(IMAGE)
92+
detections = sv.Detections.from_sam(sam_result=sam_result)
93+
```
94+
95+
- Added [#1458](https://github.com/roboflow/supervision/pull/1458): `outline_color` options for [`TriangleAnnotator`](https://supervision.roboflow.com/latest/detection/annotators/#supervision.annotators.core.TriangleAnnotator) and [`DotAnnotator`](https://supervision.roboflow.com/latest/detection/annotators/#supervision.annotators.core.DotAnnotator).
96+
97+
- Added [#1409](https://github.com/roboflow/supervision/pull/1409): `text_color` option for [`VertexLabelAnnotator`](https://supervision.roboflow.com/latest/keypoint/annotators/#supervision.keypoint.annotators.VertexLabelAnnotator) keypoint annotator.
98+
99+
- Changed [#1434](https://github.com/roboflow/supervision/pull/1434): [`InferenceSlicer`](https://supervision.roboflow.com/latest/detection/tools/inference_slicer/) now features an `overlap_ratio_wh` parameter, making it easier to compute slice sizes when handling overlapping slices.
100+
101+
- Fix [#1448](https://github.com/roboflow/supervision/pull/1448): Various annotator type issues have been resolved, supporting expanded error handling.
102+
103+
- Fix [#1348](https://github.com/roboflow/supervision/pull/1348): Introduced a new method for [seeking to a specific video frame](https://supervision.roboflow.com/latest/utils/video/#supervision.utils.video.get_video_frames_generator), addressing cases where traditional seek methods were failing. It can be enabled with `iterative_seek=True`.
104+
105+
```python
106+
import supervision as sv
107+
108+
for frame in sv.get_video_frames_generator(
109+
source_path=<SOURCE_VIDEO_PATH>,
110+
start=60,
111+
iterative_seek=True
112+
):
113+
...
114+
```
115+
116+
- Fix [#1424](https://github.com/roboflow/supervision/pull/1424): `plot_image` function now clearly indicates that the size is in inches.
117+
118+
!!! failure "Removed"
119+
120+
The `track_buffer`, `track_thresh`, and `match_thresh` parameters in [`ByteTrack`](trackers.md/#supervision.tracker.byte_tracker.core.ByteTrack) are deprecated and were removed as of `supervision-0.23.0`. Use `lost_track_buffer,` `track_activation_threshold`, and `minimum_matching_threshold` instead.
121+
122+
!!! failure "Removed"
123+
124+
The `triggering_position ` parameter in [`sv.PolygonZone`](detection/tools/polygon_zone.md/#supervision.detection.tools.polygon_zone.PolygonZone) was removed as of `supervision-0.23.0`. Use `triggering_anchors ` instead.
125+
126+
!!! failure "Deprecated"
127+
128+
`overlap_filter_strategy` in `InferenceSlicer.__init__` is deprecated and will be removed in `supervision-0.27.0`. Use `overlap_strategy` instead.
129+
130+
!!! failure "Deprecated"
131+
132+
`overlap_ratio_wh` in `InferenceSlicer.__init__` is deprecated and will be removed in `supervision-0.27.0`. Use `overlap_wh` instead.
133+
1134
### 0.22.0 <small>Jul 12, 2024</small>
2135

3136
- Added [#1326](https://github.com/roboflow/supervision/pull/1326): [`sv.DetectionsDataset`](https://supervision.roboflow.com/latest/datasets/core/#supervision.dataset.core.DetectionDataset) and [`sv.ClassificationDataset`](https://supervision.roboflow.com/latest/datasets/core/#supervision.dataset.core.ClassificationDataset) allowing to load the images into memory only when necessary (lazy loading).
@@ -360,7 +493,7 @@ annotated_frame = crop_annotator.annotate(
360493

361494
!!! failure "Deprecated"
362495

363-
The `track_buffer`, `track_thresh`, and `match_thresh` parameters in `sv.ByterTrack` are deprecated and will be removed in `supervision-0.23.0`. Use `lost_track_buffer,` `track_activation_threshold`, and `minimum_matching_threshold` instead.
496+
The `track_buffer`, `track_thresh`, and `match_thresh` parameters in `sv.ByteTrack` are deprecated and will be removed in `supervision-0.23.0`. Use `lost_track_buffer,` `track_activation_threshold`, and `minimum_matching_threshold` instead.
364497

365498
- Changed [#910](https://github.com/roboflow/supervision/pull/910): [`sv.PolygonZone`](/0.19.0/detection/tools/polygon_zone/#supervision.detection.tools.polygon_zone.PolygonZone) to now accept a list of specific box anchors that must be in zone for a detection to be counted.
366499

docs/datasets/core.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
comments: true
3-
status: new
43
---
54

65
# Datasets

docs/deprecated.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@ status: deprecated
77

88
These features are phased out due to better alternatives or potential issues in future versions. Deprecated functionalities are supported for **five subsequent releases**, providing time for users to transition to updated methods.
99

10-
- The `track_buffer`, `track_thresh`, and `match_thresh` parameters in [`ByterTrack`](trackers.md/#supervision.tracker.byte_tracker.core.ByteTrack) are deprecated and will be removed in `supervision-0.23.0`. Use `lost_track_buffer,` `track_activation_threshold`, and `minimum_matching_threshold` instead.
11-
- The `triggering_position ` parameter in [`sv.PolygonZone`](detection/tools/polygon_zone.md/#supervision.detection.tools.polygon_zone.PolygonZone) will be removed in `supervision-0.23.0`. Use `triggering_anchors ` instead.
1210
- The `frame_resolution_wh ` parameter in [`sv.PolygonZone`](detection/tools/polygon_zone.md/#supervision.detection.tools.polygon_zone.PolygonZone) will be removed in `supervision-0.24.0`.
13-
- Constructing `DetectionDataset` and `ClassificationDataset` with parameter `images` as `Dict[str, np.ndarray]` will be removed in `supervision-0.26.0`. Please pass a list of paths `List[str]` instead.
11+
12+
- Constructing [`DetectionDataset`](https://supervision.roboflow.com/latest/datasets/core/#supervision.dataset.core.DetectionDataset) and [`ClassificationDataset`](https://supervision.roboflow.com/latest/datasets/core/#supervision.dataset.core.ClassificationDataset) with parameter `images` as `Dict[str, np.ndarray]` will be removed in `supervision-0.26.0`. Please pass a list of paths `List[str]` instead.
1413
- The `DetectionDataset.images` property will be removed in `supervision-0.26.0`. Please loop over images with `for path, image, annotation in dataset:`, as that does not require loading all images into memory.
15-
- `BoundingBoxAnnotator` has been renamed to `BoxAnnotator` after the old implementation of `BoxAnnotator` has been removed. `BoundingBoxAnnotator` will be removed in `supervision-0.26.0`.
14+
- `BoundingBoxAnnotator` has been renamed to `BoxAnnotator` after the old implementation of [`BoxAnnotator`](https://supervision.roboflow.com/latest/detection/annotators/#supervision.annotators.core.BoxAnnotator) has been removed. `BoundingBoxAnnotator` will be removed in `supervision-0.26.0`.
15+
16+
- `overlap_filter_strategy` in [`InferenceSlicer.__init__`](https://supervision.roboflow.com/latest/detection/tools/inference_slicer/) is deprecated and will be removed in `supervision-0.27.0`. Use `overlap_strategy` instead.
17+
- `overlap_ratio_wh` in [`InferenceSlicer.__init__`](https://supervision.roboflow.com/latest/detection/tools/inference_slicer/) is deprecated and will be removed in `supervision-0.27.0`. Use `overlap_wh` instead.
1618

1719
# Removed
1820

21+
### 0.23.0
22+
23+
- The `track_buffer`, `track_thresh`, and `match_thresh` parameters in [`ByteTrack`](trackers.md/#supervision.tracker.byte_tracker.core.ByteTrack) are deprecated and were removed as of `supervision-0.23.0`. Use `lost_track_buffer,` `track_activation_threshold`, and `minimum_matching_threshold` instead.
24+
- The `triggering_position ` parameter in [`sv.PolygonZone`](detection/tools/polygon_zone.md/#supervision.detection.tools.polygon_zone.PolygonZone) was removed as of `supervision-0.23.0`. Use `triggering_anchors ` instead.
25+
26+
### 0.22.0
27+
1928
- [`Detections.from_froboflow`](detection/core.md/#supervision.detection.core.Detections.from_roboflow) is removed as of `supervision-0.22.0`. Use [`Detections.from_inference`](detection/core.md/#supervision.detection.core.Detections.from_inference) instead.
2029
- The method `Color.white()` was removed as of `supervision-0.22.0`. Use the constant `Color.WHITE` instead.
2130
- The method `Color.black()` was removed as of `supervision-0.22.0`. Use the constant `Color.BLACK` instead.

0 commit comments

Comments
 (0)