File size: 4,461 Bytes
cb8518a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | from __future__ import annotations
import importlib.util
import json
import sys
import tempfile
import unittest
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parents[1]
def _load_script_module():
script_path = PROJECT_ROOT / "scripts" / "run_parallel_eval.py"
spec = importlib.util.spec_from_file_location("run_parallel_eval", script_path)
if spec is None or spec.loader is None:
raise RuntimeError("Unable to load run_parallel_eval module")
mod = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = mod
spec.loader.exec_module(mod)
return mod
class TestParallelEvalHelpers(unittest.TestCase):
def test_load_track_manifest_sample_ids_reads_jsonl(self) -> None:
mod = _load_script_module()
with tempfile.TemporaryDirectory() as tmp:
manifest = Path(tmp) / "dynamic.jsonl"
manifest.write_text(
"\n".join(
[
json.dumps({"id": "case_a_f0001"}),
json.dumps({"sample_id": "case_a_f0055"}),
"",
json.dumps({"id": "case_b_f0001"}),
]
)
+ "\n",
encoding="utf-8",
)
self.assertEqual(
mod.load_track_manifest_sample_ids(manifest),
{"case_a_f0001", "case_a_f0055", "case_b_f0001"},
)
def test_track_manifest_frame_selects_exact_geometry_frame(self) -> None:
mod = _load_script_module()
with tempfile.TemporaryDirectory() as tmp:
manifest = Path(tmp) / "dynamic.jsonl"
manifest.write_text(
json.dumps({"id": "case_a_f0055", "frame": 55}) + "\n",
encoding="utf-8",
)
self.assertEqual(
mod.load_track_manifest_modes(manifest, "first_only"),
{"case_a_f0055": "exact:55"},
)
def test_collect_samples_requires_every_requested_model(self) -> None:
mod = _load_script_module()
with tempfile.TemporaryDirectory() as tmp:
data = Path(tmp) / "data"
(data / "gt" / "s1").mkdir(parents=True)
(data / "gt" / "s1" / "scene.blend").write_bytes(b"blend")
(data / "model_a" / "s1").mkdir(parents=True)
(data / "model_a" / "s1" / "scene.glb").write_bytes(b"glb")
with self.assertRaises(FileNotFoundError):
mod.collect_samples(data, ["model_a", "model_b"], None, "first_only")
self.assertEqual(
mod.collect_samples(
data,
["model_a", "model_b"],
None,
"first_only",
allow_missing_models=True,
),
[("s1", "first_only")],
)
def test_aggregate_reports_paper_scale_and_complete_coverage(self) -> None:
mod = _load_script_module()
with tempfile.TemporaryDirectory() as tmp:
out = Path(tmp)
report = out / "s1" / "reports" / "final_report.json"
report.parent.mkdir(parents=True)
report.write_text(
json.dumps(
{
"summary": [
{
"model": "model_a",
"scene_aabb_iou_mean": 0.1,
"scene_obb_iou_mean": 0.2,
"object_aabb_iou_penalized_mean": 0.3,
"object_obb_iou_penalized_mean": 0.4,
"rendered_pl_score_100": 95.0,
"rendered_n_clip_score_100": 80.0,
"rendered_pl_raw": 0.05,
"rendered_n_clip_raw": 0.2,
}
]
}
),
encoding="utf-8",
)
payload = mod.aggregate(out, [("s1", "first_only")], ["model_a"])
result = payload["results"]["model_a"]
self.assertTrue(payload["complete"])
self.assertEqual(result["coverage"], 1.0)
self.assertAlmostEqual(result["pl"], 5.0)
self.assertAlmostEqual(result["n_clip"], 2.0)
if __name__ == "__main__":
unittest.main()
|