Skip to main content

SpatialHub

PyPI version Documentation Python 3.12+ License

A spatial AI and perception library providing unified ONNX Runtime inference adapters for computer vision and 3D spatial computing models.


Motivation & Architecture

3D spatial vision systems (such as 6D object pose estimation, Visual SLAM, and 3D reconstruction) are multi-stage pipelines composed of representation learning, geometric matching, depth prediction, proposal segmentation, and pose optimization.

In practice, integrating multiple vision models into a unified pipeline presents practical challenges:

  • Interface Variations: Models differ in coordinate conventions, dictionary formats, and output tensor dimensions.
  • Environment Conflicts: Combining distinct model implementations often introduces dependency conflicts and heavy runtime footprints.

SpatialHub addresses this by providing standardized dataclass returns over a unified ONNX Runtime execution layer:

Sensor & Asset Inputs                   Perception Adapters (ONNX)          Standardized Dataclasses
─────────────────────────────────      ─────────────────────────────       ─────────────────────────
Single RGB Image                  ───►  DINOv2 (Feature Extraction)   ───►  FeatureExtractionResult
Image Pair                        ───►  EfficientLoFTR (Matching)     ───►  MatchResult
RGB Images + Intrinsics (K)       ───►  Depth Anything 3 (Depth)      ───►  DepthPredictionResult
RGB Image + CAD Mesh (.ply)       ───►  FastSAM / SAM / CNOS (Masks)  ───►  SegmentationResult
RGB-D + Intrinsics (K) + CAD Mesh ───►  FoundationPose (6D Pose)      ───►  PoseEstimationResult
                                                                                    │
                                                                                    ▼
Downstream Systems (Visual SLAM, 3D Reconstruction, Robotics Manipulation)

Downstream spatial algorithms operate on these return types, allowing models to be interchanged without modifying downstream pipeline logic.


Key Principles

  • Standardized Return Contracts: Dataclass structures across model families (MatchResult, DepthPredictionResult, FeatureExtractionResult, SegmentationResult, PoseEstimationResult).
  • ONNX Runtime Execution: Inference executes via ONNX Runtime with NumPy and OpenCV vector operations.
  • Model Weight Resolution: Automatically fetches and caches .onnx weight files from Hugging Face Hub.
  • Hardware Acceleration: Supports CPU, CUDA, and TensorRT execution providers.
  • Offscreen Rendering Utilities: Headless G-buffer and batched atlas renderer for CAD mesh template matching and 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 Docs • README
EfficientLoFTR Semi-dense Feature Matching "full" or "opt" MatchResult Docs • README
Depth Anything 3 Monocular & Multi-View Depth "da3_base" (small/large/giant/metric/nested) DepthPredictionResult Docs • README
DINOv2 Image Feature Extraction "vitl14" (vits14/vitb14/vitg14) FeatureExtractionResult Docs • README
FastSAM Real-Time Proposal Segmentation "x" or "s" SegmentationResult Docs • README
SAM Automatic Mask Generation (AMG) "vit_h" (vit_l/vit_b) SegmentationResult Docs • README
CNOS CAD Zero-Shot Object Detection 3D CAD Mesh (.ply, .obj, .stl) SegmentationResult Docs • README

Installation

Requires Python 3.12+. Choose the installation for your hardware setup:

Standard Installation

For CPU inference:

pip install "spatialhub[cpu]"

For NVIDIA GPU acceleration (CUDA / TensorRT):

pip install "spatialhub[gpu]"

3D CAD & Rendering Installation

For workflows requiring 3D CAD mesh loading and template rendering (e.g. FoundationPose, CNOS):

For CPU with rendering:

pip install "spatialhub[cpu,render]"

For GPU with rendering:

pip install "spatialhub[gpu,render]"

Quickstart

from spatialhub import FoundationPose, EfficientLoFTR, DepthAnything3, DINOv2, FastSAM, SAM, CNOS

# 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")

# 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")

# 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])

# Feature Extraction (DINOv2)
dino = DINOv2(model_variant="vitl14")
feat_res = dino.extract_features("image.png", l2_normalize=True)

# Proposal Segmentation (FastSAM)
fastsam = FastSAM(model_variant="x")
seg_res = fastsam.generate_masks("scene.png", conf_threshold=0.3)
seg_res.visualize_mask(save_path="fastsam_masks.png")

ONNX Export

Export scripts for generating .onnx models from source repositories are located under tools/export/:

uv run tools/export/export_efficient_loftr.py --checkpoint weights/eloftr_outdoor.ckpt --output-folder onnx_weight

See the ONNX Export Guide for options and details.


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.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spatialhub 0.1.6
File Size Uploaded
spatialhub-0.1.6.tar.gz 299.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for spatialhub 0.1.6
File Interpreter ABI Platform
spatialhub-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 490.6 kB

Release files / spatialhub-0.1.6.tar.gz

Download URL spatialhub-0.1.6.tar.gz
Size 299.7 kB
Tags Source
SHA-256 checksum
How to use checksums
681a65d0254d1c038815126cb743d7b3f0a460f95f2718d7b26f1c94167d30a4
BLAKE2b-256 checksum
How to use checksums
18cd382d49336ce1ea8be0540a0354286646e4a03a428e195ad08d1cb9b58073
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.6-py3-none-any.whl

Download URL spatialhub-0.1.6-py3-none-any.whl
Size 191.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
54e3b7f9369acee5b354d17358f45d1159c5ff33b6c8ef3d8386e57d086ed541
BLAKE2b-256 checksum
How to use checksums
92a187d330f2c93d92236692b4d5e02010b9cd441e6604e06e48dbf32ef1a989
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 history Release notifications | RSS feed

This release

0.1.6 This release

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page