diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md index 9e8aca5c..9782ed9a 100644 --- a/.github/CODE_OF_CONDUCT.md +++ b/.github/CODE_OF_CONDUCT.md @@ -2,129 +2,81 @@ ## Our Pledge -We as members, contributors, and leaders pledge to make participation in our -community a harassment-free experience for everyone, regardless of age, body -size, visible or invisible disability, ethnicity, sex characteristics, gender -identity and expression, level of experience, education, socioeconomic status, -nationality, personal appearance, race, caste, color, religion, or sexual -identity and orientation. +We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socioeconomic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation. -We pledge to act and interact in ways that contribute to an open, welcoming, -diverse, inclusive, and healthy community. +We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. ## Our Standards -Examples of behavior that contributes to a positive environment for our -community include: +Examples of behavior that contributes to a positive environment for our community include: - Demonstrating empathy and kindness toward other people - Being respectful of differing opinions, viewpoints, and experiences - Giving and gracefully accepting constructive feedback -- Accepting responsibility and apologizing to those affected by our mistakes, - and learning from the experience -- Focusing on what is best not just for us as individuals, but for the overall - community +- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience +- Focusing on what is best not just for us as individuals, but for the overall community Examples of unacceptable behavior include: -- The use of sexualized language or imagery, and sexual attention or advances of - any kind +- The use of sexualized language or imagery, and sexual attention or advances of any kind - Trolling, insulting or derogatory comments, and personal or political attacks - Public or private harassment -- Publishing others' private information, such as a physical or email address, - without their explicit permission -- Other conduct which could reasonably be considered inappropriate in a - professional setting +- Publishing others' private information, such as a physical or email address, without their explicit permission +- Other conduct which could reasonably be considered inappropriate in a professional setting ## Enforcement Responsibilities -Community leaders are responsible for clarifying and enforcing our standards of -acceptable behavior and will take appropriate and fair corrective action in -response to any behavior that they deem inappropriate, threatening, offensive, -or harmful. +Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. -Community leaders have the right and responsibility to remove, edit, or reject -comments, commits, code, wiki edits, issues, and other contributions that are -not aligned to this Code of Conduct, and will communicate reasons for moderation -decisions when appropriate. +Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. ## Scope -This Code of Conduct applies within all community spaces, and also applies when -an individual is officially representing the community in public spaces. -Examples of representing our community include using an official e-mail address, -posting via an official social media account, or acting as an appointed -representative at an online or offline event. +This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. ## Enforcement -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported to the community leaders responsible for enforcement at -community-reports@roboflow.com. +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at community-reports@roboflow.com. All complaints will be reviewed and investigated promptly and fairly. -All community leaders are obligated to respect the privacy and security of the -reporter of any incident. +All community leaders are obligated to respect the privacy and security of the reporter of any incident. ## Enforcement Guidelines -Community leaders will follow these Community Impact Guidelines in determining -the consequences for any action they deem in violation of this Code of Conduct: +Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: ### 1. Correction -**Community Impact**: Use of inappropriate language or other behavior deemed -unprofessional or unwelcome in the community. +**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. -**Consequence**: A private, written warning from community leaders, providing -clarity around the nature of the violation and an explanation of why the -behavior was inappropriate. A public apology may be requested. +**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. ### 2. Warning -**Community Impact**: A violation through a single incident or series of -actions. +**Community Impact**: A violation through a single incident or series of actions. -**Consequence**: A warning with consequences for continued behavior. No -interaction with the people involved, including unsolicited interaction with -those enforcing the Code of Conduct, for a specified period of time. This -includes avoiding interactions in community spaces as well as external channels -like social media. Violating these terms may lead to a temporary or permanent -ban. +**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. ### 3. Temporary Ban -**Community Impact**: A serious violation of community standards, including -sustained inappropriate behavior. +**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. -**Consequence**: A temporary ban from any sort of interaction or public -communication with the community for a specified period of time. No public or -private interaction with the people involved, including unsolicited interaction -with those enforcing the Code of Conduct, is allowed during this period. -Violating these terms may lead to a permanent ban. +**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. ### 4. Permanent Ban -**Community Impact**: Demonstrating a pattern of violation of community -standards, including sustained inappropriate behavior, harassment of an -individual, or aggression toward or disparagement of classes of individuals. +**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. -**Consequence**: A permanent ban from any sort of public interaction within the -community. +**Consequence**: A permanent ban from any sort of public interaction within the community. ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], -version 2.1, available at -[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. -Community Impact Guidelines were inspired by -[Mozilla's code of conduct enforcement ladder][mozilla coc]. +Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][mozilla coc]. -For answers to common questions about this code of conduct, see the FAQ at -[https://www.contributor-covenant.org/faq][faq]. Translations are available at -[https://www.contributor-covenant.org/translations][translations]. +For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq][faq]. Translations are available at [https://www.contributor-covenant.org/translations][translations]. [faq]: https://www.contributor-covenant.org/faq [homepage]: https://www.contributor-covenant.org diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 040eabe9..7d7e6882 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -44,39 +44,12 @@ Before you contribute a new feature, consider submitting an Issue to discuss the ### API Design Principles -Supervision APIs should remain generic, composable, and predictable across model -families. Before adding a new integration, annotator option, or data conversion -method, check the existing `sv.Detections`, `sv.KeyPoints`, and annotator -patterns and follow these principles: +Supervision APIs should remain generic, composable, and predictable across model families. Before adding a new integration, annotator option, or data conversion method, check the existing `sv.Detections`, `sv.KeyPoints`, and annotator patterns and follow these principles: -1. **Model integrations normalize raw external outputs into existing Supervision - containers.** Use `sv.Detections` for detection, segmentation, and other - instance-level predictions that include boxes, masks, class ids, confidence - scores, or extra per-instance fields. Use `sv.KeyPoints` for standalone - keypoint or pose predictions when keypoints exist independently of detection - boxes (e.g. pure pose estimation, landmark detection on pre-cropped images). - Use `Detections.keypoints` when keypoints are always co-incident with boxes - from the same model — the field stores an `(n, K, 2)` or `(n, K, 3)` array - where the optional third channel is per-point confidence in `[0, 1]`. -2. **Do not add a `from_` method when the model already returns a - Supervision object.** `from_*` methods are for converting raw outputs from - external packages such as Ultralytics, Transformers, Inference, or MediaPipe. - If a model's `predict()` method already returns `sv.Detections`, keep that - result type and store additional structured payloads in `detections.data` or - `detections.metadata` using documented keys. -3. **Annotators render data; filtering and visibility are container state.** - Filtering by confidence, class id, tracker id, geometry, or custom data should - happen before annotation through the container slicing APIs, for example - `detections[detections.confidence > 0.7]` or `key_points[key_points.confidence > 0.5]`. - Per-point presentation state, such as a `KeyPoints.visible` mask, may - live on the container and be honored consistently by annotators. -4. **Annotator constructor arguments should describe visual presentation, not - model-quality gates.** Use constructor arguments for color, thickness, - opacity, text, position, style, and generic visualization parameters such as - sigma levels. Annotators may skip invalid geometry defensively, including - missing points, zero-area boxes, non-finite coordinates, or points marked - invisible on the container. They should not introduce confidence thresholds or - model-specific quality gates as rendering options. +1. **Model integrations normalize raw external outputs into existing Supervision containers.** Use `sv.Detections` for detection, segmentation, and other instance-level predictions that include boxes, masks, class ids, confidence scores, or extra per-instance fields. Use `sv.KeyPoints` for standalone keypoint or pose predictions when keypoints exist independently of detection boxes (e.g. pure pose estimation, landmark detection on pre-cropped images). Use `Detections.keypoints` when keypoints are always co-incident with boxes from the same model — the field stores an `(n, K, 2)` or `(n, K, 3)` array where the optional third channel is per-point confidence in `[0, 1]`. +2. **Do not add a `from_` method when the model already returns a Supervision object.** `from_*` methods are for converting raw outputs from external packages such as Ultralytics, Transformers, Inference, or MediaPipe. If a model's `predict()` method already returns `sv.Detections`, keep that result type and store additional structured payloads in `detections.data` or `detections.metadata` using documented keys. +3. **Annotators render data; filtering and visibility are container state.** Filtering by confidence, class id, tracker id, geometry, or custom data should happen before annotation through the container slicing APIs, for example `detections[detections.confidence > 0.7]` or `key_points[key_points.confidence > 0.5]`. Per-point presentation state, such as a `KeyPoints.visible` mask, may live on the container and be honored consistently by annotators. +4. **Annotator constructor arguments should describe visual presentation, not model-quality gates.** Use constructor arguments for color, thickness, opacity, text, position, style, and generic visualization parameters such as sigma levels. Annotators may skip invalid geometry defensively, including missing points, zero-area boxes, non-finite coordinates, or points marked invisible on the container. They should not introduce confidence thresholds or model-specific quality gates as rendering options. ## How to Contribute Changes @@ -263,18 +236,11 @@ To run the pre-commit tool, follow these steps: ### Docstrings -All new functions and classes in `supervision` should include docstrings. This is a -prerequisite for any new functions and classes to be added to the library. +All new functions and classes in `supervision` should include docstrings. This is a prerequisite for any new functions and classes to be added to the library. -`supervision` adheres to the -[Google Python docstring style](https://google.github.io/styleguide/pyguide.html#383-functions-and-methods). -Please refer to the style guide while writing docstrings for your contribution. +`supervision` adheres to the [Google Python docstring style](https://google.github.io/styleguide/pyguide.html#383-functions-and-methods). Please refer to the style guide while writing docstrings for your contribution. -Every docstring should include a usage example. When the example only uses -`supervision`, NumPy, and the standard library — no optional extras, no external files -or network access — strongly prefer `>>>` doctest format so it is automatically -verified by the test suite. See [Doctests](#doctests) below for syntax guidance and for -when fenced ```` ```python ```` blocks are appropriate instead. +Every docstring should include a usage example. When the example only uses `supervision`, NumPy, and the standard library — no optional extras, no external files or network access — strongly prefer `>>>` doctest format so it is automatically verified by the test suite. See [Doctests](#doctests) below for syntax guidance and for when fenced ```` ```python ```` blocks are appropriate instead. ### Type checking @@ -304,9 +270,7 @@ You can learn more about mkdocs on the [mkdocs website](https://www.mkdocs.org/) ## 🧑‍🍳 Cookbooks -We are always looking for new examples and cookbooks to add to the `supervision` -documentation. If you have a use case that you think would be helpful to others, please -submit a PR with your example. Here are some guidelines for submitting a new example: +We are always looking for new examples and cookbooks to add to the `supervision` documentation. If you have a use case that you think would be helpful to others, please submit a PR with your example. Here are some guidelines for submitting a new example: - Create a new notebook in the [`docs/notebooks`](https://github.com/roboflow/supervision/tree/develop/docs/notebooks) folder. - Add a link to the new notebook in [`docs/theme/cookbooks.html`](https://github.com/roboflow/supervision/blob/develop/docs/theme/cookbooks.html). Make sure to add the path to the new notebook, as well as a title, labels, author and supervision version. @@ -334,11 +298,9 @@ uv run pytest --cov=supervision ### Test Structure -Follow **Arrange-Act-Assert (AAA)**: one setup block, one action, one assertion group per -test. Never put two independent actions in the same test. +Follow **Arrange-Act-Assert (AAA)**: one setup block, one action, one assertion group per test. Never put two independent actions in the same test. -**Class grouping:** Group related tests into a class. The class name carries the unit -under test; method names describe the expected outcome only — not the mechanism. +**Class grouping:** Group related tests into a class. The class name carries the unit under test; method names describe the expected outcome only — not the mechanism. ```python class TestDetectionsWithNms: @@ -347,10 +309,7 @@ class TestDetectionsWithNms: def test_raises_when_confidence_missing(self): ... ``` -**Parametrize aggressively:** Three or more structurally identical tests should become a -single `@pytest.mark.parametrize` case. Use `pytest.param(..., id="slug")` per case — -not `ids=[...]` on the decorator — so the ID stays co-located with its arguments and -survives reordering. +**Parametrize aggressively:** Three or more structurally identical tests should become a single `@pytest.mark.parametrize` case. Use `pytest.param(..., id="slug")` per case — not `ids=[...]` on the decorator — so the ID stays co-located with its arguments and survives reordering. ```python @pytest.mark.parametrize( @@ -367,23 +326,13 @@ def test_overlap_metric_determines_suppression( ... ``` -**Docstrings:** Every test function/method requires at minimum a one-line docstring -(within the project line length configured in `pyproject.toml`). Describe the scenario, -not the implementation. +**Docstrings:** Every test function/method requires at minimum a one-line docstring (within the project line length configured in `pyproject.toml`). Describe the scenario, not the implementation. ### Doctests -**Guidance:** when an example uses only `supervision`, NumPy, and the standard library -— no optional extras (e.g. no `--extra metrics` packages), no external files, no -network, no devices — prefer `>>>` doctest format so it is automatically verified by -the test suite. Fenced ```` ```python ```` blocks are appropriate when the example -cannot reasonably be executed (e.g. loading a third-party model, reading a video file) -or when the primary purpose is demonstrating error/exception behaviour rather than -return values. +**Guidance:** when an example uses only `supervision`, NumPy, and the standard library — no optional extras (e.g. no `--extra metrics` packages), no external files, no network, no devices — prefer `>>>` doctest format so it is automatically verified by the test suite. Fenced ```` ```python ```` blocks are appropriate when the example cannot reasonably be executed (e.g. loading a third-party model, reading a video file) or when the primary purpose is demonstrating error/exception behaviour rather than return values. -Doctests run automatically as part of the test suite via `--doctest-modules` in -`pyproject.toml`. The `ELLIPSIS` and `NORMALIZE_WHITESPACE` flags are enabled globally, -so `...` matches any output fragment and minor whitespace differences are ignored. +Doctests run automatically as part of the test suite via `--doctest-modules` in `pyproject.toml`. The `ELLIPSIS` and `NORMALIZE_WHITESPACE` flags are enabled globally, so `...` matches any output fragment and minor whitespace differences are ignored. ```bash uv run pytest --doctest-modules src/ @@ -391,9 +340,7 @@ uv run pytest --doctest-modules src/ **Writing a doctest** -Use the `Example:` section of a Google-style docstring. Prefix each input line with -`>>>` and each continuation line with `...`. Place expected output immediately after -the last input line with no blank line between them. +Use the `Example:` section of a Google-style docstring. Prefix each input line with `>>>` and each continuation line with `...`. Place expected output immediately after the last input line with no blank line between them. ```python def clip_boxes(xyxy: np.ndarray, resolution_wh: tuple) -> np.ndarray: @@ -417,16 +364,12 @@ def clip_boxes(xyxy: np.ndarray, resolution_wh: tuple) -> np.ndarray: ### Key rules -- **Single-line expression** — write the repr as expected output: - `>>> len(result)` → `1` -- **Multi-line statement** — use `...` continuation: - `>>> arr = np.array([` / `... [1, 2],` / `... ])` +- **Single-line expression** — write the repr as expected output: `>>> len(result)` → `1` +- **Multi-line statement** — use `...` continuation: `>>> arr = np.array([` / `... [1, 2],` / `... ])` - **Print output** — write the printed string as expected output (no quotes). - **`None` return** — no output line needed (suppress with assignment or `_ =`). - **Large/variable arrays** — use `ELLIPSIS`: `array([...])` matches any content. -- **`# doctest: +SKIP`** — use only as a last resort for genuinely non-runnable lines - (e.g. a GPU-only call inside an otherwise runnable example). Prefer splitting the - example into two blocks instead. +- **`# doctest: +SKIP`** — use only as a last resort for genuinely non-runnable lines (e.g. a GPU-only call inside an otherwise runnable example). Prefer splitting the example into two blocks instead. Fenced ```` ```python ```` blocks remain appropriate for: diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 8e24765e..4002566e 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -141,6 +141,6 @@ Quick checklist: ## 🎯 Context-Aware Behavior -**For general development tasks**: Follow [AGENTS.md](../AGENTS.md) -**For pull request reviews**: Follow [PR Review Guidelines](CONTRIBUTING.md#pr-review-guidelines) -**For detailed processes**: Consult [CONTRIBUTING.md](CONTRIBUTING.md) +- **For general development tasks**: Follow [AGENTS.md](../AGENTS.md) +- **For pull request reviews**: Follow [PR Review Guidelines](CONTRIBUTING.md#pr-review-guidelines) +- **For detailed processes**: Consult [CONTRIBUTING.md](CONTRIBUTING.md) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 90d8478d..1be81e2b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -61,7 +61,7 @@ repos: additional_dependencies: - "mdformat-mkdocs[recommended]>=2.1.0" - "mdformat-ruff" - args: ["--number"] + args: ["--number", "--wrap=no"] exclude: ^(docs/changelog\.md|docs/deprecated\.md)$ - repo: https://github.com/pre-commit/mirrors-mypy diff --git a/AGENTS.md b/AGENTS.md index 48fe0851..4b6ef7f7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,10 +1,8 @@ # Agent Guidelines for `supervision` -These instructions define how AI agents (GitHub Copilot, Claude, etc.) should behave when -assigned an issue, task, or multi-step problem in this repository. +These instructions define how AI agents (GitHub Copilot, Claude, etc.) should behave when assigned an issue, task, or multi-step problem in this repository. -Behave like a senior contributor: precise, efficient, aligned with the project's -philosophy, and focused on maintainability and clarity. +Behave like a senior contributor: precise, efficient, aligned with the project's philosophy, and focused on maintainability and clarity. --- @@ -20,8 +18,7 @@ philosophy, and focused on maintainability and clarity. ## 2. Repository Conventions -All work must follow the conventions of the `supervision` library -(see [CONTRIBUTING.md](.github/CONTRIBUTING.md) for full details). +All work must follow the conventions of the `supervision` library (see [CONTRIBUTING.md](.github/CONTRIBUTING.md) for full details). ### Branching & Commits @@ -31,21 +28,13 @@ All work must follow the conventions of the `supervision` library ### Code Style -- **Heading depth in docs/docstrings**: `###` maximum. `####` and deeper render - identically to bold in mkdocs — use `**bold**` instead. +- **Heading depth in docs/docstrings**: `###` maximum. `####` and deeper render identically to bold in mkdocs — use `**bold**` instead. -- **Formatting and linting** are enforced by **pre-commit**. - The hook chain typically includes: ruff-check, ruff-format, codespell, mdformat, - prettier, pyproject-fmt, and standard pre-commit-hooks (trailing whitespace, YAML, TOML, etc.). +- **Formatting and linting** are enforced by **pre-commit**. The hook chain typically includes: ruff-check, ruff-format, codespell, mdformat, prettier, pyproject-fmt, and standard pre-commit-hooks (trailing whitespace, YAML, TOML, etc.). -- **Type hints**: required on all new code. Type checking with mypy is encouraged but not - currently enforced systematically by pre-commit; see [.github/CONTRIBUTING.md](.github/CONTRIBUTING.md) - for the latest type-checking expectations. +- **Type hints**: required on all new code. Type checking with mypy is encouraged but not currently enforced systematically by pre-commit; see [.github/CONTRIBUTING.md](.github/CONTRIBUTING.md) for the latest type-checking expectations. -- **Docstrings**: Google Python docstring style. Required for all new functions and classes. - Every docstring should include a usage example. Prefer `>>>` doctest format when - the example only uses `supervision`, NumPy, and stdlib (no optional extras, no - external files or network). See §3a and CONTRIBUTING.md for syntax. +- **Docstrings**: Google Python docstring style. Required for all new functions and classes. Every docstring should include a usage example. Prefer `>>>` doctest format when the example only uses `supervision`, NumPy, and stdlib (no optional extras, no external files or network). See §3a and CONTRIBUTING.md for syntax. ### API Consistency @@ -76,17 +65,10 @@ All work must follow the conventions of the `supervision` library Full test guidelines are in [CONTRIBUTING.md](.github/CONTRIBUTING.md#tests). Key rules: - **AAA structure**: one arrange, one act, one assertion group per test. No second act. -- **Class grouping**: group related tests into a class. Class name = unit under test. - Method names describe the expected outcome only — not the mechanism. -- **Parametrize**: 3+ structurally identical tests → `@pytest.mark.parametrize`. - Use `pytest.param(..., id="slug")` per case (not `ids=[...]` on the decorator). -- **Docstrings**: every test function/method needs at minimum a one-line docstring - within the project line length (see `pyproject.toml`). Describe the scenario, not the implementation. -- **Doctests**: prefer `>>>` doctest when example uses only `supervision`, NumPy, and - stdlib (no optional extras, no external files). Fenced ```` ```python ```` is fine - when non-runnable (third-party model, video file, optional extra) or when the - example's purpose is showing exception/error behaviour. See CONTRIBUTING.md - §Doctests for syntax guide (continuation lines, ELLIPSIS, `+SKIP` rules). +- **Class grouping**: group related tests into a class. Class name = unit under test. Method names describe the expected outcome only — not the mechanism. +- **Parametrize**: 3+ structurally identical tests → `@pytest.mark.parametrize`. Use `pytest.param(..., id="slug")` per case (not `ids=[...]` on the decorator). +- **Docstrings**: every test function/method needs at minimum a one-line docstring within the project line length (see `pyproject.toml`). Describe the scenario, not the implementation. +- **Doctests**: prefer `>>>` doctest when example uses only `supervision`, NumPy, and stdlib (no optional extras, no external files). Fenced ```` ```python ```` is fine when non-runnable (third-party model, video file, optional extra) or when the example's purpose is showing exception/error behaviour. See CONTRIBUTING.md §Doctests for syntax guide (continuation lines, ELLIPSIS, `+SKIP` rules). --- @@ -118,6 +100,5 @@ uv run pre-commit run --all-files ``` - All pre-commit hooks must pass (formatting, linting, type checking, spell check, etc.). -- All tests must pass before opening a PR. Note: some existing tests in the repo may - already be failing — your changes must not introduce new failures. +- All tests must pass before opening a PR. Note: some existing tests in the repo may already be failing — your changes must not introduce new failures. - Fix any issues reported and re-run until clean. diff --git a/LICENSE.md b/LICENSE.md index 25b9b89b..ab7110e8 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -2,20 +2,8 @@ MIT License Copyright (c) 2022 Roboflow -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 3f35d27c..7a9d6a32 100644 --- a/README.md +++ b/README.md @@ -14,16 +14,9 @@
-[![version](https://badge.fury.io/py/supervision.svg)](https://badge.fury.io/py/supervision) -[![downloads](https://img.shields.io/pypi/dm/supervision)](https://pypistats.org/packages/supervision) -[![license](https://img.shields.io/pypi/l/supervision)](LICENSE.md) -[![python-version](https://img.shields.io/pypi/pyversions/supervision)](https://badge.fury.io/py/supervision) -[![codecov](https://codecov.io/gh/roboflow/supervision/graph/badge.svg?token=HMNJ5FVZ36)](https://codecov.io/gh/roboflow/supervision) +[![version](https://badge.fury.io/py/supervision.svg)](https://badge.fury.io/py/supervision) [![downloads](https://img.shields.io/pypi/dm/supervision)](https://pypistats.org/packages/supervision) [![license](https://img.shields.io/pypi/l/supervision)](LICENSE.md) [![python-version](https://img.shields.io/pypi/pyversions/supervision)](https://badge.fury.io/py/supervision) [![codecov](https://codecov.io/gh/roboflow/supervision/graph/badge.svg?token=HMNJ5FVZ36)](https://codecov.io/gh/roboflow/supervision) -[![snyk](https://snyk.io/advisor/python/supervision/badge.svg)](https://snyk.io/advisor/python/supervision) -[![colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/roboflow/supervision/blob/main/demo.ipynb) -[![gradio](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/Roboflow/Annotators) -[![discord](https://img.shields.io/discord/1159501506232451173?logo=discord&label=discord&labelColor=fff&color=5865f2&link=https%3A%2F%2Fdiscord.gg%2FGbfgXGJ8Bk)](https://discord.gg/GbfgXGJ8Bk) +[![snyk](https://snyk.io/advisor/python/supervision/badge.svg)](https://snyk.io/advisor/python/supervision) [![colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/roboflow/supervision/blob/main/demo.ipynb) [![gradio](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/Roboflow/Annotators) [![discord](https://img.shields.io/discord/1159501506232451173?logo=discord&label=discord&labelColor=fff&color=5865f2&link=https%3A%2F%2Fdiscord.gg%2FGbfgXGJ8Bk)](https://discord.gg/GbfgXGJ8Bk)
roboflow%2Fsupervision | Trendshift @@ -37,8 +30,7 @@ ## 💻 install -Pip install the supervision package in a -[**Python>=3.9**](https://www.python.org/) environment. +Pip install the supervision package in a [**Python>=3.9**](https://www.python.org/) environment. ```bash pip install supervision diff --git a/docs/assets.md b/docs/assets.md index 691ba7e4..dff01147 100644 --- a/docs/assets.md +++ b/docs/assets.md @@ -5,8 +5,7 @@ description: API reference for supervision's assets module — download sample v # Assets -Supervision offers an assets download utility that allows you to download image and video files -that you can use in your demos. +Supervision offers an assets download utility that allows you to download image and video files that you can use in your demos.

download_assets

diff --git a/docs/datasets/core.md b/docs/datasets/core.md index 98013280..f98712c9 100644 --- a/docs/datasets/core.md +++ b/docs/datasets/core.md @@ -7,8 +7,7 @@ description: API reference for supervision's DetectionDataset and Classification !!! warning - Dataset API is still fluid and may change. If you use Dataset API in your project until further notice, freeze the - `supervision` version in your `requirements.txt` or `setup.py`. + Dataset API is still fluid and may change. If you use Dataset API in your project until further notice, freeze the `supervision` version in your `requirements.txt` or `setup.py`.

DetectionDataset

diff --git a/docs/detection/annotators.md b/docs/detection/annotators.md index 60ba3ded..91a6e276 100644 --- a/docs/detection/annotators.md +++ b/docs/detection/annotators.md @@ -196,13 +196,7 @@ Annotators accept detections and apply box or mask visualizations to the detecti !!! note - `MaskAnnotator` expects `detections.mask` to contain instance segmentation - masks aligned to the image passed to `annotate`. For dense masks, provide a - boolean array of shape `(N, H, W)` where `(H, W)` matches the image height - and width (it also accepts `sv.CompactMask`). If your model returns - framework-specific results, convert them to `sv.Detections` first, for - example with `sv.Detections.from_ultralytics(...)` or - `sv.Detections.from_inference(...)`. + `MaskAnnotator` expects `detections.mask` to contain instance segmentation masks aligned to the image passed to `annotate`. For dense masks, provide a boolean array of shape `(N, H, W)` where `(H, W)` matches the image height and width (it also accepts `sv.CompactMask`). If your model returns framework-specific results, convert them to `sv.Detections` first, for example with `sv.Detections.from_ultralytics(...)` or `sv.Detections.from_inference(...)`.
diff --git a/docs/detection/metrics.md b/docs/detection/metrics.md index f0152fac..4d67bf91 100644 --- a/docs/detection/metrics.md +++ b/docs/detection/metrics.md @@ -4,8 +4,7 @@ comments: true # Legacy Metrics -Starting with `0.23.0`, a new metrics module is being introduced to supervision. -Metrics here are part of the legacy evaluation API and will be deprecated in the future. +Starting with `0.23.0`, a new metrics module is being introduced to supervision. Metrics here are part of the legacy evaluation API and will be deprecated in the future.

ConfusionMatrix

diff --git a/docs/how_to/benchmark_a_model.md b/docs/how_to/benchmark_a_model.md index 0185dc19..e2485a68 100644 --- a/docs/how_to/benchmark_a_model.md +++ b/docs/how_to/benchmark_a_model.md @@ -130,8 +130,7 @@ Evaluating your model requires careful selection of the dataset. Which images sh - **Validation Set**: This is the set of images used to validate the model during training. Every Nth training epoch, the model is evaluated on the validation set. Often the training is stopped once the validation loss stops improving. Therefore, even while the images aren't used to train the model, it still indirectly influences the training outcome. - **Test Set**: This is the set of images kept aside for model testing. It is exactly the set you should use for benchmarking. If the dataset was split correctly, none of these images would be shown to the model during training. -Therefore, an unrelated dataset or the `test` set is the best choice for benchmarking. -Several other problems may arise: +Therefore, an unrelated dataset or the `test` set is the best choice for benchmarking. Several other problems may arise: - **Extra Classes**: An unrelated dataset may contain additional classes which you may need to [filter out](https://supervision.roboflow.com/how_to/filter_detections/#by-set-of-classes) before computing metrics. - **Class Mismatch**: In an unrelated dataset, the class names or IDs may be different to what your model produces, you'll need to remap them, which is [shown in this guide](#running-a-model). @@ -145,8 +144,7 @@ At this stage, you should have: - A dataset of labeled images to evaluate the model. - A model prepared for benchmarking. -With these ready, we can now run the model and obtain predictions. -We'll use `supervision` to create a dataset iterator, and then run the model on each image. +With these ready, we can now run the model and obtain predictions. We'll use `supervision` to create a dataset iterator, and then run the model on each image. === "Inference" @@ -198,8 +196,7 @@ We'll use `supervision` to create a dataset iterator, and then run the model on ## Remapping classes -Did you notice an issue in the above logic? -Since we're using an unrelated dataset, the class names and IDs may be different from what the model was trained on. +Did you notice an issue in the above logic? Since we're using an unrelated dataset, the class names and IDs may be different from what the model was trained on. We need to remap them to match the dataset classes. Here's how to do it: @@ -259,8 +256,7 @@ Let's also remove the predictions that are not in the dataset classes. Dataset class names and IDs can be found in the `data.yaml` file, or by printing `dataset.classes`. - Each model will have a different class mapping, so make sure to check the model's documentation. In this case, the model was trained on the COCO dataset, with a class - configuration found [here](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/cfg/datasets/coco8.yaml). + Each model will have a different class mapping, so make sure to check the model's documentation. In this case, the model was trained on the COCO dataset, with a class configuration found [here](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/cfg/datasets/coco8.yaml). ```python import supervision as sv @@ -293,8 +289,7 @@ Let's also remove the predictions that are not in the dataset classes. ## Visualizing Predictions -The first step in evaluating your model’s performance is to visualize its predictions. -This gives an intuitive sense of how well your model is detecting objects and where it might be failing. +The first step in evaluating your model’s performance is to visualize its predictions. This gives an intuitive sense of how well your model is detecting objects and where it might be failing. ```python import supervision as sv diff --git a/docs/how_to/detect_and_annotate.md b/docs/how_to/detect_and_annotate.md index 3c0163e1..9cbc3ac4 100644 --- a/docs/how_to/detect_and_annotate.md +++ b/docs/how_to/detect_and_annotate.md @@ -25,20 +25,13 @@ date_modified: 2026-04-22 Then replace `` with `"dog.jpeg"`. ``` -Supervision provides a seamless process for annotating predictions generated by various -object detection and segmentation models. This guide shows how to perform inference -with the [Inference](https://github.com/roboflow/inference), -[Ultralytics](https://github.com/ultralytics/ultralytics) or -[Transformers](https://github.com/huggingface/transformers) packages. Following this, -you'll learn how to import these predictions into Supervision and use them to annotate -source image. +Supervision provides a seamless process for annotating predictions generated by various object detection and segmentation models. This guide shows how to perform inference with the [Inference](https://github.com/roboflow/inference), [Ultralytics](https://github.com/ultralytics/ultralytics) or [Transformers](https://github.com/huggingface/transformers) packages. Following this, you'll learn how to import these predictions into Supervision and use them to annotate source image. ![basic-annotation](https://media.roboflow.com/supervision_detect_and_annotate_example_1.png) ## Run Detection -First, you'll need to obtain predictions from your object detection or segmentation -model. +First, you'll need to obtain predictions from your object detection or segmentation model. To run inference, initialize your chosen model and pass the source image to its predict or infer method. Supervision supports Roboflow Inference, Ultralytics YOLO, and Hugging Face Transformers -- select the tab matching your framework. The result is a framework-specific object you will convert to a `Detections` instance in the next step. @@ -245,9 +238,7 @@ To draw bounding boxes and class labels on your image, create a `BoxAnnotator` a ## Display Custom Labels -By default, [`sv.LabelAnnotator`](https://supervision.roboflow.com/latest/detection/annotators/#supervision.annotators.core.LabelAnnotator) -will label each detection with its `class_name` (if possible) or `class_id`. You can -override this behavior by passing a list of custom `labels` to the `annotate` method. +By default, [`sv.LabelAnnotator`](https://supervision.roboflow.com/latest/detection/annotators/#supervision.annotators.core.LabelAnnotator) will label each detection with its `class_name` (if possible) or `class_id`. You can override this behavior by passing a list of custom `labels` to the `annotate` method. === "Inference" @@ -347,11 +338,7 @@ override this behavior by passing a list of custom `labels` to the `annotate` me ## Annotate Image with Segmentations -If you are running the segmentation model -[`sv.MaskAnnotator`](https://supervision.roboflow.com/latest/detection/annotators/#supervision.annotators.core.MaskAnnotator) -is a drop-in replacement for -[`sv.BoxAnnotator`](https://supervision.roboflow.com/latest/detection/annotators/#supervision.annotators.core.BoxAnnotator) -that will allow you to draw masks instead of boxes. +If you are running the segmentation model [`sv.MaskAnnotator`](https://supervision.roboflow.com/latest/detection/annotators/#supervision.annotators.core.MaskAnnotator) is a drop-in replacement for [`sv.BoxAnnotator`](https://supervision.roboflow.com/latest/detection/annotators/#supervision.annotators.core.BoxAnnotator) that will allow you to draw masks instead of boxes. === "Inference" diff --git a/docs/how_to/detect_small_objects.md b/docs/how_to/detect_small_objects.md index edc15b5d..237dff31 100644 --- a/docs/how_to/detect_small_objects.md +++ b/docs/how_to/detect_small_objects.md @@ -10,11 +10,7 @@ date_modified: 2026-04-22 # Detect Small Objects -This guide shows how to detect small objects -with the [Inference](https://github.com/roboflow/inference), -[Ultralytics](https://github.com/ultralytics/ultralytics) or -[Transformers](https://github.com/huggingface/transformers) packages using -[`InferenceSlicer`](https://supervision.roboflow.com/latest/detection/tools/inference_slicer/#supervision.detection.tools.inference_slicer.InferenceSlicer). +This guide shows how to detect small objects with the [Inference](https://github.com/roboflow/inference), [Ultralytics](https://github.com/ultralytics/ultralytics) or [Transformers](https://github.com/huggingface/transformers) packages using [`InferenceSlicer`](https://supervision.roboflow.com/latest/detection/tools/inference_slicer/#supervision.detection.tools.inference_slicer.InferenceSlicer).