SpatialHub
A high-performance, zero-PyTorch spatial AI and perception library providing unified ONNX Runtime inference adapters for computer vision and 3D spatial computing models.
Key Principles
- Zero-PyTorch Inference: Core runtime paths execute exclusively on ONNX Runtime with pure NumPy and OpenCV vector operations.
- Unified Return Contracts: Standardized dataclass outputs across all model families (
MatchResult,DepthPredictionResult,FeatureExtractionResult,SegmentationResult,PoseEstimationResult). - Automatic Weight Management: Downloads, verifies, and caches pretrained
.onnxweight binaries seamlessly from Hugging Face Hub. - Hardware Acceleration: Native support for CPU, CUDA, and TensorRT execution providers with runtime fallback verification.
- ModernGL GPU Rendering: Built-in headless offscreen G-buffer and batched atlas renderer for CAD model template matching and 6D pose estimation.
Supported Models
| Model Architecture | Task | Default Variant / Option | Returned Dataclass | Documentation |
|---|---|---|---|---|
| FoundationPose | 6D Object Pose Estimation & Tracking | 3D CAD Mesh (.ply, .obj, .stl) |
PoseEstimationResult |
Model Reference • Export Guide |
| EfficientLoFTR | Semi-dense Feature Matching | "full" or "opt" |
MatchResult |
Model Reference • Export Guide |
| Depth Anything 3 | Monocular & Multi-View Depth | "da3_base" (small/large/giant/metric/nested) |
DepthPredictionResult |
Model Reference • Export Guide |
| DINOv2 | Image Feature Extraction | "dinov2_vitl14" (vits14/vitb14/vitg14) |
FeatureExtractionResult |
Model Reference • Export Guide |
| FastSAM | Real-Time Proposal Segmentation | "FastSAM-x" or "FastSAM-s" |
SegmentationResult |
Model Reference • Export Guide |
| SAM | Automatic Mask Generation (AMG) | "sam_vit_h" (vit_l/vit_b) |
SegmentationResult |
Model Reference • Export Guide |
| CNOS | CAD Zero-Shot Object Detection | 3D CAD Mesh (.ply, .obj, .stl) |
SegmentationResult |
Model Reference • Export Guide |
Installation
Requires Python 3.12+.
pip install spatialhub
For GPU acceleration (CUDA / TensorRT):
pip install "spatialhub[gpu]"
For 3D CAD mesh processing and ModernGL rendering:
pip install "spatialhub[render]"
Quickstart
from spatialhub import FoundationPose, EfficientLoFTR, DepthAnything3, DINOV2, FastSAM, SAM, CNOS
# 1. 6D Object Pose Estimation (FoundationPose)
est = FoundationPose(
model_path="mesh.obj",
model_unit="mm",
scorer_weights="scorer.onnx",
refiner_weights="refiner.onnx"
)
pose_res = est.estimate(rgb=rgb_img, depth=depth_img, K=cam_K, mask=obj_mask)
pose_res.visualize(draw_bbox=True, draw_axes=True, save_path="pose.png")
# 2. Feature Matching (EfficientLoFTR)
matcher = EfficientLoFTR()
match_res = matcher.match("img1.jpg", "img2.jpg", max_dim=1024)
match_res.visualize(top_k=50, save_path="matches.png")
# 3. Depth Estimation (Depth Anything 3)
estimator = DepthAnything3(model_name="da3_base")
depth_res = estimator.estimate_depth(images=["view1.png", "view2.png"])
depth_viz = estimator.visualize(depth_res.depth[0])
# 4. Feature Embeddings (DINOv2)
dino = DINOV2(model_variant="dinov2_vitl14")
feat_res = dino.extract_features("image.png", l2_normalize=True)
# 5. Proposal Segmentation (FastSAM)
fastsam = FastSAM(model_variant="FastSAM-x")
seg_res = fastsam.generate_masks("scene.png", conf_threshold=0.3)
seg_res.visualize_mask(save_path="fastsam_masks.png")
Reproducible ONNX Export Workflow
Each model directory under src/spatialhub/models/<model>/ contains an isolated environment configuration and export_onnx.py script to re-export custom ONNX graphs:
cd src/spatialhub/models/efficient_loftr
uv sync
uv run python export_onnx.py --checkpoint weights/model.ckpt --output-path weights/model.onnx
See the Reproducible ONNX Export Guide for complete documentation.
License
Core SpatialHub code is released under the Apache 2.0 License. Pretrained model weights and submodule architectures maintain their respective original licenses.
Release files for spatialhub 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| spatialhub-0.1.5.tar.gz | 2.2 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| spatialhub-0.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 4.2 MB
Release files / spatialhub-0.1.5.tar.gz
| Download URL | spatialhub-0.1.5.tar.gz |
|---|---|
| Size | 2.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
20df5511f58e52c60c9e31da0d700045fc0bcfb361accc0f00a728cf83c740d0
|
|
BLAKE2b-256 checksum How to use checksums |
0ea61866d7314dfe722b53ac169b3454059d55b50caa46d699bea95584a5d177
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / spatialhub-0.1.5-py3-none-any.whl
| Download URL | spatialhub-0.1.5-py3-none-any.whl |
|---|---|
| Size | 2.0 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5938bca6f5bc16252e6c0dd6725252b5d84197dd6f33cd7e6eb86f202c2aaeac
|
|
BLAKE2b-256 checksum How to use checksums |
45d825f36ed86dfd47e3a12297dfa47d66e22136f790cf3cd0c0b5e37da84229
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|