superiorvision 0.30.0.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. superiorvision/__init__.py +19 -0
  2. superiorvision-0.30.0.dev0.dist-info/METADATA +398 -0
  3. superiorvision-0.30.0.dev0.dist-info/RECORD +96 -0
  4. superiorvision-0.30.0.dev0.dist-info/WHEEL +5 -0
  5. superiorvision-0.30.0.dev0.dist-info/licenses/LICENSE.md +9 -0
  6. superiorvision-0.30.0.dev0.dist-info/top_level.txt +2 -0
  7. supervision/__init__.py +318 -0
  8. supervision/annotators/__init__.py +0 -0
  9. supervision/annotators/base.py +21 -0
  10. supervision/annotators/core.py +3551 -0
  11. supervision/annotators/utils.py +541 -0
  12. supervision/assets/__init__.py +4 -0
  13. supervision/assets/downloader.py +166 -0
  14. supervision/assets/list.py +84 -0
  15. supervision/classification/__init__.py +0 -0
  16. supervision/classification/core.py +216 -0
  17. supervision/config.py +13 -0
  18. supervision/dataset/__init__.py +0 -0
  19. supervision/dataset/core.py +1313 -0
  20. supervision/dataset/formats/__init__.py +0 -0
  21. supervision/dataset/formats/coco.py +708 -0
  22. supervision/dataset/formats/createml.py +331 -0
  23. supervision/dataset/formats/labelme.py +405 -0
  24. supervision/dataset/formats/pascal_voc.py +449 -0
  25. supervision/dataset/formats/yolo.py +502 -0
  26. supervision/dataset/utils.py +265 -0
  27. supervision/detection/__init__.py +0 -0
  28. supervision/detection/compact_mask.py +1927 -0
  29. supervision/detection/core.py +3864 -0
  30. supervision/detection/line_zone.py +924 -0
  31. supervision/detection/overlap_filter.py +426 -0
  32. supervision/detection/tensor_utils.py +1596 -0
  33. supervision/detection/tensor_views.py +48 -0
  34. supervision/detection/tools/__init__.py +0 -0
  35. supervision/detection/tools/csv_sink.py +242 -0
  36. supervision/detection/tools/inference_slicer.py +776 -0
  37. supervision/detection/tools/json_sink.py +215 -0
  38. supervision/detection/tools/polygon_zone.py +266 -0
  39. supervision/detection/tools/smoother.py +218 -0
  40. supervision/detection/tools/transformers.py +265 -0
  41. supervision/detection/utils/__init__.py +12 -0
  42. supervision/detection/utils/_typing.py +11 -0
  43. supervision/detection/utils/boxes.py +510 -0
  44. supervision/detection/utils/converters.py +830 -0
  45. supervision/detection/utils/internal.py +806 -0
  46. supervision/detection/utils/iou_and_nms.py +1606 -0
  47. supervision/detection/utils/masks.py +625 -0
  48. supervision/detection/utils/polygons.py +128 -0
  49. supervision/detection/utils/vlms.py +97 -0
  50. supervision/detection/vlm.py +945 -0
  51. supervision/draw/__init__.py +0 -0
  52. supervision/draw/base.py +14 -0
  53. supervision/draw/color.py +598 -0
  54. supervision/draw/utils.py +527 -0
  55. supervision/geometry/__init__.py +0 -0
  56. supervision/geometry/core.py +208 -0
  57. supervision/geometry/utils.py +54 -0
  58. supervision/key_points/__init__.py +0 -0
  59. supervision/key_points/annotators.py +997 -0
  60. supervision/key_points/core.py +1506 -0
  61. supervision/key_points/skeletons.py +2646 -0
  62. supervision/keypoint/__init__.py +13 -0
  63. supervision/keypoint/annotators.py +13 -0
  64. supervision/keypoint/core.py +8 -0
  65. supervision/metrics/__init__.py +40 -0
  66. supervision/metrics/core.py +74 -0
  67. supervision/metrics/detection.py +1632 -0
  68. supervision/metrics/f1_score.py +815 -0
  69. supervision/metrics/mean_average_precision.py +1723 -0
  70. supervision/metrics/mean_average_recall.py +734 -0
  71. supervision/metrics/precision.py +815 -0
  72. supervision/metrics/recall.py +774 -0
  73. supervision/metrics/utils/__init__.py +0 -0
  74. supervision/metrics/utils/matching.py +56 -0
  75. supervision/metrics/utils/object_size.py +256 -0
  76. supervision/metrics/utils/utils.py +9 -0
  77. supervision/py.typed +0 -0
  78. supervision/tracker/__init__.py +5 -0
  79. supervision/tracker/byte_tracker/__init__.py +0 -0
  80. supervision/tracker/byte_tracker/core.py +448 -0
  81. supervision/tracker/byte_tracker/kalman_filter.py +186 -0
  82. supervision/tracker/byte_tracker/matching.py +211 -0
  83. supervision/tracker/byte_tracker/single_object_track.py +194 -0
  84. supervision/tracker/byte_tracker/utils.py +34 -0
  85. supervision/utils/__init__.py +0 -0
  86. supervision/utils/conversion.py +223 -0
  87. supervision/utils/deprecate.py +54 -0
  88. supervision/utils/file.py +209 -0
  89. supervision/utils/image.py +988 -0
  90. supervision/utils/internal.py +209 -0
  91. supervision/utils/iterables.py +103 -0
  92. supervision/utils/logger.py +61 -0
  93. supervision/utils/notebook.py +124 -0
  94. supervision/utils/tensor.py +362 -0
  95. supervision/utils/video.py +533 -0
  96. supervision/validators/__init__.py +379 -0
@@ -0,0 +1,54 @@
1
+ """Compatibility facade for the pydeprecate versions used by Inference.
2
+
3
+ Supervision 0.30 uses ``TargetMode`` and ``deprecated_class``, while the
4
+ currently deployed Inference environment still carries the older decorator
5
+ API. Keeping the version adaptation here lets SuperiorVision remain a
6
+ drop-in package without weakening Inference's dependency lock.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from collections.abc import Callable
12
+ from enum import Enum
13
+ from typing import Any
14
+
15
+ from deprecate import deprecated as _deprecated
16
+ from deprecate import void
17
+
18
+ try:
19
+ from deprecate import TargetMode, deprecated_class
20
+ _HAS_NATIVE_TARGET_MODE = True
21
+ except ImportError:
22
+ _HAS_NATIVE_TARGET_MODE = False
23
+
24
+ class TargetMode(Enum):
25
+ """Old-pydeprecate equivalents for the newer target modes."""
26
+
27
+ NOTIFY = None
28
+ ARGS_REMAP = True
29
+
30
+ def deprecated_class(
31
+ target: Any = None,
32
+ **kwargs: Any,
33
+ ) -> Callable[[type], type]:
34
+ """Retain class identity when old pydeprecate lacks class proxies."""
35
+
36
+ del target, kwargs
37
+
38
+ def decorate(cls: type) -> type:
39
+ return cls
40
+
41
+ return decorate
42
+
43
+
44
+ def deprecated(
45
+ target: Any = TargetMode.NOTIFY,
46
+ **kwargs: Any,
47
+ ) -> Callable[[Callable[..., Any]], Callable[..., Any]]:
48
+ """Translate new target-mode values to either pydeprecate API."""
49
+ if not _HAS_NATIVE_TARGET_MODE and isinstance(target, TargetMode):
50
+ target = target.value
51
+ return _deprecated(target=target, **kwargs)
52
+
53
+
54
+ __all__ = ["TargetMode", "deprecated", "deprecated_class", "void"]
@@ -0,0 +1,209 @@
1
+ import json
2
+ from pathlib import Path
3
+ from typing import Any
4
+
5
+ import numpy as np
6
+ import yaml
7
+
8
+
9
+ class NumpyJsonEncoder(json.JSONEncoder):
10
+ def default(self, obj: Any) -> Any:
11
+ if isinstance(obj, np.integer):
12
+ return int(obj)
13
+ if isinstance(obj, np.floating):
14
+ return float(obj)
15
+ if isinstance(obj, np.ndarray):
16
+ return obj.tolist()
17
+ return super().default(obj)
18
+
19
+
20
+ def list_files_with_extensions(
21
+ directory: str | Path, extensions: list[str] | None = None
22
+ ) -> list[Path]:
23
+ """
24
+ List files in a directory with specified extensions or
25
+ all files if no extensions are provided.
26
+
27
+ Args:
28
+ directory: The directory path as a string or Path object.
29
+ extensions: A list of file extensions to filter. Extensions may be
30
+ supplied with or without a leading dot (e.g. ``'jpg'`` and
31
+ ``'.jpg'`` are equivalent). Matching is case-insensitive.
32
+ Multi-part extensions are supported (e.g. ``'tar.gz'``). Pass
33
+ ``None`` (default) to list all files; pass an empty list to
34
+ return no files.
35
+
36
+ Returns:
37
+ A list of Path objects for the matching files.
38
+
39
+ Examples:
40
+ ```pycon
41
+ >>> import supervision as sv
42
+ >>> from pathlib import Path
43
+ >>> import tempfile
44
+ >>> # Keep a reference to the directory object
45
+ >>> tmp_dir_obj = tempfile.TemporaryDirectory()
46
+ >>> tmpdir = tmp_dir_obj.name
47
+ >>> # Create test files
48
+ >>> (Path(tmpdir) / "test1.txt").touch()
49
+ >>> (Path(tmpdir) / "test2.md").touch()
50
+ >>> (Path(tmpdir) / "test3.py").touch()
51
+ >>> # List all files in the directory
52
+ >>> files = sv.list_files_with_extensions(directory=tmpdir)
53
+ >>> len(files)
54
+ 3
55
+ >>> # Leading dot accepted; matching is case-insensitive
56
+ >>> files = sv.list_files_with_extensions(
57
+ ... directory=tmpdir, extensions=['.txt', 'md'])
58
+ >>> len(files)
59
+ 2
60
+
61
+ ```
62
+ """
63
+
64
+ directory = Path(directory)
65
+ files_with_extensions: list[Path] = []
66
+
67
+ if extensions is not None:
68
+ candidates = [p for p in directory.glob("*") if p.is_file()]
69
+ path_index: dict[Path, set[str]] = {}
70
+ for path in candidates:
71
+ suffixes = [suffix.lower().lstrip(".") for suffix in path.suffixes]
72
+ path_index[path] = {
73
+ ".".join(suffixes[index:]) for index in range(len(suffixes))
74
+ }
75
+ seen_paths: set[Path] = set()
76
+ for ext in extensions:
77
+ normalized_extension = ext.lower().lstrip(".")
78
+ if not normalized_extension:
79
+ continue
80
+ for path, path_extensions in path_index.items():
81
+ if path not in seen_paths and normalized_extension in path_extensions:
82
+ files_with_extensions.append(path)
83
+ seen_paths.add(path)
84
+ else:
85
+ files_with_extensions.extend(directory.glob("*"))
86
+
87
+ return files_with_extensions
88
+
89
+
90
+ def read_txt_file(file_path: str | Path, skip_empty: bool = False) -> list[str]:
91
+ """
92
+ Read a text file and return a list of strings without newline characters.
93
+ Optionally skip empty lines.
94
+
95
+ Args:
96
+ file_path: The file path as a string or Path object.
97
+ skip_empty: If True, skip lines that are empty or contain only
98
+ whitespace. Default is False.
99
+
100
+ Returns:
101
+ A list of strings representing the lines in the text file.
102
+
103
+ Examples:
104
+ ```pycon
105
+ >>> import tempfile
106
+ >>> from pathlib import Path
107
+ >>> from supervision.utils.file import read_txt_file, save_text_file
108
+ >>> with tempfile.TemporaryDirectory() as tmpdir:
109
+ ... file_path = Path(tmpdir) / "test.txt"
110
+ ... save_text_file(["line1", " ", "line3"], file_path)
111
+ ... print(read_txt_file(file_path))
112
+ ... print(read_txt_file(file_path, skip_empty=True))
113
+ ['line1', ' ', 'line3']
114
+ ['line1', 'line3']
115
+
116
+ ```
117
+ """
118
+ with open(str(file_path)) as file:
119
+ if skip_empty:
120
+ lines = [line.rstrip("\n") for line in file if line.strip()]
121
+ else:
122
+ lines = [line.rstrip("\n") for line in file]
123
+
124
+ return lines
125
+
126
+
127
+ def save_text_file(lines: list[str], file_path: str | Path) -> None:
128
+ """
129
+ Write a list of strings to a text file, each string on a new line.
130
+
131
+ Args:
132
+ lines: The list of strings to be written to the file.
133
+ file_path: The file path as a string or Path object.
134
+ """
135
+ with open(str(file_path), "w") as file:
136
+ for line in lines:
137
+ file.write(line + "\n")
138
+
139
+
140
+ def read_json_file(file_path: str | Path) -> dict[str, Any]:
141
+ """
142
+ Read a json file and return a dict.
143
+
144
+ Args:
145
+ file_path: The file path as a string or Path object.
146
+
147
+ Returns:
148
+ A dict of annotations information
149
+
150
+ Examples:
151
+ ```pycon
152
+ >>> import tempfile
153
+ >>> from pathlib import Path
154
+ >>> from supervision.utils.file import read_json_file, save_json_file
155
+ >>> data = {"key": "value", "list": [1, 2, 3]}
156
+ >>> with tempfile.TemporaryDirectory() as tmpdir:
157
+ ... file_path = Path(tmpdir) / "test.json"
158
+ ... save_json_file(data, file_path)
159
+ ... print(read_json_file(file_path))
160
+ {'key': 'value', 'list': [1, 2, 3]}
161
+
162
+ ```
163
+ """
164
+ with open(str(file_path)) as file:
165
+ data = json.load(file)
166
+ return data # type: ignore
167
+
168
+
169
+ def save_json_file(
170
+ data: dict[str, Any], file_path: str | Path, indent: int = 3
171
+ ) -> None:
172
+ """
173
+ Write a dict to a json file.
174
+
175
+ Args:
176
+ data: dict with unique keys and value as pair.
177
+ file_path: The file path as a string or Path object.
178
+ indent:
179
+ """
180
+ with open(str(file_path), "w") as fp:
181
+ json.dump(data, fp, cls=NumpyJsonEncoder, indent=indent)
182
+
183
+
184
+ def read_yaml_file(file_path: str | Path) -> dict[str, Any]:
185
+ """
186
+ Read a yaml file and return a dict.
187
+
188
+ Args:
189
+ file_path: The file path as a string or Path object.
190
+
191
+ Returns:
192
+ A dict of content information
193
+ """
194
+ with open(str(file_path)) as file:
195
+ data = yaml.safe_load(file)
196
+ return data # type: ignore
197
+
198
+
199
+ def save_yaml_file(data: dict[str, Any], file_path: str | Path) -> None:
200
+ """
201
+ Save a dict to a yaml file.
202
+
203
+ Args:
204
+ data: dict with unique keys and value as pair.
205
+ file_path: The file path as a string or Path object.
206
+ """
207
+
208
+ with open(str(file_path), "w") as outfile:
209
+ yaml.dump(data, outfile, sort_keys=False, default_flow_style=None)