ort-vision-sdk 0.2.0__tar.gz
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.
- ort_vision_sdk-0.2.0/.gitignore +63 -0
- ort_vision_sdk-0.2.0/CHANGELOG.md +110 -0
- ort_vision_sdk-0.2.0/LICENSE +21 -0
- ort_vision_sdk-0.2.0/PKG-INFO +79 -0
- ort_vision_sdk-0.2.0/README.md +40 -0
- ort_vision_sdk-0.2.0/pyproject.toml +123 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/__init__.py +57 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/core/__init__.py +24 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/core/exceptions.py +31 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/core/providers.py +104 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/core/session.py +122 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/io/__init__.py +5 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/io/image.py +91 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/labels.py +203 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/postprocess/__init__.py +30 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/postprocess/classification.py +45 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/postprocess/detection.py +360 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/postprocess/segmentation.py +246 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/preprocess/__init__.py +23 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/preprocess/image.py +185 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/py.typed +0 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/results.py +363 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/tasks/__init__.py +15 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/tasks/base.py +58 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/tasks/classifier.py +211 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/tasks/detector.py +274 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/tasks/segmenter.py +359 -0
- ort_vision_sdk-0.2.0/src/ort_vision_sdk/types.py +288 -0
- ort_vision_sdk-0.2.0/tests/__init__.py +0 -0
- ort_vision_sdk-0.2.0/tests/test_deprecations.py +103 -0
- ort_vision_sdk-0.2.0/tests/test_labels.py +83 -0
- ort_vision_sdk-0.2.0/tests/test_postprocess_classification.py +64 -0
- ort_vision_sdk-0.2.0/tests/test_postprocess_detection.py +259 -0
- ort_vision_sdk-0.2.0/tests/test_postprocess_segmentation.py +151 -0
- ort_vision_sdk-0.2.0/tests/test_results.py +228 -0
- ort_vision_sdk-0.2.0/tests/test_types.py +95 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
build/
|
|
8
|
+
develop-eggs/
|
|
9
|
+
dist/
|
|
10
|
+
downloads/
|
|
11
|
+
eggs/
|
|
12
|
+
.eggs/
|
|
13
|
+
lib/
|
|
14
|
+
lib64/
|
|
15
|
+
parts/
|
|
16
|
+
sdist/
|
|
17
|
+
var/
|
|
18
|
+
wheels/
|
|
19
|
+
share/python-wheels/
|
|
20
|
+
*.egg-info/
|
|
21
|
+
.installed.cfg
|
|
22
|
+
*.egg
|
|
23
|
+
MANIFEST
|
|
24
|
+
|
|
25
|
+
# Virtual envs
|
|
26
|
+
.venv/
|
|
27
|
+
venv/
|
|
28
|
+
env/
|
|
29
|
+
ENV/
|
|
30
|
+
|
|
31
|
+
# Tooling caches
|
|
32
|
+
.pytest_cache/
|
|
33
|
+
.mypy_cache/
|
|
34
|
+
.ruff_cache/
|
|
35
|
+
.coverage
|
|
36
|
+
.coverage.*
|
|
37
|
+
htmlcov/
|
|
38
|
+
coverage.xml
|
|
39
|
+
*.cover
|
|
40
|
+
|
|
41
|
+
# IDEs
|
|
42
|
+
.vscode/
|
|
43
|
+
.idea/
|
|
44
|
+
*.swp
|
|
45
|
+
*.swo
|
|
46
|
+
|
|
47
|
+
# OS
|
|
48
|
+
.DS_Store
|
|
49
|
+
Thumbs.db
|
|
50
|
+
|
|
51
|
+
# Models and assets (keep repo lean)
|
|
52
|
+
*.onnx
|
|
53
|
+
*.pt
|
|
54
|
+
*.pth
|
|
55
|
+
*.h5
|
|
56
|
+
*.pb
|
|
57
|
+
models/
|
|
58
|
+
assets/
|
|
59
|
+
data/
|
|
60
|
+
|
|
61
|
+
# Local env
|
|
62
|
+
.env
|
|
63
|
+
.env.local
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `ort-vision-sdk` (Python) are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.2.0] - 2026-05-02
|
|
11
|
+
|
|
12
|
+
This release brings the public API in line with the Ultralytics / PyTorch
|
|
13
|
+
idiom, so code ported from those ecosystems works with minimal changes.
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- **Per-image `Results` envelopes** (`DetectionResults`, `ClassificationResults`,
|
|
18
|
+
`SegmentationResults`) returned by every `predict()` call as a 1-element
|
|
19
|
+
list, mirroring `YOLO("img.jpg")`. Each envelope holds:
|
|
20
|
+
- `boxes` / `probs` / `masks` — bulk numpy views with Ultralytics-style
|
|
21
|
+
accessors (`xyxy`, `xywh`, `xyxyn`, `xywhn`, `cls`, `conf`, `data`,
|
|
22
|
+
`top1`, `top1conf`, `top5`, `top5conf`).
|
|
23
|
+
- `detections` — tuple of per-instance dataclasses (the previous return
|
|
24
|
+
type).
|
|
25
|
+
- `names` — `dict[int, str]` matching `model.names`.
|
|
26
|
+
- `orig_img`, `orig_shape`, `path`, `speed`.
|
|
27
|
+
- **Ultralytics-style aliases** on `BoundingBox`, `ClassProbability`,
|
|
28
|
+
`ClassificationResult`, `DetectionResult`, `SegmentationResult`:
|
|
29
|
+
`cls`, `conf`, `name`, `box`, `xyxy`, `xywh` (center coords),
|
|
30
|
+
plus `xyxyn(orig_shape)` / `xywhn(orig_shape)` methods on `BoundingBox`.
|
|
31
|
+
- **`__call__` on every task class** — `Detector(model)(image)` now works
|
|
32
|
+
like `torch.nn.Module.__call__`, delegating to `predict()`.
|
|
33
|
+
- **`names: dict[int, str]` property** on every task class alongside
|
|
34
|
+
`labels: tuple[str, ...]`.
|
|
35
|
+
- **Short device aliases** in `providers=` — `"cpu"`, `"cuda"`, `"gpu"`,
|
|
36
|
+
`"tensorrt"` / `"trt"`, `"coreml"` / `"mps"`, `"dml"` / `"directml"`,
|
|
37
|
+
`"openvino"` are expanded to the canonical `*ExecutionProvider` names.
|
|
38
|
+
New helper `normalize_provider(name)`.
|
|
39
|
+
- **Explicit `head=` parameter** on `Detector` and `Segmenter` constructors —
|
|
40
|
+
caller declares which decoder family the model uses (`"yolo"` for
|
|
41
|
+
detect heads of v8/v9/v10/v11/v12/v26; `"yolo-seg"` for the matching
|
|
42
|
+
seg heads). The SDK does **not** auto-detect — wrong head raises
|
|
43
|
+
`ValueError`. New types `DetectorHead`, `SegmenterHead`.
|
|
44
|
+
- **`classes` filter** on `Detector.predict()` / `Detector.__call__()` and
|
|
45
|
+
`Segmenter.predict()` / `Segmenter.__call__()` — keeps only results whose
|
|
46
|
+
`class_id` is in the supplied list, matching Ultralytics'
|
|
47
|
+
`model.predict(img, classes=[0, 16])`.
|
|
48
|
+
- **`postprocess.batched_nms(boxes, scores, idxs, iou_threshold)`** matching
|
|
49
|
+
`torchvision.ops.batched_nms`.
|
|
50
|
+
- **Generic YOLO decoder names**: `decode_yolo`, `decode_yolo_anchors`,
|
|
51
|
+
`decode_yolo_seg` — same code, accurate name (covers v8/v9/v10/v11/v12).
|
|
52
|
+
- **Preprocess helpers** mirroring torchvision/OpenCV:
|
|
53
|
+
- `to_tensor(image)` → CHW `float32 / 255` (ToTensor parity).
|
|
54
|
+
- `from_cv2(bgr)` / `to_cv2(rgb)` — channel-order bridges.
|
|
55
|
+
|
|
56
|
+
### Changed
|
|
57
|
+
|
|
58
|
+
- `Detector.predict(img)` now returns `list[DetectionResults]` (1 element)
|
|
59
|
+
instead of `list[DetectionResult]`. Iterate the envelope to recover the
|
|
60
|
+
old shape: `for d in detector.predict(img)[0]: ...`.
|
|
61
|
+
- `Classifier.predict(img)` now returns `list[ClassificationResults]`.
|
|
62
|
+
- `Segmenter.predict(img)` now returns `list[SegmentationResults]`.
|
|
63
|
+
- `nms(boxes, scores, iou_threshold)` — first parameter renamed from
|
|
64
|
+
`boxes_xyxy` to `boxes` for `torchvision.ops.nms` parity.
|
|
65
|
+
- The detection decoder no longer applies the per-class loop inline — it
|
|
66
|
+
delegates to `batched_nms`.
|
|
67
|
+
|
|
68
|
+
### Deprecated
|
|
69
|
+
|
|
70
|
+
- `decode_yolov8`, `decode_yolov8_anchors`, `decode_yolov8_seg` — emit
|
|
71
|
+
`DeprecationWarning`; will be removed in 0.3.0. Use `decode_yolo`,
|
|
72
|
+
`decode_yolo_anchors`, `decode_yolo_seg` instead.
|
|
73
|
+
|
|
74
|
+
### Migration
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
# Before (0.1.0)
|
|
78
|
+
detections = detector.predict("street.jpg")
|
|
79
|
+
for d in detections:
|
|
80
|
+
print(d.class_id, d.class_name, d.confidence, d.bbox.as_xyxy())
|
|
81
|
+
|
|
82
|
+
# After (0.2.0)
|
|
83
|
+
results = detector.predict("street.jpg") # list[DetectionResults], len 1
|
|
84
|
+
r = results[0]
|
|
85
|
+
|
|
86
|
+
# Per-instance dataclasses (legacy fields still work):
|
|
87
|
+
for d in r:
|
|
88
|
+
print(d.class_id, d.class_name, d.confidence, d.bbox.as_xyxy())
|
|
89
|
+
# or with the new short aliases:
|
|
90
|
+
for d in r:
|
|
91
|
+
print(d.cls, d.name, d.conf, d.box.xyxy)
|
|
92
|
+
|
|
93
|
+
# Bulk numpy access (matches Ultralytics):
|
|
94
|
+
print(r.boxes.xyxy.shape, r.boxes.cls, r.boxes.conf, r.names)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## [0.1.0] - 2026-05-02
|
|
98
|
+
|
|
99
|
+
### Added
|
|
100
|
+
|
|
101
|
+
- Initial alpha release.
|
|
102
|
+
- `Classifier` and `Detector` task classes wrapping `onnxruntime.InferenceSession`.
|
|
103
|
+
- Image I/O helpers (`load_image`, `ImageInput`).
|
|
104
|
+
- Default label maps (`COCO_CLASSES`, ImageNet via `resolve_labels`).
|
|
105
|
+
- Public types: `BoundingBox`, `ClassProbability`, `ClassificationResult`, `DetectionResult`, `ImageArray`.
|
|
106
|
+
- Optional extras: `gpu` (onnxruntime-gpu), `opencv` (opencv-python), `dev` (test/lint tooling).
|
|
107
|
+
|
|
108
|
+
[Unreleased]: https://github.com/mauriciobenjamin700/ort-vision-sdk/compare/v0.2.0...HEAD
|
|
109
|
+
[0.2.0]: https://github.com/mauriciobenjamin700/ort-vision-sdk/releases/tag/v0.2.0
|
|
110
|
+
[0.1.0]: https://github.com/mauriciobenjamin700/ort-vision-sdk/releases/tag/v0.1.0
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mauricio Benjamin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ort-vision-sdk
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: High-level Python SDK for computer vision inference with ONNX Runtime.
|
|
5
|
+
Project-URL: Homepage, https://github.com/mauriciobenjamin700/ort-vision-sdk
|
|
6
|
+
Project-URL: Repository, https://github.com/mauriciobenjamin700/ort-vision-sdk
|
|
7
|
+
Project-URL: Issues, https://github.com/mauriciobenjamin700/ort-vision-sdk/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/mauriciobenjamin700/ort-vision-sdk/blob/main/CHANGELOG.md
|
|
9
|
+
Author-email: Mauricio Benjamin <mauriciobenjamin700@gmail.com>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: computer-vision,inference,onnx,onnxruntime,sdk
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Requires-Dist: numpy>=1.24.0
|
|
25
|
+
Requires-Dist: onnxruntime>=1.17.0
|
|
26
|
+
Requires-Dist: pillow>=10.0.0
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: build>=1.2.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: mypy>=1.10.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
32
|
+
Requires-Dist: ruff>=0.5.0; extra == 'dev'
|
|
33
|
+
Requires-Dist: twine>=5.0.0; extra == 'dev'
|
|
34
|
+
Provides-Extra: gpu
|
|
35
|
+
Requires-Dist: onnxruntime-gpu>=1.17.0; extra == 'gpu'
|
|
36
|
+
Provides-Extra: opencv
|
|
37
|
+
Requires-Dist: opencv-python>=4.8.0; extra == 'opencv'
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
# ort-vision-sdk
|
|
41
|
+
|
|
42
|
+
High-level Python SDK for computer vision inference on top of [ONNX Runtime](https://onnxruntime.ai/).
|
|
43
|
+
|
|
44
|
+
Wraps the low-level `InferenceSession` API with task-oriented classes (`Classifier`, `Detector`, ...) that handle preprocessing, execution provider selection, and postprocessing — so you go from an image to a typed result in one call.
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install ort-vision-sdk # CPU only
|
|
50
|
+
pip install ort-vision-sdk[gpu] # CUDA
|
|
51
|
+
pip install ort-vision-sdk[opencv] # adds cv2 image backend
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Quick start
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from ort_vision_sdk import Classifier
|
|
58
|
+
|
|
59
|
+
clf = Classifier("resnet50.onnx", labels="imagenet")
|
|
60
|
+
result = clf.predict("dog.jpg")
|
|
61
|
+
|
|
62
|
+
print(result.class_name, result.confidence)
|
|
63
|
+
print(result.probabilities[:5]) # top-5 ClassProbability tuples
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from ort_vision_sdk import Detector
|
|
68
|
+
|
|
69
|
+
det = Detector("yolov8n.onnx", labels="coco")
|
|
70
|
+
detections = det.predict("street.jpg")
|
|
71
|
+
|
|
72
|
+
for d in detections:
|
|
73
|
+
print(d.class_name, d.confidence, d.bbox.as_xyxy())
|
|
74
|
+
# d.cropped_image is a np.ndarray (HWC, RGB, uint8)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Status
|
|
78
|
+
|
|
79
|
+
Alpha — API may change. See [`pyproject.toml`](pyproject.toml) for supported Python and dependency versions.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# ort-vision-sdk
|
|
2
|
+
|
|
3
|
+
High-level Python SDK for computer vision inference on top of [ONNX Runtime](https://onnxruntime.ai/).
|
|
4
|
+
|
|
5
|
+
Wraps the low-level `InferenceSession` API with task-oriented classes (`Classifier`, `Detector`, ...) that handle preprocessing, execution provider selection, and postprocessing — so you go from an image to a typed result in one call.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install ort-vision-sdk # CPU only
|
|
11
|
+
pip install ort-vision-sdk[gpu] # CUDA
|
|
12
|
+
pip install ort-vision-sdk[opencv] # adds cv2 image backend
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from ort_vision_sdk import Classifier
|
|
19
|
+
|
|
20
|
+
clf = Classifier("resnet50.onnx", labels="imagenet")
|
|
21
|
+
result = clf.predict("dog.jpg")
|
|
22
|
+
|
|
23
|
+
print(result.class_name, result.confidence)
|
|
24
|
+
print(result.probabilities[:5]) # top-5 ClassProbability tuples
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from ort_vision_sdk import Detector
|
|
29
|
+
|
|
30
|
+
det = Detector("yolov8n.onnx", labels="coco")
|
|
31
|
+
detections = det.predict("street.jpg")
|
|
32
|
+
|
|
33
|
+
for d in detections:
|
|
34
|
+
print(d.class_name, d.confidence, d.bbox.as_xyxy())
|
|
35
|
+
# d.cropped_image is a np.ndarray (HWC, RGB, uint8)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Status
|
|
39
|
+
|
|
40
|
+
Alpha — API may change. See [`pyproject.toml`](pyproject.toml) for supported Python and dependency versions.
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ort-vision-sdk"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "High-level Python SDK for computer vision inference with ONNX Runtime."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Mauricio Benjamin", email = "mauriciobenjamin700@gmail.com" },
|
|
15
|
+
]
|
|
16
|
+
keywords = ["onnx", "onnxruntime", "computer-vision", "inference", "sdk"]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 3 - Alpha",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
26
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
27
|
+
"Typing :: Typed",
|
|
28
|
+
]
|
|
29
|
+
dependencies = [
|
|
30
|
+
"onnxruntime>=1.17.0",
|
|
31
|
+
"numpy>=1.24.0",
|
|
32
|
+
"pillow>=10.0.0",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.optional-dependencies]
|
|
36
|
+
gpu = ["onnxruntime-gpu>=1.17.0"]
|
|
37
|
+
opencv = ["opencv-python>=4.8.0"]
|
|
38
|
+
dev = [
|
|
39
|
+
"pytest>=8.0.0",
|
|
40
|
+
"pytest-cov>=5.0.0",
|
|
41
|
+
"ruff>=0.5.0",
|
|
42
|
+
"mypy>=1.10.0",
|
|
43
|
+
"build>=1.2.0",
|
|
44
|
+
"twine>=5.0.0",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
[project.urls]
|
|
48
|
+
Homepage = "https://github.com/mauriciobenjamin700/ort-vision-sdk"
|
|
49
|
+
Repository = "https://github.com/mauriciobenjamin700/ort-vision-sdk"
|
|
50
|
+
Issues = "https://github.com/mauriciobenjamin700/ort-vision-sdk/issues"
|
|
51
|
+
Changelog = "https://github.com/mauriciobenjamin700/ort-vision-sdk/blob/main/CHANGELOG.md"
|
|
52
|
+
|
|
53
|
+
[tool.hatch.build.targets.wheel]
|
|
54
|
+
packages = ["src/ort_vision_sdk"]
|
|
55
|
+
|
|
56
|
+
[tool.hatch.build.targets.sdist]
|
|
57
|
+
include = [
|
|
58
|
+
"/src/ort_vision_sdk",
|
|
59
|
+
"/tests",
|
|
60
|
+
"/README.md",
|
|
61
|
+
"/LICENSE",
|
|
62
|
+
"/CHANGELOG.md",
|
|
63
|
+
"/pyproject.toml",
|
|
64
|
+
]
|
|
65
|
+
exclude = [
|
|
66
|
+
"/dist",
|
|
67
|
+
"**/__pycache__",
|
|
68
|
+
"**/*.py[cod]",
|
|
69
|
+
"**/.mypy_cache",
|
|
70
|
+
"**/.pytest_cache",
|
|
71
|
+
"**/.ruff_cache",
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
[tool.ruff]
|
|
75
|
+
line-length = 100
|
|
76
|
+
target-version = "py310"
|
|
77
|
+
src = ["src", "tests"]
|
|
78
|
+
|
|
79
|
+
[tool.ruff.lint]
|
|
80
|
+
select = [
|
|
81
|
+
"E", # pycodestyle errors
|
|
82
|
+
"W", # pycodestyle warnings
|
|
83
|
+
"F", # pyflakes
|
|
84
|
+
"I", # isort
|
|
85
|
+
"B", # flake8-bugbear
|
|
86
|
+
"UP", # pyupgrade
|
|
87
|
+
"N", # pep8-naming
|
|
88
|
+
"D", # pydocstyle
|
|
89
|
+
"ANN", # flake8-annotations
|
|
90
|
+
"RUF",
|
|
91
|
+
]
|
|
92
|
+
ignore = [
|
|
93
|
+
"D203", # one-blank-line-before-class (conflicts with D211)
|
|
94
|
+
"D213", # multi-line-summary-second-line (conflicts with D212)
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
[tool.ruff.lint.pydocstyle]
|
|
98
|
+
convention = "google"
|
|
99
|
+
|
|
100
|
+
[tool.ruff.format]
|
|
101
|
+
quote-style = "double"
|
|
102
|
+
indent-style = "space"
|
|
103
|
+
|
|
104
|
+
[tool.mypy]
|
|
105
|
+
python_version = "3.10"
|
|
106
|
+
strict = true
|
|
107
|
+
warn_unused_ignores = true
|
|
108
|
+
warn_return_any = true
|
|
109
|
+
disallow_untyped_defs = true
|
|
110
|
+
disallow_incomplete_defs = true
|
|
111
|
+
|
|
112
|
+
[[tool.mypy.overrides]]
|
|
113
|
+
module = ["onnxruntime.*", "cv2.*"]
|
|
114
|
+
ignore_missing_imports = true
|
|
115
|
+
|
|
116
|
+
[tool.pytest.ini_options]
|
|
117
|
+
testpaths = ["tests"]
|
|
118
|
+
python_files = ["test_*.py"]
|
|
119
|
+
pythonpath = ["src"]
|
|
120
|
+
addopts = "-ra --strict-markers"
|
|
121
|
+
filterwarnings = [
|
|
122
|
+
"default::DeprecationWarning:ort_vision_sdk.*",
|
|
123
|
+
]
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""ort-vision-sdk: high-level Python SDK for computer vision inference with ONNX Runtime."""
|
|
2
|
+
|
|
3
|
+
from ort_vision_sdk.io import ImageInput, load_image
|
|
4
|
+
from ort_vision_sdk.labels import COCO_CLASSES, LabelSpec, resolve_labels
|
|
5
|
+
from ort_vision_sdk.results import (
|
|
6
|
+
Boxes,
|
|
7
|
+
ClassificationResults,
|
|
8
|
+
DetectionResults,
|
|
9
|
+
Masks,
|
|
10
|
+
Probs,
|
|
11
|
+
SegmentationResults,
|
|
12
|
+
)
|
|
13
|
+
from ort_vision_sdk.tasks import (
|
|
14
|
+
Classifier,
|
|
15
|
+
Detector,
|
|
16
|
+
DetectorHead,
|
|
17
|
+
Segmenter,
|
|
18
|
+
SegmenterHead,
|
|
19
|
+
VisionTask,
|
|
20
|
+
)
|
|
21
|
+
from ort_vision_sdk.types import (
|
|
22
|
+
BoundingBox,
|
|
23
|
+
ClassificationResult,
|
|
24
|
+
ClassProbability,
|
|
25
|
+
DetectionResult,
|
|
26
|
+
ImageArray,
|
|
27
|
+
SegmentationResult,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
__version__: str = "0.2.0"
|
|
31
|
+
|
|
32
|
+
__all__: list[str] = [
|
|
33
|
+
"COCO_CLASSES",
|
|
34
|
+
"BoundingBox",
|
|
35
|
+
"Boxes",
|
|
36
|
+
"ClassProbability",
|
|
37
|
+
"ClassificationResult",
|
|
38
|
+
"ClassificationResults",
|
|
39
|
+
"Classifier",
|
|
40
|
+
"DetectionResult",
|
|
41
|
+
"DetectionResults",
|
|
42
|
+
"Detector",
|
|
43
|
+
"DetectorHead",
|
|
44
|
+
"ImageArray",
|
|
45
|
+
"ImageInput",
|
|
46
|
+
"LabelSpec",
|
|
47
|
+
"Masks",
|
|
48
|
+
"Probs",
|
|
49
|
+
"SegmentationResult",
|
|
50
|
+
"SegmentationResults",
|
|
51
|
+
"Segmenter",
|
|
52
|
+
"SegmenterHead",
|
|
53
|
+
"VisionTask",
|
|
54
|
+
"__version__",
|
|
55
|
+
"load_image",
|
|
56
|
+
"resolve_labels",
|
|
57
|
+
]
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""Core building blocks: ORT session wrapper, provider resolution, and exceptions."""
|
|
2
|
+
|
|
3
|
+
from ort_vision_sdk.core.exceptions import (
|
|
4
|
+
ImageLoadError,
|
|
5
|
+
InferenceError,
|
|
6
|
+
LabelMapError,
|
|
7
|
+
ModelLoadError,
|
|
8
|
+
OrtVisionError,
|
|
9
|
+
ProviderNotAvailableError,
|
|
10
|
+
)
|
|
11
|
+
from ort_vision_sdk.core.providers import available_providers, resolve_providers
|
|
12
|
+
from ort_vision_sdk.core.session import OrtSession
|
|
13
|
+
|
|
14
|
+
__all__: list[str] = [
|
|
15
|
+
"ImageLoadError",
|
|
16
|
+
"InferenceError",
|
|
17
|
+
"LabelMapError",
|
|
18
|
+
"ModelLoadError",
|
|
19
|
+
"OrtSession",
|
|
20
|
+
"OrtVisionError",
|
|
21
|
+
"ProviderNotAvailableError",
|
|
22
|
+
"available_providers",
|
|
23
|
+
"resolve_providers",
|
|
24
|
+
]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""Exceptions raised by the SDK.
|
|
2
|
+
|
|
3
|
+
All exceptions inherit from :class:`OrtVisionError`, so callers can catch the
|
|
4
|
+
base class to handle any SDK-originated failure uniformly.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class OrtVisionError(Exception):
|
|
11
|
+
"""Base class for all ort-vision-sdk errors."""
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ModelLoadError(OrtVisionError):
|
|
15
|
+
"""Raised when an ONNX model cannot be loaded into an inference session."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class InferenceError(OrtVisionError):
|
|
19
|
+
"""Raised when ONNX Runtime fails while executing a model."""
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ProviderNotAvailableError(OrtVisionError):
|
|
23
|
+
"""Raised when a requested execution provider is not available in this ORT build."""
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ImageLoadError(OrtVisionError):
|
|
27
|
+
"""Raised when an input image cannot be decoded into the canonical array format."""
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class LabelMapError(OrtVisionError):
|
|
31
|
+
"""Raised when class labels cannot be resolved from the supplied spec."""
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""Execution-provider resolution for ONNX Runtime sessions.
|
|
2
|
+
|
|
3
|
+
Encapsulates the logic of picking the best available accelerator (CUDA,
|
|
4
|
+
TensorRT, CoreML, DirectML, OpenVINO) and falling back to CPU. Callers can
|
|
5
|
+
pass an explicit list of providers when they need full control.
|
|
6
|
+
|
|
7
|
+
Short Ultralytics-style aliases (``"cpu"``, ``"cuda"``, ``"tensorrt"``,
|
|
8
|
+
``"coreml"``, ``"dml"`` / ``"directml"``, ``"openvino"``) are accepted in
|
|
9
|
+
addition to the canonical ORT names (``"CPUExecutionProvider"``,
|
|
10
|
+
``"CUDAExecutionProvider"``, ...).
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import onnxruntime as ort
|
|
16
|
+
|
|
17
|
+
from ort_vision_sdk.core.exceptions import ProviderNotAvailableError
|
|
18
|
+
|
|
19
|
+
_PRIORITY: tuple[str, ...] = (
|
|
20
|
+
"TensorrtExecutionProvider",
|
|
21
|
+
"CUDAExecutionProvider",
|
|
22
|
+
"CoreMLExecutionProvider",
|
|
23
|
+
"DmlExecutionProvider",
|
|
24
|
+
"OpenVINOExecutionProvider",
|
|
25
|
+
"CPUExecutionProvider",
|
|
26
|
+
)
|
|
27
|
+
"""Default preference order, from most to least accelerated."""
|
|
28
|
+
|
|
29
|
+
_ALIASES: dict[str, str] = {
|
|
30
|
+
"cpu": "CPUExecutionProvider",
|
|
31
|
+
"cuda": "CUDAExecutionProvider",
|
|
32
|
+
"gpu": "CUDAExecutionProvider",
|
|
33
|
+
"tensorrt": "TensorrtExecutionProvider",
|
|
34
|
+
"trt": "TensorrtExecutionProvider",
|
|
35
|
+
"coreml": "CoreMLExecutionProvider",
|
|
36
|
+
"mps": "CoreMLExecutionProvider",
|
|
37
|
+
"dml": "DmlExecutionProvider",
|
|
38
|
+
"directml": "DmlExecutionProvider",
|
|
39
|
+
"openvino": "OpenVINOExecutionProvider",
|
|
40
|
+
}
|
|
41
|
+
"""Short device aliases → canonical ORT provider names. Lookup is case-insensitive."""
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def available_providers() -> list[str]:
|
|
45
|
+
"""Return the execution providers available in this ORT build.
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
List of provider names exactly as ONNX Runtime reports them.
|
|
49
|
+
"""
|
|
50
|
+
return list(ort.get_available_providers())
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def normalize_provider(name: str) -> str:
|
|
54
|
+
"""Expand a short device alias to its canonical ORT provider name.
|
|
55
|
+
|
|
56
|
+
Names that already end in ``ExecutionProvider`` are returned unchanged
|
|
57
|
+
(case-preserving). Short aliases are looked up case-insensitively.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
name: Either a short alias (``"cpu"``, ``"cuda"``, ``"tensorrt"``,
|
|
61
|
+
``"coreml"``, ``"dml"``, ``"openvino"``, ...) or a canonical ORT
|
|
62
|
+
provider name (``"CPUExecutionProvider"`` etc.).
|
|
63
|
+
|
|
64
|
+
Returns:
|
|
65
|
+
The canonical ORT provider name. If ``name`` is already canonical,
|
|
66
|
+
it is returned as-is.
|
|
67
|
+
"""
|
|
68
|
+
if name.endswith("ExecutionProvider"):
|
|
69
|
+
return name
|
|
70
|
+
return _ALIASES.get(name.lower(), name)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def resolve_providers(requested: list[str] | None = None) -> list[str]:
|
|
74
|
+
"""Resolve the execution providers to use for an inference session.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
requested: Explicit list of providers in preference order. Each entry
|
|
78
|
+
may be a canonical ORT name (``"CUDAExecutionProvider"``) or a
|
|
79
|
+
short alias (``"cuda"``, ``"cpu"``, ``"tensorrt"``, ...). ``None``
|
|
80
|
+
(default) auto-selects the best available accelerator with CPU
|
|
81
|
+
as the final fallback.
|
|
82
|
+
|
|
83
|
+
Returns:
|
|
84
|
+
Ordered list of canonical providers to pass to
|
|
85
|
+
``onnxruntime.InferenceSession``. Always non-empty (CPU is always
|
|
86
|
+
available).
|
|
87
|
+
|
|
88
|
+
Raises:
|
|
89
|
+
ProviderNotAvailableError: If any explicitly requested provider is
|
|
90
|
+
not available in this ORT build.
|
|
91
|
+
"""
|
|
92
|
+
available = set(available_providers())
|
|
93
|
+
if requested is None:
|
|
94
|
+
ordered = [p for p in _PRIORITY if p in available]
|
|
95
|
+
return ordered or ["CPUExecutionProvider"]
|
|
96
|
+
|
|
97
|
+
canonical = [normalize_provider(p) for p in requested]
|
|
98
|
+
missing = [p for p in canonical if p not in available]
|
|
99
|
+
if missing:
|
|
100
|
+
raise ProviderNotAvailableError(
|
|
101
|
+
f"Requested execution provider(s) not available: {missing}. "
|
|
102
|
+
f"Available providers: {sorted(available)}."
|
|
103
|
+
)
|
|
104
|
+
return canonical
|