File size: 2,114 Bytes
540706c | 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 | 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))
|