Compare commits

...
25 Commits
Author SHA1 Message Date
SkalskiP 87979384ed Update project version in pyproject.toml file
The project version in the pyproject.toml file has been updated from 0.17.0rc6 to 0.17.0rc7.
2023-12-05 12:14:28 +01:00
Piotr Skalski 83603e3677 Merge pull request #633 from roboflow/add-piexlate-annotator
Add `PixelateAnnotator`
2023-12-05 12:05:39 +01:00
pre-commit-ci[bot] 566a9296d0 fix(pre_commit): 🎨 auto format pre-commit hooks 2023-12-05 11:04:16 +00:00
SkalskiP 9612fe7849 Refactor PixelateAnnotator and update docs 2023-12-05 12:03:59 +01:00
Piotr Skalski b69eea47a9 Update 🔥 quick start section in README.md 2023-12-04 21:37:30 +01:00
Piotr Skalski fe9b422185 Update 🔥 quick start section in README.md 2023-12-04 21:28:01 +01:00
Piotr Skalski d6fd1b0644 Merge pull request #643 from roboflow/og-images
Add open graph images to documentation.
2023-12-04 18:49:22 +01:00
James Gallagher 1ef1622126 add lenny 2023-12-04 17:03:05 +00:00
James Gallagher e45e1e277b resubmit mkdocs pr 2023-12-04 17:02:44 +00:00
Piotr Skalski b1ac5bc876 Merge pull request #566 from roboflow/min-ver-settings
build(deps): 🚀 min and max supervision package requirements are added
2023-12-04 18:02:04 +01:00
Onuralp SEZER 178d91eaa0 Merge pull request #639 from roboflow/add-open-graph-images
Add mkdocs-material[imaging] dependency
2023-12-04 19:31:26 +03:00
Onuralp SEZER 726ad1dbb1 Merge branch 'develop' into min-ver-settings 2023-12-04 19:23:20 +03:00
SkalskiP e08e4ee389 Rename calculate_dynamic_font_scale to calculate_dynamic_text_scale 2023-12-04 17:05:49 +01:00
SkalskiP 23a58ef99e Rename calculate_dynamic_font_scale to calculate_dynamic_text_scale 2023-12-04 17:04:07 +01:00
James Gallagher 1710021ece add mkdocs-material[imaging] dependency 2023-12-04 15:22:23 +00:00
pre-commit-ci[bot] f046940bb5 fix(pre_commit): 🎨 auto format pre-commit hooks 2023-12-04 14:08:00 +00:00
James Gallagher e7e542d160 add required import 2023-12-04 14:07:25 +00:00
James Gallagher dd19c4e185 work on annotator 2023-12-04 14:05:49 +00:00
James Gallagher dfb703219e work on annotator 2023-12-04 14:04:59 +00:00
pre-commit-ci[bot] 8946d44dcb fix(pre_commit): 🎨 auto format pre-commit hooks 2023-12-04 13:16:58 +00:00
capjamesg 718f1b077d add pixelate annotator 2023-12-04 13:15:45 +00:00
Onuralp SEZER b3dec1a734 Merge branch 'develop' into min-ver-settings 2023-11-15 21:39:37 +03:00
Onuralp SEZER 583ad5f6e2 ci: 👷 ci job are renamed
Signed-off-by: Onuralp SEZER <thunderbirdtr@gmail.com>
2023-11-03 14:11:12 +03:00
Onuralp SEZER 9a0f35fcf9 ci: 👷 python3.8 and minimum version package CI added
Signed-off-by: Onuralp SEZER <thunderbirdtr@gmail.com>
2023-11-02 22:19:35 +03:00
Onuralp SEZER 7a7b50eb12 build(deps): 🚀 min and max supervision package reqs are added
Signed-off-by: Onuralp SEZER <thunderbirdtr@gmail.com>
2023-11-02 22:17:27 +03:00
14 changed files with 1167 additions and 991 deletions
+27
View File
@@ -0,0 +1,27 @@
attrs==23.1.0
certifi==2023.7.22
charset-normalizer==2.0.12
cycler==0.12.1
exceptiongroup==1.1.3
fonttools==4.43.1
idna==3.4
iniconfig==2.0.0
kiwisolver==1.4.5
matplotlib==3.5.0
numpy==1.24.4
opencv-python==4.5.5.64
packaging==23.2
Pillow==10.1.0
pluggy==1.3.0
pyparsing==3.1.1
pytest==7.2.0
python-dateutil==2.8.2
PyYAML==5.3
requests==2.26.0
scipy==1.9.0
setuptools-scm==8.0.4
six==1.16.0
tomli==2.0.1
tqdm==4.62.3
typing_extensions==4.8.0
urllib3==1.26.18
+1
View File
@@ -22,4 +22,5 @@ jobs:
python-version: 3.x
- run: pip install mkdocs-material
- run: pip install "mkdocstrings[python]"
- run: pip install "mkdocs-material[imaging]"
- run: mkdocs gh-deploy --force
+32
View File
@@ -0,0 +1,32 @@
name: Python 3.8 - Min Dep Test WorkFlow
on:
pull_request:
branches: [main, develop]
jobs:
build-min-dep-test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8"]
steps:
- name: 🛎️ Checkout
uses: actions/checkout@v4
- name: 🐍 Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
# id based on python version
id: python-setup
with:
python-version: ${{ matrix.python-version }}
check-latest: true
cache: 'pip'
cache-dependency-path: '**/requirements-dev-min.txt'
- name: 📦 Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r .github/requirements-dev-min.txt
- name: 🧪 Test
run: "python -m pytest ./test"
+1 -1
View File
@@ -5,7 +5,7 @@ on:
branches: [main, develop]
jobs:
build:
build-dev-test:
runs-on: ubuntu-latest
strategy:
matrix:
+49 -135
View File
@@ -41,66 +41,55 @@ Read more about desktop, headless, and local installation in our [guide](https:/
## 🔥 quickstart
### [detections processing](https://roboflow.github.io/supervision/detection/core/)
### models
Supervision was designed to be model agnostic. Just plug in any classification, detection, or segmentation model. For your convenience, we have created [connectors](https://supervision.roboflow.com/detection/core/#detections) for the most popular libraries like Ultralytics, Transformers, or MMDetection.
```python
>>> import cv2
>>> import supervision as sv
>>> from ultralytics import YOLO
>>> image = cv2.imread(...)
>>> model = YOLO('yolov8s.pt')
>>> result = model(IMAGE)[0]
>>> result = model(image)[0]
>>> detections = sv.Detections.from_ultralytics(result)
>>> len(detections)
5
```
<details close>
<summary>👉 more detections utils</summary>
### annotators
- Easily switch inference pipeline between supported object detection/instance segmentation models
Supervision offers a wide range of highly customizable [annotators](https://supervision.roboflow.com/annotators/), allowing you to compose the perfect visualization for your use case.
```python
>>> import supervision as sv
>>> from segment_anything import sam_model_registry, SamAutomaticMaskGenerator
```python
>>> import cv2
>>> import supervision as sv
>>> sam = sam_model_registry[MODEL_TYPE](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)
```
>>> image = cv2.imread(...)
>>> detections = sv.Detections(...)
- [Advanced filtering](https://roboflow.github.io/supervision/quickstart/detections/)
>>> bounding_box_annotator = sv.BoundingBoxAnnotator()
>>> annotated_frame = bounding_box_annotator.annotate(
... scene=image.copy(),
... detections=detections
... )
```
```python
>>> detections = detections[detections.class_id == 0]
>>> detections = detections[detections.confidence > 0.5]
>>> detections = detections[detections.area > 1000]
```
https://github.com/roboflow/supervision/assets/26109316/691e219c-0565-4403-9218-ab5644f39bce
- Image annotation
### datasets
```python
>>> import supervision as sv
>>> box_annotator = sv.BoxAnnotator()
>>> annotated_frame = box_annotator.annotate(
... scene=IMAGE,
... detections=detections
... )
```
</details>
### [datasets processing](https://roboflow.github.io/supervision/dataset/core/)
Supervision provides a set of [utils](https://supervision.roboflow.com/datasets/) that allow you to load, split, merge, and save datasets in one of the supported formats.
```python
>>> import supervision as sv
>>> dataset = sv.DetectionDataset.from_yolo(
... images_directory_path='...',
... annotations_directory_path='...',
... data_yaml_path='...'
... images_directory_path=...,
... annotations_directory_path=...,
... data_yaml_path=...
... )
>>> dataset.classes
@@ -113,38 +102,27 @@ Read more about desktop, headless, and local installation in our [guide](https:/
<details close>
<summary>👉 more dataset utils</summary>
- Load object detection/instance segmentation datasets in one of the supported formats
- load
```python
>>> dataset = sv.DetectionDataset.from_yolo(
... images_directory_path='...',
... annotations_directory_path='...',
... data_yaml_path='...'
... images_directory_path=...,
... annotations_directory_path=...,
... data_yaml_path=...
... )
>>> dataset = sv.DetectionDataset.from_pascal_voc(
... images_directory_path='...',
... annotations_directory_path='...'
... images_directory_path=...,
... annotations_directory_path=...
... )
>>> dataset = sv.DetectionDataset.from_coco(
... images_directory_path='...',
... annotations_path='...'
... images_directory_path=...,
... annotations_path=...
... )
```
- Loop over dataset entries
```python
>>> for name, image, labels in dataset:
... print(labels.xyxy)
array([[404. , 719. , 538. , 884.5 ],
[155. , 497. , 404. , 833.5 ],
[ 20.154999, 347.825 , 416.125 , 915.895 ]], dtype=float32)
```
- Split dataset for training, testing, and validation
- split
```python
>>> train_dataset, test_dataset = dataset.split(split_ratio=0.7)
@@ -154,7 +132,7 @@ Read more about desktop, headless, and local installation in our [guide](https:/
(700, 150, 150)
```
- Merge multiple datasets
- merge
```python
>>> ds_1 = sv.DetectionDataset(...)
@@ -176,103 +154,39 @@ Read more about desktop, headless, and local installation in our [guide](https:/
['cat', 'dog', 'person']
```
- Save object detection/instance segmentation datasets in one of the supported formats
- save
```python
>>> dataset.as_yolo(
... images_directory_path='...',
... annotations_directory_path='...',
... data_yaml_path='...'
... images_directory_path=...,
... annotations_directory_path=...,
... data_yaml_path=...
... )
>>> dataset.as_pascal_voc(
... images_directory_path='...',
... annotations_directory_path='...'
... images_directory_path=...,
... annotations_directory_path=...
... )
>>> dataset.as_coco(
... images_directory_path='...',
... annotations_path='...'
... images_directory_path=...,
... annotations_path=...
... )
```
- Convert labels between supported formats
- convert
```python
>>> sv.DetectionDataset.from_yolo(
... images_directory_path='...',
... annotations_directory_path='...',
... data_yaml_path='...'
... images_directory_path=...,
... annotations_directory_path=...,
... data_yaml_path=...
... ).as_pascal_voc(
... images_directory_path='...',
... annotations_directory_path='...'
... images_directory_path=...,
... annotations_directory_path=...
... )
```
- Load classification datasets in one of the supported formats
```python
>>> cs = sv.ClassificationDataset.from_folder_structure(
... root_directory_path='...'
... )
```
- Save classification datasets in one of the supported formats
```python
>>> cs.as_folder_structure(
... root_directory_path='...'
... )
```
</details>
### [model evaluation](https://roboflow.github.io/supervision/metrics/detection/)
```python
>>> import supervision as sv
>>> dataset = sv.DetectionDataset.from_yolo(...)
>>> def callback(image: np.ndarray) -> sv.Detections:
... ...
>>> 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.]
])
```
<details close>
<summary>👉 more metrics</summary>
- Mean average precision (mAP) for object detection tasks.
```python
>>> import supervision as sv
>>> dataset = sv.DetectionDataset.from_yolo(...)
>>> def callback(image: np.ndarray) -> sv.Detections:
... ...
>>> mean_average_precision = sv.MeanAveragePrecision.benchmark(
... dataset = dataset,
... callback = callback
... )
>>> mean_average_precision.map50_95
0.433
```
</details>
## 🎬 tutorials
+25
View File
@@ -229,6 +229,27 @@
</div>
=== "Pixelate"
```python
>>> import supervision as sv
>>> image = ...
>>> detections = sv.Detections(...)
>>> pixelate_annotator = sv.PixelateAnnotator()
>>> annotated_frame = pixelate_annotator.annotate(
... scene=image.copy(),
... detections=detections
... )
```
<div class="result" markdown>
![pixelate-annotator-example](https://media.roboflow.com/supervision-annotator-examples/pixelate-annotator-example-10.png){ align=center width="800" }
</div>
=== "Trace"
```python
@@ -337,6 +358,10 @@
:::supervision.annotators.core.BlurAnnotator
## PixelateAnnotator
:::supervision.annotators.core.PixelateAnnotator
## TraceAnnotator
:::supervision.annotators.core.TraceAnnotator
Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

+1 -1
View File
@@ -24,7 +24,7 @@
## calculate_dynamic_font_scale
:::supervision.draw.utils.calculate_dynamic_font_scale
:::supervision.draw.utils.calculate_dynamic_text_scale
## calculate_dynamic_line_thickness
+6 -3
View File
@@ -1,7 +1,7 @@
site_name: Supervision
site_url: https://supervision.roboflow.com/
site_author: Roboflow
site_description: A set of easy-to-use utils that will come in handy in any Computer Vision project
site_description: A set of easy-to-use utilities that will come in handy in any computer vision project.
repo_name: roboflow/supervision
repo_url: https://github.com/roboflow/supervision
edit_uri: https://github.com/roboflow/supervision/tree/main/docs
@@ -60,8 +60,8 @@ nav:
theme:
name: 'material'
logo: https://media.roboflow.com/open-source/supervision/supervision-lenny.png
favicon: https://media.roboflow.com/open-source/supervision/supervision-lenny.png
logo: assets/supervision-lenny.png
favicon: assets/supervision-lenny.png
palette:
# Palette for light mode
- scheme: default
@@ -85,6 +85,9 @@ theme:
plugins:
- mkdocstrings
- search
- social:
cards_layout_dir: docs/layouts
cards_layout: custom
markdown_extensions:
- admonition
Generated
+946 -839
View File
File diff suppressed because it is too large Load Diff
+10 -10
View File
@@ -1,6 +1,6 @@
[tool.poetry]
name = "supervision"
version = "0.17.0rc5"
version = "0.17.0rc7"
description = "A set of easy-to-use utils that will come in handy in any Computer Vision project"
authors = ["Piotr Skalski <piotr.skalski92@gmail.com>"]
maintainers = ["Piotr Skalski <piotr.skalski92@gmail.com>"]
@@ -36,15 +36,15 @@ classifiers=[
[tool.poetry.dependencies]
python = ">=3.8,<3.12.0"
numpy = "^1.20.0"
matplotlib = "^3.7.1"
pyyaml = "^6.0"
pillow = ">=9.4,<11.0"
opencv-python = { version = "^4.8.0.74", optional = true }
opencv-python-headless = "^4.8.0.74"
scipy = "^1.9.0"
requests = { version = "^2.31.0", optional = true }
tqdm = { version = "^4.66.1", optional = true }
numpy = ">=1.24.0,>=1.26.1"
matplotlib = ">=3.5.0,>=3.8.1"
pyyaml = ">=5.3,<=6.0.1"
pillow = ">=9.4,<=10.1.0"
opencv-python = { version = ">=4.5.5.64,<=4.8.1.78", optional = true }
opencv-python-headless = ">=4.5.5.64,<=4.8.1.78"
scipy = ">=1.9.0,<=2.0.0"
requests = { version = ">=2.26.0,<=2.31.0", optional = true }
tqdm = { version = ">=4.62.3,<=4.66.1", optional = true }
[tool.poetry.extras]
+2 -1
View File
@@ -18,6 +18,7 @@ from supervision.annotators.core import (
HeatMapAnnotator,
LabelAnnotator,
MaskAnnotator,
PixelateAnnotator,
PolygonAnnotator,
TraceAnnotator,
)
@@ -45,8 +46,8 @@ from supervision.detection.utils import (
)
from supervision.draw.color import Color, ColorPalette
from supervision.draw.utils import (
calculate_dynamic_font_scale,
calculate_dynamic_line_thickness,
calculate_dynamic_text_scale,
draw_filled_rectangle,
draw_image,
draw_line,
+66
View File
@@ -1197,3 +1197,69 @@ class HeatMapAnnotator:
mask
]
return scene
class PixelateAnnotator(BaseAnnotator):
"""
A class for pixelating regions in an image using provided detections.
"""
def __init__(self, pixel_size: int = 20):
"""
Args:
pixel_size (int): The size of the pixelation.
"""
self.pixel_size: int = pixel_size
def annotate(
self,
scene: np.ndarray,
detections: Detections,
) -> np.ndarray:
"""
Annotates the given scene by pixelating regions based on the provided
detections.
Args:
scene (np.ndarray): The image where pixelating will be applied.
detections (Detections): Object detections to annotate.
Returns:
The annotated image.
Example:
```python
>>> import supervision as sv
>>> image = ...
>>> detections = sv.Detections(...)
>>> pixelate_annotator = sv.PixelateAnnotator()
>>> annotated_frame = pixelate_annotator.annotate(
... scene=image.copy(),
... detections=detections
... )
```
![pixelate-annotator-example](https://media.roboflow.com/
supervision-annotator-examples/pixelate-annotator-example-10.png)
"""
image_height, image_width = scene.shape[:2]
clipped_xyxy = clip_boxes(
xyxy=detections.xyxy, resolution_wh=(image_width, image_height)
).astype(int)
for x1, y1, x2, y2 in clipped_xyxy:
roi = scene[y1:y2, x1:x2]
scaled_up_roi = cv2.resize(
src=roi, dsize=None, fx=1 / self.pixel_size, fy=1 / self.pixel_size
)
scaled_down_roi = cv2.resize(
src=scaled_up_roi,
dsize=(roi.shape[1], roi.shape[0]),
interpolation=cv2.INTER_NEAREST,
)
scene[y1:y2, x1:x2] = scaled_down_roi
return scene
+1 -1
View File
@@ -233,7 +233,7 @@ def draw_image(
return scene
def calculate_dynamic_font_scale(resolution_wh: Tuple[int, int]) -> float:
def calculate_dynamic_text_scale(resolution_wh: Tuple[int, int]) -> float:
"""
Calculate a dynamic font scale based on the resolution of an image.