File size: 3,500 Bytes
208faa0 | 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 | """Smoke-check raw + depth layout for coaf_dataset_24_25."""
from __future__ import annotations
import argparse
import json
import sys
from pathlib import Path
import cv2
import numpy as np
SCRIPT_DIR = Path(__file__).resolve().parent
sys.path.insert(0, str(SCRIPT_DIR))
from sampling import RGB_FRAMES, REASON_FRAMES
DATASET_ROOT = Path("/project/llmsvgen/sunkai/robomaster_3d/Casual_CoAF/coaf_dataset_24_25")
def check_episode(ep_dir: Path, check_depth: bool) -> list[str]:
errors = []
ep_name = ep_dir.name
for sub, n in (("rgb", RGB_FRAMES), ("rgb_align", REASON_FRAMES)):
d = ep_dir / sub
if not d.is_dir():
errors.append(f"{ep_name}: missing {sub}/")
continue
for i in range(1, n + 1):
if not (d / f"frame_{i:04d}.png").exists():
errors.append(f"{ep_name}: missing {sub}/frame_{i:04d}.png")
break
state_path = ep_dir / "state" / "state.npy"
action_path = ep_dir / "action" / "action.npy"
if not state_path.exists():
errors.append(f"{ep_name}: missing state.npy")
else:
state = np.load(state_path)
if state.shape != (REASON_FRAMES, 7):
errors.append(f"{ep_name}: state shape {state.shape}")
if not action_path.exists():
errors.append(f"{ep_name}: missing action.npy")
else:
action = np.load(action_path)
if action.shape != (REASON_FRAMES, 7):
errors.append(f"{ep_name}: action shape {action.shape}")
manifest_path = ep_dir / "manifest.json"
if not manifest_path.exists():
errors.append(f"{ep_name}: missing manifest.json")
else:
manifest = json.loads(manifest_path.read_text())
if len(manifest.get("reason_indices", [])) != REASON_FRAMES:
errors.append(f"{ep_name}: bad reason_indices length")
if len(manifest.get("rgb_indices", [])) != RGB_FRAMES:
errors.append(f"{ep_name}: bad rgb_indices length")
if check_depth:
depth_mp4 = DATASET_ROOT / "modalities" / "depth" / ep_name / "depth.mp4"
if not depth_mp4.exists():
errors.append(f"{ep_name}: missing depth.mp4")
else:
cap = cv2.VideoCapture(str(depth_mp4))
n = 0
while True:
ret, _ = cap.read()
if not ret:
break
n += 1
cap.release()
if n != REASON_FRAMES:
errors.append(f"{ep_name}: depth.mp4 has {n} frames, expected {REASON_FRAMES}")
return errors
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--start", type=int, default=0)
parser.add_argument("--stop", type=int, default=5000)
parser.add_argument("--check-depth", action="store_true")
args = parser.parse_args()
raw_root = DATASET_ROOT / "raw"
all_errors = []
checked = 0
for idx in range(args.start, args.stop):
ep_dir = raw_root / f"episode_{idx:06d}"
if not ep_dir.exists():
all_errors.append(f"episode_{idx:06d}: raw dir missing")
continue
all_errors.extend(check_episode(ep_dir, args.check_depth))
checked += 1
if all_errors:
print("FAILED:")
for e in all_errors:
print(f" - {e}")
raise SystemExit(1)
print(f"OK: {checked} episodes verified"
f"{' (with depth)' if args.check_depth else ''}")
if __name__ == "__main__":
main()
|