| """ |
| T3: Inject canonical_names into all skeleton.npz files. |
| |
| Adds a 'canonical_names' field parallel to 'joint_names' in every |
| skeleton.npz across all datasets. |
| """ |
|
|
| import sys |
| import os |
| from pathlib import Path |
| import numpy as np |
|
|
| project_root = Path(__file__).parent.parent |
| sys.path.insert(0, str(project_root)) |
|
|
| from src.data.canonical_names import get_canonical_names, CANONICAL_MAPS |
| from src.data.zoo_canonical_names import get_zoo_canonical_names |
|
|
|
|
| def inject_skeleton(npz_path: Path, dataset_id: str, is_zoo: bool = False): |
| """Add canonical_names to a skeleton.npz file.""" |
| data = dict(np.load(npz_path, allow_pickle=True)) |
| raw_names = [str(n) for n in data['joint_names']] |
|
|
| if is_zoo: |
| canonical = get_zoo_canonical_names(raw_names) |
| else: |
| canonical = get_canonical_names(raw_names, dataset_id) |
|
|
| data['canonical_names'] = np.array(canonical) |
| np.savez(npz_path, **data) |
| return canonical |
|
|
|
|
| def main(): |
| base = project_root / 'data' / 'processed' |
|
|
| |
| human_datasets = ['humanml3d', 'lafan1', '100style', 'bandai_namco', 'cmu_mocap', 'mixamo'] |
| for ds in human_datasets: |
| skel_path = base / ds / 'skeleton.npz' |
| if not skel_path.exists(): |
| print(f' SKIP {ds}: skeleton.npz not found') |
| continue |
| canon = inject_skeleton(skel_path, ds, is_zoo=False) |
| print(f' {ds:15s}: {len(canon)} joints → canonical injected') |
|
|
| |
| zoo_dir = base / 'truebones_zoo' |
| if zoo_dir.exists(): |
| |
| main_skel = zoo_dir / 'skeleton.npz' |
| if main_skel.exists(): |
| canon = inject_skeleton(main_skel, 'truebones_zoo', is_zoo=True) |
| print(f' {"zoo/main":15s}: {len(canon)} joints → canonical injected') |
|
|
| |
| skel_dir = zoo_dir / 'skeletons' |
| if skel_dir.exists(): |
| count = 0 |
| for f in sorted(skel_dir.glob('*.npz')): |
| inject_skeleton(f, 'truebones_zoo', is_zoo=True) |
| count += 1 |
| print(f' {"zoo/species":15s}: {count} species → canonical injected') |
|
|
| print('\nDone!') |
|
|
|
|
| if __name__ == '__main__': |
| main() |
|
|