File size: 8,186 Bytes
6b11150 | 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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | #!/usr/bin/env python3
"""Batch runner for classification probe milestones."""
from __future__ import annotations
import argparse
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent
PY = sys.executable
# Prefer ACP /data/share, else Himacon /share (override with LABEL_ROOT / VIDEO_ROOT)
sys.path.insert(0, str(ROOT))
from path_detect import detect_share_roots # noqa: E402
_label, _video = detect_share_roots()
LABEL_ROOT = str(_label)
VIDEO_ROOT = str(_video)
OUT = ROOT / "outputs" / "classification_probe"
TASK = "blocks_ranking_rgb"
DEMOS = ["demo_clean_100_arx", "demo_clean_100_franka", "demo_clean_100_ur5"]
def run(cmd: list[str]) -> None:
print("+", " ".join(cmd), flush=True)
subprocess.run(cmd, check=True, cwd=str(ROOT))
def smoke(n_episodes: int = 5, n_splits: int = 2) -> None:
demo = "demo_clean_100_franka"
run([
PY, "classification_probe.py", "propose-primitive-labels",
"--task", TASK, "--demo", demo,
"--label-root", LABEL_ROOT, "--video-root", VIDEO_ROOT,
"--annotation-root", str(OUT), "--max-episodes", str(n_episodes),
])
for label_kind in ("full_label", "womae_label"):
out = OUT / "within_robot" / TASK / demo / f"{label_kind}_val0_960"
run([
PY, "classification_probe.py", "fit-cv",
"--task", TASK, "--demo", demo, "--label-kind", label_kind,
"--label-root", LABEL_ROOT, "--video-root", VIDEO_ROOT,
"--annotation-root", str(OUT), "--output-dir", str(out),
"--n-splits", str(n_splits), "--seed", "42",
])
run([
PY, "classification_probe.py", "viz-temporal",
"--task", TASK, "--label-kind", "full_label",
"--label-root", LABEL_ROOT, "--video-root", VIDEO_ROOT,
"--annotation-root", str(OUT),
"--output-dir", str(OUT / "visualization" / "smoke"),
"--train-demo", demo, "--eval-demo", demo,
"--source-episode", "0", "--target-episode", "0",
"--model-path", str(OUT / "within_robot" / TASK / demo / "full_label_val0_960" / "checkpoints" / "model_all_episodes.joblib"),
])
def train(n_episodes: int = 100, n_splits: int = 10) -> None:
"""Train/eval on existing annotations (no proposal step)."""
run([
PY, "classification_probe.py", "check-distribution",
"--task", TASK, "--annotation-root", str(OUT),
"--output-dir", str(OUT / "summary"),
])
for demo in DEMOS:
for label_kind in ("full_label", "womae_label"):
out = OUT / "within_robot" / TASK / demo / f"{label_kind}_val0_960"
run([
PY, "classification_probe.py", "fit-cv",
"--task", TASK, "--demo", demo, "--label-kind", label_kind,
"--label-root", LABEL_ROOT, "--video-root", VIDEO_ROOT,
"--annotation-root", str(OUT), "--output-dir", str(out),
"--n-splits", str(n_splits), "--seed", "42", "--max-episodes", str(n_episodes),
])
run([
PY, "classification_probe.py", "fit-time-baseline",
"--task", TASK, "--demo", demo, "--label-kind", label_kind,
"--label-root", LABEL_ROOT, "--video-root", VIDEO_ROOT,
"--annotation-root", str(OUT),
"--n-splits", str(n_splits), "--seed", "42", "--max-episodes", str(n_episodes),
])
run([
PY, "classification_probe.py", "fit-majority-baseline",
"--task", TASK, "--demo", demo, "--label-kind", label_kind,
"--label-root", LABEL_ROOT, "--video-root", VIDEO_ROOT,
"--annotation-root", str(OUT),
"--n-splits", str(n_splits), "--seed", "42", "--max-episodes", str(n_episodes),
])
cross_out = OUT / "cross_robot" / TASK
run([
PY, "classification_probe.py", "fit-cross-robot",
"--task", TASK, "--label-root", LABEL_ROOT, "--video-root", VIDEO_ROOT,
"--annotation-root", str(OUT), "--output-dir", str(cross_out),
"--max-episodes", str(n_episodes),
])
run([
PY, "classification_probe.py", "summarize",
"--task", TASK, "--label-root", LABEL_ROOT, "--video-root", VIDEO_ROOT,
"--annotation-root", str(OUT), "--max-episodes", str(n_episodes),
])
def pilot(n_episodes: int = 20, n_splits: int = 5) -> None:
run([
PY, "classification_probe.py", "propose-primitive-labels",
"--task", TASK, "--demos", *DEMOS,
"--label-root", LABEL_ROOT, "--video-root", VIDEO_ROOT,
"--annotation-root", str(OUT), "--max-episodes", str(n_episodes),
])
run([
PY, "classification_probe.py", "check-distribution",
"--task", TASK, "--annotation-root", str(OUT),
"--output-dir", str(OUT / "summary"),
])
for demo in DEMOS:
for label_kind in ("full_label", "womae_label"):
out = OUT / "within_robot" / TASK / demo / f"{label_kind}_val0_960"
run([
PY, "classification_probe.py", "fit-cv",
"--task", TASK, "--demo", demo, "--label-kind", label_kind,
"--label-root", LABEL_ROOT, "--video-root", VIDEO_ROOT,
"--annotation-root", str(OUT), "--output-dir", str(out),
"--n-splits", str(n_splits), "--seed", "42", "--max-episodes", str(n_episodes),
])
run([
PY, "classification_probe.py", "fit-time-baseline",
"--task", TASK, "--demo", demo, "--label-kind", label_kind,
"--label-root", LABEL_ROOT, "--video-root", VIDEO_ROOT,
"--annotation-root", str(OUT),
"--n-splits", str(n_splits), "--seed", "42", "--max-episodes", str(n_episodes),
])
run([
PY, "classification_probe.py", "fit-majority-baseline",
"--task", TASK, "--demo", demo, "--label-kind", label_kind,
"--label-root", LABEL_ROOT, "--video-root", VIDEO_ROOT,
"--annotation-root", str(OUT),
"--n-splits", str(n_splits), "--seed", "42", "--max-episodes", str(n_episodes),
])
cross_out = OUT / "cross_robot" / TASK
run([
PY, "classification_probe.py", "fit-cross-robot",
"--task", TASK, "--label-root", LABEL_ROOT, "--video-root", VIDEO_ROOT,
"--annotation-root", str(OUT), "--output-dir", str(cross_out),
"--max-episodes", str(n_episodes),
])
run([
PY, "classification_probe.py", "viz-tsne",
"--task", TASK, "--label-kind", "full_label",
"--label-root", LABEL_ROOT, "--video-root", VIDEO_ROOT,
"--annotation-root", str(OUT),
"--output-dir", str(OUT / "visualization"),
"--demos", *DEMOS, "--max-episodes", str(n_episodes),
])
run([
PY, "classification_probe.py", "summarize",
"--task", TASK, "--label-root", LABEL_ROOT, "--video-root", VIDEO_ROOT,
"--annotation-root", str(OUT), "--max-episodes", str(n_episodes),
])
def final(n_episodes: int = 100, n_splits: int = 10) -> None:
run([
PY, "classification_probe.py", "propose-primitive-labels",
"--task", TASK, "--demos", *DEMOS,
"--label-root", LABEL_ROOT, "--video-root", VIDEO_ROOT,
"--annotation-root", str(OUT), "--max-episodes", str(n_episodes),
])
pilot(n_episodes=n_episodes, n_splits=n_splits)
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("stage", choices=["smoke", "pilot", "final", "train"])
parser.add_argument("--n-episodes", type=int, default=None)
parser.add_argument("--n-splits", type=int, default=None)
args = parser.parse_args()
OUT.mkdir(parents=True, exist_ok=True)
if args.stage == "smoke":
smoke(args.n_episodes or 5, args.n_splits or 2)
elif args.stage == "pilot":
pilot(args.n_episodes or 20, args.n_splits or 5)
elif args.stage == "train":
train(args.n_episodes or 100, args.n_splits or 10)
else:
final(args.n_episodes or 100, args.n_splits or 10)
if __name__ == "__main__":
main()
|