From 04629cd7f4ce996275cc46e2af2a4cf3c2a9bbda Mon Sep 17 00:00:00 2001 From: Hardik Dava Date: Fri, 11 Aug 2023 14:07:14 +0200 Subject: [PATCH 1/5] initial commit --- supervision/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/supervision/__init__.py b/supervision/__init__.py index edb9675d..e918ecee 100644 --- a/supervision/__init__.py +++ b/supervision/__init__.py @@ -34,6 +34,7 @@ from supervision.metrics.detection import ConfusionMatrix, MeanAveragePrecision from supervision.utils.file import list_files_with_extensions from supervision.utils.image import ImageSink, crop from supervision.utils.notebook import plot_image, plot_images_grid +from supervision.utils.fps import FpsMonitor from supervision.utils.video import ( VideoInfo, VideoSink, From c746a7f9e403e9c7e77e7bb5ba09058d775812fd Mon Sep 17 00:00:00 2001 From: Hardik Dava Date: Fri, 11 Aug 2023 14:08:52 +0200 Subject: [PATCH 2/5] docs added --- docs/utils/fps.md | 3 +++ mkdocs.yml | 1 + supervision/utils/fps.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 docs/utils/fps.md create mode 100644 supervision/utils/fps.py diff --git a/docs/utils/fps.md b/docs/utils/fps.md new file mode 100644 index 00000000..4732ce62 --- /dev/null +++ b/docs/utils/fps.md @@ -0,0 +1,3 @@ +## list_files_with_extensions + +:::supervision.utils.fps.FpsMonitor diff --git a/mkdocs.yml b/mkdocs.yml index dd41adc9..94a36abb 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -48,6 +48,7 @@ nav: - Image: utils/image.md - Notebook: utils/notebook.md - File: utils/file.md + - FPS: utils/fps.md - Changelog: changelog.md theme: diff --git a/supervision/utils/fps.py b/supervision/utils/fps.py new file mode 100644 index 00000000..648367bb --- /dev/null +++ b/supervision/utils/fps.py @@ -0,0 +1,34 @@ +import time +from collections import deque + + +class FpsMonitor: + def __init__(self, sample_size: int = 30): + """ + Initialize class to measure Frame per second for latency benchmark. + Args: + sample_size (int): Maximum observation to measure latency benchmark + Examples: + ```python + >>> import supervision as sv + + >>> fps_monitor = sv.FpsMonitor() + >>> while True: + ... (...) + ... fps_monitor.tick() + ... fps = fps_monitor() + ``` + """ + self.all_timestamps = deque(maxlen=sample_size) + + def __call__(self) -> float: + if not self.all_timestamps: + return 0.0 + taken_time = self.all_timestamps[-1] - self.all_timestamps[0] + return (len(self.all_timestamps)) / taken_time if taken_time != 0 else 0.0 + + def tick(self) -> None: + self.all_timestamps.append(time.monotonic()) + + def reset(self) -> None: + self.all_timestamps.clear() \ No newline at end of file From 3f7043e780e7ec27cf132a887f7101728970b04b Mon Sep 17 00:00:00 2001 From: Hardik Dava Date: Fri, 11 Aug 2023 14:13:17 +0200 Subject: [PATCH 3/5] Make with Black --- supervision/utils/fps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supervision/utils/fps.py b/supervision/utils/fps.py index 648367bb..90a458f7 100644 --- a/supervision/utils/fps.py +++ b/supervision/utils/fps.py @@ -31,4 +31,4 @@ class FpsMonitor: self.all_timestamps.append(time.monotonic()) def reset(self) -> None: - self.all_timestamps.clear() \ No newline at end of file + self.all_timestamps.clear() From 5c9e529743b719deba895a88838d33f9820d5e43 Mon Sep 17 00:00:00 2001 From: Hardik Dava Date: Fri, 11 Aug 2023 14:15:47 +0200 Subject: [PATCH 4/5] Make with isort --- supervision/__init__.py | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/supervision/__init__.py b/supervision/__init__.py index e918ecee..c1c995ee 100644 --- a/supervision/__init__.py +++ b/supervision/__init__.py @@ -8,36 +8,27 @@ except importlib_metadata.PackageNotFoundError: from supervision.classification.core import Classifications -from supervision.dataset.core import ( - BaseDataset, - ClassificationDataset, - DetectionDataset, -) +from supervision.dataset.core import (BaseDataset, ClassificationDataset, + DetectionDataset) from supervision.detection.annotate import BoxAnnotator, MaskAnnotator from supervision.detection.core import Detections from supervision.detection.line_counter import LineZone, LineZoneAnnotator -from supervision.detection.tools.polygon_zone import PolygonZone, PolygonZoneAnnotator -from supervision.detection.utils import ( - box_iou_batch, - filter_polygons_by_area, - mask_to_polygons, - mask_to_xyxy, - non_max_suppression, - polygon_to_mask, - polygon_to_xyxy, -) +from supervision.detection.tools.polygon_zone import (PolygonZone, + PolygonZoneAnnotator) +from supervision.detection.utils import (box_iou_batch, + filter_polygons_by_area, + mask_to_polygons, mask_to_xyxy, + non_max_suppression, polygon_to_mask, + polygon_to_xyxy) from supervision.draw.color import Color, ColorPalette -from supervision.draw.utils import draw_filled_rectangle, draw_polygon, draw_text +from supervision.draw.utils import (draw_filled_rectangle, draw_polygon, + draw_text) from supervision.geometry.core import Point, Position, Rect from supervision.geometry.utils import get_polygon_center from supervision.metrics.detection import ConfusionMatrix, MeanAveragePrecision from supervision.utils.file import list_files_with_extensions +from supervision.utils.fps import FpsMonitor from supervision.utils.image import ImageSink, crop from supervision.utils.notebook import plot_image, plot_images_grid -from supervision.utils.fps import FpsMonitor -from supervision.utils.video import ( - VideoInfo, - VideoSink, - get_video_frames_generator, - process_video, -) +from supervision.utils.video import (VideoInfo, VideoSink, + get_video_frames_generator, process_video) From 5d71ab296113c7e3c5c87363ea756f7982644423 Mon Sep 17 00:00:00 2001 From: Hardik Dava Date: Fri, 11 Aug 2023 14:18:25 +0200 Subject: [PATCH 5/5] Make with black again --- supervision/__init__.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/supervision/__init__.py b/supervision/__init__.py index c1c995ee..757ed136 100644 --- a/supervision/__init__.py +++ b/supervision/__init__.py @@ -8,21 +8,26 @@ except importlib_metadata.PackageNotFoundError: from supervision.classification.core import Classifications -from supervision.dataset.core import (BaseDataset, ClassificationDataset, - DetectionDataset) +from supervision.dataset.core import ( + BaseDataset, + ClassificationDataset, + DetectionDataset, +) from supervision.detection.annotate import BoxAnnotator, MaskAnnotator from supervision.detection.core import Detections from supervision.detection.line_counter import LineZone, LineZoneAnnotator -from supervision.detection.tools.polygon_zone import (PolygonZone, - PolygonZoneAnnotator) -from supervision.detection.utils import (box_iou_batch, - filter_polygons_by_area, - mask_to_polygons, mask_to_xyxy, - non_max_suppression, polygon_to_mask, - polygon_to_xyxy) +from supervision.detection.tools.polygon_zone import PolygonZone, PolygonZoneAnnotator +from supervision.detection.utils import ( + box_iou_batch, + filter_polygons_by_area, + mask_to_polygons, + mask_to_xyxy, + non_max_suppression, + polygon_to_mask, + polygon_to_xyxy, +) from supervision.draw.color import Color, ColorPalette -from supervision.draw.utils import (draw_filled_rectangle, draw_polygon, - draw_text) +from supervision.draw.utils import draw_filled_rectangle, draw_polygon, draw_text from supervision.geometry.core import Point, Position, Rect from supervision.geometry.utils import get_polygon_center from supervision.metrics.detection import ConfusionMatrix, MeanAveragePrecision @@ -30,5 +35,9 @@ from supervision.utils.file import list_files_with_extensions from supervision.utils.fps import FpsMonitor from supervision.utils.image import ImageSink, crop from supervision.utils.notebook import plot_image, plot_images_grid -from supervision.utils.video import (VideoInfo, VideoSink, - get_video_frames_generator, process_video) +from supervision.utils.video import ( + VideoInfo, + VideoSink, + get_video_frames_generator, + process_video, +)