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.
- superiorvision/__init__.py +19 -0
- superiorvision-0.30.0.dev0.dist-info/METADATA +398 -0
- superiorvision-0.30.0.dev0.dist-info/RECORD +96 -0
- superiorvision-0.30.0.dev0.dist-info/WHEEL +5 -0
- superiorvision-0.30.0.dev0.dist-info/licenses/LICENSE.md +9 -0
- superiorvision-0.30.0.dev0.dist-info/top_level.txt +2 -0
- supervision/__init__.py +318 -0
- supervision/annotators/__init__.py +0 -0
- supervision/annotators/base.py +21 -0
- supervision/annotators/core.py +3551 -0
- supervision/annotators/utils.py +541 -0
- supervision/assets/__init__.py +4 -0
- supervision/assets/downloader.py +166 -0
- supervision/assets/list.py +84 -0
- supervision/classification/__init__.py +0 -0
- supervision/classification/core.py +216 -0
- supervision/config.py +13 -0
- supervision/dataset/__init__.py +0 -0
- supervision/dataset/core.py +1313 -0
- supervision/dataset/formats/__init__.py +0 -0
- supervision/dataset/formats/coco.py +708 -0
- supervision/dataset/formats/createml.py +331 -0
- supervision/dataset/formats/labelme.py +405 -0
- supervision/dataset/formats/pascal_voc.py +449 -0
- supervision/dataset/formats/yolo.py +502 -0
- supervision/dataset/utils.py +265 -0
- supervision/detection/__init__.py +0 -0
- supervision/detection/compact_mask.py +1927 -0
- supervision/detection/core.py +3864 -0
- supervision/detection/line_zone.py +924 -0
- supervision/detection/overlap_filter.py +426 -0
- supervision/detection/tensor_utils.py +1596 -0
- supervision/detection/tensor_views.py +48 -0
- supervision/detection/tools/__init__.py +0 -0
- supervision/detection/tools/csv_sink.py +242 -0
- supervision/detection/tools/inference_slicer.py +776 -0
- supervision/detection/tools/json_sink.py +215 -0
- supervision/detection/tools/polygon_zone.py +266 -0
- supervision/detection/tools/smoother.py +218 -0
- supervision/detection/tools/transformers.py +265 -0
- supervision/detection/utils/__init__.py +12 -0
- supervision/detection/utils/_typing.py +11 -0
- supervision/detection/utils/boxes.py +510 -0
- supervision/detection/utils/converters.py +830 -0
- supervision/detection/utils/internal.py +806 -0
- supervision/detection/utils/iou_and_nms.py +1606 -0
- supervision/detection/utils/masks.py +625 -0
- supervision/detection/utils/polygons.py +128 -0
- supervision/detection/utils/vlms.py +97 -0
- supervision/detection/vlm.py +945 -0
- supervision/draw/__init__.py +0 -0
- supervision/draw/base.py +14 -0
- supervision/draw/color.py +598 -0
- supervision/draw/utils.py +527 -0
- supervision/geometry/__init__.py +0 -0
- supervision/geometry/core.py +208 -0
- supervision/geometry/utils.py +54 -0
- supervision/key_points/__init__.py +0 -0
- supervision/key_points/annotators.py +997 -0
- supervision/key_points/core.py +1506 -0
- supervision/key_points/skeletons.py +2646 -0
- supervision/keypoint/__init__.py +13 -0
- supervision/keypoint/annotators.py +13 -0
- supervision/keypoint/core.py +8 -0
- supervision/metrics/__init__.py +40 -0
- supervision/metrics/core.py +74 -0
- supervision/metrics/detection.py +1632 -0
- supervision/metrics/f1_score.py +815 -0
- supervision/metrics/mean_average_precision.py +1723 -0
- supervision/metrics/mean_average_recall.py +734 -0
- supervision/metrics/precision.py +815 -0
- supervision/metrics/recall.py +774 -0
- supervision/metrics/utils/__init__.py +0 -0
- supervision/metrics/utils/matching.py +56 -0
- supervision/metrics/utils/object_size.py +256 -0
- supervision/metrics/utils/utils.py +9 -0
- supervision/py.typed +0 -0
- supervision/tracker/__init__.py +5 -0
- supervision/tracker/byte_tracker/__init__.py +0 -0
- supervision/tracker/byte_tracker/core.py +448 -0
- supervision/tracker/byte_tracker/kalman_filter.py +186 -0
- supervision/tracker/byte_tracker/matching.py +211 -0
- supervision/tracker/byte_tracker/single_object_track.py +194 -0
- supervision/tracker/byte_tracker/utils.py +34 -0
- supervision/utils/__init__.py +0 -0
- supervision/utils/conversion.py +223 -0
- supervision/utils/deprecate.py +54 -0
- supervision/utils/file.py +209 -0
- supervision/utils/image.py +988 -0
- supervision/utils/internal.py +209 -0
- supervision/utils/iterables.py +103 -0
- supervision/utils/logger.py +61 -0
- supervision/utils/notebook.py +124 -0
- supervision/utils/tensor.py +362 -0
- supervision/utils/video.py +533 -0
- 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)
|