junaid-simamdigital commited on
Commit
ba4dc89
·
verified ·
1 Parent(s): 74b422f

eval: add depth dataset manifest runner

Browse files
Files changed (1) hide show
  1. evaluate_depth_dataset.py +66 -0
evaluate_depth_dataset.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Evaluate a JSONL manifest of paired Simam3D depth arrays."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import json
7
+ from pathlib import Path
8
+
9
+ import numpy as np
10
+
11
+ from evaluate_depth import evaluate_depth_pair
12
+
13
+
14
+ def evaluate_manifest(manifest_path: str | Path) -> dict[str, object]:
15
+ """Evaluate every manifest row and aggregate successful metric values."""
16
+ manifest_path = Path(manifest_path)
17
+ rows: list[dict[str, object]] = []
18
+ failures: list[dict[str, str]] = []
19
+ for line_number, raw_line in enumerate(manifest_path.read_text(encoding="utf-8").splitlines(), 1):
20
+ if not raw_line.strip() or raw_line.lstrip().startswith("#"):
21
+ continue
22
+ try:
23
+ record = json.loads(raw_line)
24
+ prediction_path = manifest_path.parent / str(record["prediction"])
25
+ ground_truth_path = manifest_path.parent / str(record["ground_truth"])
26
+ mask_path = record.get("mask")
27
+ mask = np.load(manifest_path.parent / str(mask_path)) if mask_path else None
28
+ report = evaluate_depth_pair(
29
+ np.load(prediction_path),
30
+ np.load(ground_truth_path),
31
+ mask,
32
+ bool(record.get("inverse_depth", False)),
33
+ )
34
+ rows.append({"id": record.get("id", f"line-{line_number}"), **report})
35
+ except (KeyError, OSError, ValueError, json.JSONDecodeError) as exc:
36
+ failures.append({"line": str(line_number), "error": f"{type(exc).__name__}: {exc}"})
37
+ if not rows:
38
+ raise ValueError("manifest produced no successful evaluation rows")
39
+ metric_names = ("abs_rel", "sq_rel", "rmse", "rmse_log", "delta1", "delta2", "delta3")
40
+ aggregate = {
41
+ name: {
42
+ "mean": float(np.mean([row["median_scaled"][name] for row in rows])),
43
+ "median": float(np.median([row["median_scaled"][name] for row in rows])),
44
+ }
45
+ for name in metric_names
46
+ }
47
+ return {
48
+ "project": "Simam3D",
49
+ "manifest": str(manifest_path),
50
+ "successful_rows": len(rows),
51
+ "failed_rows": failures,
52
+ "aggregate_median_scaled": aggregate,
53
+ "rows": rows,
54
+ }
55
+
56
+
57
+ def main(argv: list[str] | None = None) -> int:
58
+ parser = argparse.ArgumentParser(description=__doc__)
59
+ parser.add_argument("manifest", type=Path, help="JSONL depth-pair manifest")
60
+ args = parser.parse_args(argv)
61
+ print(json.dumps(evaluate_manifest(args.manifest), indent=2))
62
+ return 0
63
+
64
+
65
+ if __name__ == "__main__":
66
+ raise SystemExit(main())