Download scripts/build_train_sets.py from Kyry10/rfcp-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.92 kB
-
https://huggingface.co/datasets/Kyry10/rfcp-dataset/resolve/main/scripts/build_train_sets.py
- Command line
-
hf download hf://datasets/Kyry10/rfcp-dataset/scripts/build_train_sets.py
-
curl -L -o build_train_sets.py https://huggingface.co/datasets/Kyry10/rfcp-dataset/resolve/main/scripts/build_train_sets.py
1.92 kB
| """Build Ghost04 train sets from one motion + the 30 controls (unique file names AND unique top-level keys). | |
| A = <motion> only (1 file) | |
| B = 30 controls + 14 copies of <motion> | |
| B2 = 30 controls + 25 copies of <motion> | |
| usage: python build_train_sets.py <data_dir> <motion> (expects <data_dir>/<motion>_pkl/**/<motion>.pkl and <data_dir>/controls/*.pkl) | |
| Used with motion=m7 (raw m7; the m7_v2 foot fix failed the float check at sigma 0.2 s).""" | |
| import glob, json, os, shutil, sys | |
| import joblib, numpy as np | |
| D, MOT = sys.argv[1], sys.argv[2] | |
| src = glob.glob(f"{D}/{MOT}_pkl/**/{MOT}.pkl", recursive=True); assert len(src) == 1, src | |
| k, m = list(joblib.load(src[0]).items())[0] | |
| assert m["fps"] == 30 and m["dof"].shape[1] == 29 and all(x in m for x in ["root_trans_offset", "root_rot", "dof", "fps"]) | |
| assert all(np.isfinite(v).all() for v in m.values() if hasattr(v, "shape")) | |
| ctrl = sorted(glob.glob(f"{D}/controls/*.pkl")); assert len(ctrl) == 30, len(ctrl) | |
| summary = {"motion": MOT, "source_pkl": src[0]} | |
| for name, copies in (("train_A", 0), ("train_B", 14), ("train_B2", 25)): | |
| out = f"{D}/{name}"; os.makedirs(out, exist_ok=True) | |
| assert not glob.glob(out + "/*.pkl"), f"{out} not empty" | |
| if name == "train_A": | |
| joblib.dump({MOT: m}, f"{out}/{MOT}.pkl", compress=True) | |
| else: | |
| for f in ctrl: shutil.copy(f, out) | |
| for i in range(copies): joblib.dump({f"{MOT}_c{i:02d}": m}, f"{out}/{MOT}_c{i:02d}.pkl", compress=True) | |
| files = sorted(glob.glob(out + "/*.pkl")); keys = [list(joblib.load(f).keys())[0] for f in files] | |
| assert len(set(keys)) == len(keys) == len(files) | |
| n7 = sum(x == MOT or x.startswith(MOT + "_c") for x in keys) | |
| summary[name] = {"files": len(files), "motion_copies": n7, "controls": len(files) - n7, "motion_share_pct": round(100 * n7 / len(files), 1)} | |
| print(json.dumps(summary)); json.dump(summary, open(f"{D}/train_sets_summary.json", "w"), indent=2) | |