import json from pathlib import Path from collections import Counter ROOT = Path(r"C:\AI\dataset_factory\dataset_farming\game\top6") DATASET = ROOT / "metadata_final" / "dataset.jsonl" REPORT = ROOT / "metadata_final" / "validation_report.json" ACTIONS = { "move_left": (-0.25, 0.0, 0.0), "move_right": (0.25, 0.0, 0.0), "move_forward": (0.0, 0.25, 0.0), "move_backward": (0.0, -0.25, 0.0), "interact": (0.0, 0.0, 0.0), "noop": (0.0, 0.0, 0.0), } def q(x): return round(float(x), 5) rows = [ json.loads(x) for x in DATASET.read_text(encoding="utf-8").splitlines() if x.strip() ] ids = set() actions = Counter() splits = Counter() for r in rows: rid = r["id"] if rid in ids: raise ValueError(f"duplicate id {rid}") ids.add(rid) rgb = ROOT / r["rgb_file"] mask = ROOT / r["mask_file"] if not rgb.exists() or rgb.stat().st_size == 0: raise ValueError(f"bad rgb {rid}") if not mask.exists() or mask.stat().st_size == 0: raise ValueError(f"bad mask {rid}") if r["action"] not in ACTIONS: raise ValueError(f"bad action {rid}") t = r["state_t0"]["target"] bbox = t["bbox_xyxy"] if ( not isinstance(bbox, list) or len(bbox) != 4 or not all(isinstance(x, int) for x in bbox) ): raise ValueError(f"bad bbox {rid}") x, y, z = t["position"] dx, dy, dz = ACTIONS[r["action"]] expected = [ q(x + dx), q(y + dy), q(z + dz) ] if r["expected_target_position_t1"] != expected: raise ValueError(f"oracle mismatch {rid}") if t["camera_depth"] <= 0: raise ValueError(f"bad camera depth {rid}") if t["camera_distance"] <= 0: raise ValueError(f"bad camera distance {rid}") actions[r["action"]] += 1 splits[r["split"]] += 1 report = { "status": "PASS", "validated": len(rows), "unique_ids": len(ids), "actions": dict(actions), "splits": dict(splits) } REPORT.write_text( json.dumps(report, indent=2), encoding="utf-8" ) print(json.dumps(report))