Spaces:
Paused
Paused
Centralize and test DA3 output contract normalization
Browse files- tests/test_core.py +26 -0
tests/test_core.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import numpy as np
|
| 2 |
from pathlib import Path
|
|
|
|
| 3 |
|
| 4 |
from simam3d_core import (
|
| 5 |
analyze_light_field,
|
|
@@ -12,6 +13,7 @@ from simam3d_core import (
|
|
| 12 |
fusion_metrics,
|
| 13 |
gaussian_initialization,
|
| 14 |
normalize_map,
|
|
|
|
| 15 |
next_view_plan,
|
| 16 |
orbit_project_points,
|
| 17 |
prepare_intrinsics,
|
|
@@ -85,6 +87,30 @@ def test_orbit_projection_rotates_points_without_nan():
|
|
| 85 |
assert np.all(np.abs(xy) <= 1.0)
|
| 86 |
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
def test_normalize_map_handles_constant_and_nan_values():
|
| 89 |
assert np.all(normalize_map(np.ones((2, 2))) == 0)
|
| 90 |
normalized = normalize_map(np.array([[np.nan, 1.0], [2.0, 3.0]], dtype=np.float32))
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
from pathlib import Path
|
| 3 |
+
from types import SimpleNamespace
|
| 4 |
|
| 5 |
from simam3d_core import (
|
| 6 |
analyze_light_field,
|
|
|
|
| 13 |
fusion_metrics,
|
| 14 |
gaussian_initialization,
|
| 15 |
normalize_map,
|
| 16 |
+
normalize_prediction_contract,
|
| 17 |
next_view_plan,
|
| 18 |
orbit_project_points,
|
| 19 |
prepare_intrinsics,
|
|
|
|
| 87 |
assert np.all(np.abs(xy) <= 1.0)
|
| 88 |
|
| 89 |
|
| 90 |
+
def test_prediction_contract_normalizes_single_view_and_optional_fields():
|
| 91 |
+
prediction = SimpleNamespace(depth=np.ones((4, 5), dtype=np.float32), conf=None)
|
| 92 |
+
depth, confidence, extrinsics, intrinsics, confidence_source, pose_source = normalize_prediction_contract(prediction, 1)
|
| 93 |
+
assert depth.shape == (1, 4, 5)
|
| 94 |
+
assert confidence.shape == depth.shape
|
| 95 |
+
assert extrinsics.shape == (1, 4, 4)
|
| 96 |
+
assert intrinsics.shape == (1, 3, 3)
|
| 97 |
+
assert confidence_source == "baseline_uniform"
|
| 98 |
+
assert pose_source == "synthetic_orbit_prior"
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def test_prediction_contract_rejects_mismatched_confidence():
|
| 102 |
+
prediction = SimpleNamespace(
|
| 103 |
+
depth=np.ones((2, 4, 5), dtype=np.float32),
|
| 104 |
+
conf=np.ones((1, 4, 5), dtype=np.float32),
|
| 105 |
+
)
|
| 106 |
+
try:
|
| 107 |
+
normalize_prediction_contract(prediction, 2)
|
| 108 |
+
except ValueError as exc:
|
| 109 |
+
assert "confidence" in str(exc)
|
| 110 |
+
else:
|
| 111 |
+
raise AssertionError("mismatched DA3 confidence should be rejected")
|
| 112 |
+
|
| 113 |
+
|
| 114 |
def test_normalize_map_handles_constant_and_nan_values():
|
| 115 |
assert np.all(normalize_map(np.ones((2, 2))) == 0)
|
| 116 |
normalized = normalize_map(np.array([[np.nan, 1.0], [2.0, 3.0]], dtype=np.float32))
|