From e1ffd0e8a970a40d4d1ea5ab2e6ab7404a84763b Mon Sep 17 00:00:00 2001 From: LinasKo Date: Wed, 14 Aug 2024 15:38:50 +0300 Subject: [PATCH] Address some review comments --- mkdocs.yml | 92 +++++++++---------- supervision/metrics/core.py | 10 +- .../metrics/intersection_over_union.py | 15 ++- 3 files changed, 54 insertions(+), 63 deletions(-) diff --git a/mkdocs.yml b/mkdocs.yml index d20dbb23..9af0d516 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -33,7 +33,6 @@ extra_css: - stylesheets/extra.css - stylesheets/cookbooks-card.css - nav: - Supervision: index.md - Learn: @@ -45,50 +44,50 @@ nav: - Process Datasets: how_to/process_datasets.md - Reference - Code API: - - Detection and Segmentation: - - Core: detection/core.md - - Annotators: detection/annotators.md - - Metrics: detection/metrics.md - - Double Detection Filter: detection/double_detection_filter.md - - Utils: detection/utils.md - - Keypoint Detection: - - Core: keypoint/core.md - - Annotators: keypoint/annotators.md - - Classification: - - Core: classification/core.md - - Tools: - - Line Zone: detection/tools/line_zone.md - - Polygon Zone: detection/tools/polygon_zone.md - - Inference Slicer: detection/tools/inference_slicer.md - - Detection Smoother: detection/tools/smoother.md - - Save Detections: detection/tools/save_detections.md - - Trackers: trackers.md - - Datasets: - - Core: datasets/core.md - - Utils: datasets/utils.md - - Utils: - - Video: utils/video.md - - Image: utils/image.md - - Iterables: utils/iterables.md - - Notebook: utils/notebook.md - - File: utils/file.md - - Draw: utils/draw.md - - Geometry: utils/geometry.md - - Assets: assets.md + - Detection and Segmentation: + - Core: detection/core.md + - Annotators: detection/annotators.md + - Metrics: detection/metrics.md + - Double Detection Filter: detection/double_detection_filter.md + - Utils: detection/utils.md + - Keypoint Detection: + - Core: keypoint/core.md + - Annotators: keypoint/annotators.md + - Classification: + - Core: classification/core.md + - Tools: + - Line Zone: detection/tools/line_zone.md + - Polygon Zone: detection/tools/polygon_zone.md + - Inference Slicer: detection/tools/inference_slicer.md + - Detection Smoother: detection/tools/smoother.md + - Save Detections: detection/tools/save_detections.md + - Trackers: trackers.md + - Datasets: + - Core: datasets/core.md + - Utils: datasets/utils.md + - Metrics: + - IoU: metrics/intersection_over_union.md + - Utils: + - Video: utils/video.md + - Image: utils/image.md + - Iterables: utils/iterables.md + - Notebook: utils/notebook.md + - File: utils/file.md + - Draw: utils/draw.md + - Geometry: utils/geometry.md + - Assets: assets.md - Cookbooks: cookbooks.md - Cheatsheet: https://roboflow.github.io/cheatsheet-supervision/ - Contribute: - - Contributing: contributing.md - - Code of Conduct: code_of_conduct.md - - License: license.md + - Contributing: contributing.md + - Code of Conduct: code_of_conduct.md + - License: license.md - Release Notes: - - Changelog: changelog.md - - Deprecated: deprecated.md - - + - Changelog: changelog.md + - Deprecated: deprecated.md theme: - name: 'material' + name: "material" icon: edit: material/pencil logo: assets/supervision-lenny.png @@ -105,19 +104,18 @@ theme: palette: # Palette for light mode - scheme: default - primary: 'custom' + primary: "custom" toggle: icon: material/brightness-7 name: Switch to dark mode # Palette toggle for dark mode - scheme: slate - primary: 'custom' + primary: "custom" toggle: icon: material/brightness-4 name: Switch to light mode - font: text: Roboto code: Roboto Mono @@ -128,10 +126,10 @@ theme: plugins: - search - mkdocs-jupyter: - kernel_name: python3 - execute: false - include_source: True - include_requirejs: true + kernel_name: python3 + execute: false + include_source: True + include_requirejs: true - mkdocstrings: default_handler: python handlers: @@ -155,8 +153,6 @@ plugins: - git-revision-date-localized: enable_creation_date: true - - markdown_extensions: - admonition - pymdownx.details diff --git a/supervision/metrics/core.py b/supervision/metrics/core.py index 33024d28..e747766a 100644 --- a/supervision/metrics/core.py +++ b/supervision/metrics/core.py @@ -6,6 +6,7 @@ from typing import Any, Dict, Iterator, Optional, Tuple, Union import numpy as np import numpy.typing as npt +from typing_extensions import Self from supervision import config from supervision.detection.core import Detections @@ -20,15 +21,10 @@ class Metric(ABC): """ @abstractmethod - def update(self, *args, **kwargs) -> Metric: + def update(self, *args, **kwargs) -> Self: """ Add data to the metric, without computing the result. - Return the metric itself to allow method chaining, for example: - - Example: - ```python - result = metric.update(data).compute() - ``` + Return the metric itself to allow method chaining. """ raise NotImplementedError diff --git a/supervision/metrics/intersection_over_union.py b/supervision/metrics/intersection_over_union.py index 22b8b56d..2ae512e2 100644 --- a/supervision/metrics/intersection_over_union.py +++ b/supervision/metrics/intersection_over_union.py @@ -1,14 +1,12 @@ -from typing import TYPE_CHECKING, Dict, Union +from typing import Dict, Union import numpy as np import numpy.typing as npt +from typing_extensions import Self from supervision.detection.core import Detections from supervision.metrics.core import InternalMetricDataStore, Metric, MetricTarget -if TYPE_CHECKING: - pass - class IntersectionOverUnion(Metric): def __init__( @@ -36,14 +34,15 @@ class IntersectionOverUnion(Metric): self, data_1: Union[npt.NDArray, Detections], data_2: Union[npt.NDArray, Detections], - ) -> Metric: + ) -> Self: """ Add data to the metric, without computing the result. The arguments can be: - * Boxes of shape (N, 4), float32, - * Masks of shape (N, H, W), bool - * Oriented bounding boxes of shape (N, 8), float32. + + * Boxes of shape `(N, 4)`, `float32`, + * Masks of shape `(N, H, W)`, `bool` + * Oriented bounding boxes of shape `(N, 8)`, `float32`. * Detections object. Args: