Download code/eraser/infer_stack.py from SeongJoon/StackCube_simvla_spa_mirror_20261110: direct link, hf CLI and curl.
- Browser
- Download file 2.35 kB
-
https://huggingface.co/datasets/SeongJoon/StackCube_simvla_spa_mirror_20261110/resolve/main/code/eraser/infer_stack.py
- Command line
-
hf download hf://datasets/SeongJoon/StackCube_simvla_spa_mirror_20261110/code/eraser/infer_stack.py
-
curl -L -o infer_stack.py https://huggingface.co/datasets/SeongJoon/StackCube_simvla_spa_mirror_20261110/resolve/main/code/eraser/infer_stack.py
2.35 kB
| """SimVLA StackCube(xArm6, SPA 미러 학습) 체크포인트 추론. infer_eraser.EraserPolicy 와 같고 지시문 기본값만 StackCube 문장이다. | |
| from infer_stack import StackPolicy | |
| policy = StackPolicy("H/step030000", device="cuda") | |
| targets = policy.predict(top_rgb, wrist_rgb, front_rgb, xyz_mm, rpy_rad, gripper) # (16, 10) 절대 목표 | |
| xyz, rpy, grip = policy.to_xarm(targets) # (16,3) mm, (16,3) rad, (16,) -1 열기 / +1 닫기 | |
| 입력·출력 형식은 infer_eraser.py 설명과 같다 (카메라 top·wrist·front 순서 480x640 RGB, TCP xyz mm·RPY rad, 그리퍼 위치 353~801). | |
| 실행 확인: python infer_stack.py <ckpt_dir> [--device cuda] | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import os | |
| import sys | |
| import time | |
| import numpy as np | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| from infer_eraser import EraserPolicy # noqa: E402 | |
| TASK = "Pick up the yellow cube and stack it on the orange cube." | |
| class StackPolicy(EraserPolicy): | |
| def predict_state10(self, top_rgb, wrist_rgb, front_rgb, state10, task: str = TASK) -> np.ndarray: | |
| return super().predict_state10(top_rgb, wrist_rgb, front_rgb, state10, task) | |
| def predict(self, top_rgb, wrist_rgb, front_rgb, xyz_mm, rpy_rad, gripper, task: str = TASK) -> np.ndarray: | |
| return super().predict(top_rgb, wrist_rgb, front_rgb, xyz_mm, rpy_rad, gripper, task) | |
| def _check(ckpt, device): | |
| p = StackPolicy(ckpt, device=device) | |
| rng = np.random.default_rng(0) | |
| imgs = [rng.integers(0, 255, (480, 640, 3), dtype=np.uint8) for _ in range(3)] | |
| # 미러 데이터의 대표 자세: 오른쪽(y<0), 그리퍼가 수평으로 앞을 향함 (pitch 약 -86도), 그리퍼 열림 | |
| xyz, rpy, grip = [498.0, -184.0, 158.0], np.radians([-8.4, -85.8, -171.9]), 800.0 | |
| t0 = time.time(); tg = p.predict(*imgs, xyz, rpy, grip); dt = time.time() - t0 | |
| x, r, g = p.to_xarm(tg) | |
| print("목표", tg.shape, "첫 xyz", np.round(x[0], 1).tolist(), "rpy(도)", np.round(np.degrees(r[0]), 1).tolist(), | |
| "그리퍼", round(float(g[0]), 2), f"({dt:.2f}s)") | |
| assert np.isfinite(tg).all() | |
| print("OK") | |
| if __name__ == "__main__": | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("ckpt") | |
| ap.add_argument("--device", default="cuda") | |
| a = ap.parse_args() | |
| _check(a.ckpt, a.device) | |