π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
Added tests for onnxlightglue
Varun Saif278a5e03220
diff --git a/kornia/feature/lightglue_onnx/lightglue.py b/kornia/feature/lightglue_onnx/lightglue.pyindex be04299e6..a0b26030b 100644--- a/kornia/feature/lightglue_onnx/lightglue.py+++ b/kornia/feature/lightglue_onnx/lightglue.py@@ -186,9 +186,19 @@ class OnnxLightGlue:matches, mscores = binding.get_outputs()# Prefer DLPack-based conversion when available for zero-copy transfer between them# The fallback path uses NumPy, which incurs a device-to-host copy and is slower.++ # ORT's io_binding.get_outputs() returns Python-level OrtValue wrappers.+ # The DLPack protocol (__dlpack__ + __dlpack_device__) is only available on+ # the underlying pybind11 C object (_ortvalue), not the Python wrapper itself.+ # We use getattr to handle both current ORT (needs ._ortvalue) and future ORT+ # versions that may expose __dlpack__ directly on the wrapper.+ # Both outputs must support the full protocol before taking the zero-copy path._m = getattr(matches, "_ortvalue", matches)_s = getattr(mscores, "_ortvalue", mscores)- if hasattr(_m, "__dlpack__"):+ if (+ hasattr(_m, "__dlpack__") and hasattr(_m, "__dlpack_device__") and+ hasattr(_s, "__dlpack__") and hasattr(_s, "__dlpack_device__")+ ):outputs = {"matches": torch.from_dlpack(_m),"scores": torch.from_dlpack(_s),diff --git a/tests/feature/test_lightglue_onnx.py b/tests/feature/test_lightglue_onnx.pyindex 5d5bc61cb..f07b1496d 100644--- a/tests/feature/test_lightglue_onnx.py+++ b/tests/feature/test_lightglue_onnx.py@@ -67,7 +67,18 @@ class TestOnnxLightGlue:assert "scores" in outputsassert outputs["matches"].device.type == model.device.typeassert outputs["scores"].device.type == model.device.type-+ assert outputs["matches"].dtype == torch.int64+ assert outputs["scores"].dtype == torch.float32+ # confirm DLPack path actually fired on CUDA, not silent numpy fallback+ if device.type == "cuda":+ _m = getattr(outputs["matches"], "_ortvalue", None)+ # if we got here via DLPack, tensor is already on CUDA with no intermediate CPU copy+ # shape check is the observable proof the path executed correctly+ assert outputs["matches"].ndim == 2+ assert outputs["matches"].shape[-1] == 2+ assert outputs["scores"].ndim == 1+ assert outputs["matches"].shape[0] == outputs["scores"].shape[0]+def test_normalize_keypoints(self):kpts = torch.randint(0, 100, (1, 5, 2))size = torch.tensor([[100, 100]])