test: cover depth evaluation metrics
Browse files- tests/test_evaluate_depth.py +40 -0
tests/test_evaluate_depth.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from evaluate_depth import depth_metrics, evaluate_depth_pair
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def test_depth_metrics_reports_perfect_prediction():
|
| 7 |
+
depth = np.array([[1.0, 2.0], [3.0, 4.0]])
|
| 8 |
+
metrics = depth_metrics(depth, depth)
|
| 9 |
+
assert metrics["valid_pixel_count"] == 4
|
| 10 |
+
assert metrics["abs_rel"] == 0.0
|
| 11 |
+
assert metrics["rmse"] == 0.0
|
| 12 |
+
assert metrics["delta1"] == 1.0
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def test_depth_pair_separates_relative_scale_from_raw_error():
|
| 16 |
+
ground_truth = np.array([[1.0, 2.0], [3.0, 4.0]])
|
| 17 |
+
prediction = ground_truth * 7.0
|
| 18 |
+
report = evaluate_depth_pair(prediction, ground_truth)
|
| 19 |
+
assert report["raw"]["abs_rel"] > 5.0
|
| 20 |
+
assert report["median_scaled"]["rmse"] < 1e-12
|
| 21 |
+
assert abs(report["median_scale"] - 1.0 / 7.0) < 1e-12
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def test_inverse_depth_option_converts_before_scoring():
|
| 25 |
+
ground_truth = np.array([[1.0, 2.0], [4.0, 8.0]])
|
| 26 |
+
report = evaluate_depth_pair(1.0 / ground_truth, ground_truth, prediction_is_inverse_depth=True)
|
| 27 |
+
assert report["raw"]["rmse"] < 1e-12
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def test_depth_metrics_respects_mask_and_rejects_shape_mismatch():
|
| 31 |
+
prediction = np.array([[1.0, 2.0], [30.0, 40.0]])
|
| 32 |
+
ground_truth = np.array([[1.0, 2.0], [3.0, 4.0]])
|
| 33 |
+
mask = np.array([[True, True], [False, False]])
|
| 34 |
+
assert depth_metrics(prediction, ground_truth, mask)["valid_pixel_count"] == 2
|
| 35 |
+
try:
|
| 36 |
+
depth_metrics(prediction, ground_truth, np.ones((1, 1), dtype=bool))
|
| 37 |
+
except ValueError as exc:
|
| 38 |
+
assert "valid_mask" in str(exc)
|
| 39 |
+
else:
|
| 40 |
+
raise AssertionError("shape mismatch should fail")
|