Download benchmark/common.py from Tinghong-Ye22/code-HFD: direct link, hf CLI and curl.
- Browser
- Download file 2.11 kB
-
https://huggingface.co/Tinghong-Ye22/code-HFD/resolve/main/benchmark/common.py
- Command line
-
hf download hf://Tinghong-Ye22/code-HFD/benchmark/common.py
-
curl -L -o common.py https://huggingface.co/Tinghong-Ye22/code-HFD/resolve/main/benchmark/common.py
2.11 kB
| """HFD adapters; metric definitions remain in the read-only OmniHM evaluator.""" | |
| from pathlib import Path | |
| import hashlib | |
| import json | |
| import os | |
| import numpy as np | |
| from scipy.spatial.transform import Rotation, Slerp | |
| ROOT = Path(__file__).resolve().parents[1] | |
| WORK = Path(__file__).resolve().parent | |
| WORKSPACE = ROOT.parents[2] | |
| PEER = WORKSPACE / "buwendong/user/code" | |
| OMNI = WORK / "vendor/OmniHM_bench" | |
| OMG = WORK / "vendor/OMG" | |
| EVALUATOR = WORK / "vendor/evaluator_v13.pt" | |
| DEFAULT_RUN = ROOT / "runs/posttrain_full_duplex/hfd.gpus4.2610100010-thirdparty" | |
| # Identical to HFD's SONIC renderer: IsaacLab breadth-first -> MuJoCo tree order. | |
| ISAAC_TO_MUJOCO = [0,3,6,9,13,17,1,4,7,10,14,18,2,5,8,11,15,19,21,23,25,27,12,16,20,22,24,26,28] | |
| def sha256(path): | |
| h = hashlib.sha256() | |
| with Path(path).open('rb') as f: | |
| for chunk in iter(lambda: f.read(8*1024*1024), b''): | |
| h.update(chunk) | |
| return h.hexdigest() | |
| def write_json(path, value): | |
| path = Path(path) | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| tmp = path.with_suffix(path.suffix + f'.{os.getpid()}.tmp') | |
| tmp.write_text(json.dumps(value, ensure_ascii=False, indent=2, allow_nan=False)+'\n') | |
| tmp.replace(path) | |
| def qpos_from_absolute(motion, source_fps=50., target_fps=30.): | |
| """No heading/height correction, smoothing, temporal warp or GT alignment.""" | |
| motion = np.asarray(motion, np.float64) | |
| if motion.ndim != 2 or motion.shape[1] != 36 or len(motion) < 4 or not np.isfinite(motion).all(): | |
| raise ValueError('Expected finite HFD physical absolute [T,36]') | |
| quat = motion[:, 32:36] | |
| if not np.allclose(np.linalg.norm(quat, axis=1), 1., atol=5e-3): | |
| raise ValueError('Non-unit wxyz quaternion') | |
| old = np.arange(len(motion)) / source_fps | |
| new = np.arange(int(np.floor(old[-1]*target_fps))+1) / target_fps | |
| linear = np.stack([np.interp(new, old, motion[:, i]) for i in range(32)], -1) | |
| rot = Slerp(old, Rotation.from_quat(quat[:, [1,2,3,0]]))(new).as_quat()[:, [3,0,1,2]] | |
| return np.concatenate([linear[:,29:32], rot, linear[:, ISAAC_TO_MUJOCO]], -1).astype(np.float32) | |