Tevior commited on
Commit
b1bed7a
·
verified ·
1 Parent(s): 571a68d

Upload scripts/inject_canonical_names.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. scripts/inject_canonical_names.py +70 -0
scripts/inject_canonical_names.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ T3: Inject canonical_names into all skeleton.npz files.
3
+
4
+ Adds a 'canonical_names' field parallel to 'joint_names' in every
5
+ skeleton.npz across all datasets.
6
+ """
7
+
8
+ import sys
9
+ import os
10
+ from pathlib import Path
11
+ import numpy as np
12
+
13
+ project_root = Path(__file__).parent.parent
14
+ sys.path.insert(0, str(project_root))
15
+
16
+ from src.data.canonical_names import get_canonical_names, CANONICAL_MAPS
17
+ from src.data.zoo_canonical_names import get_zoo_canonical_names
18
+
19
+
20
+ def inject_skeleton(npz_path: Path, dataset_id: str, is_zoo: bool = False):
21
+ """Add canonical_names to a skeleton.npz file."""
22
+ data = dict(np.load(npz_path, allow_pickle=True))
23
+ raw_names = [str(n) for n in data['joint_names']]
24
+
25
+ if is_zoo:
26
+ canonical = get_zoo_canonical_names(raw_names)
27
+ else:
28
+ canonical = get_canonical_names(raw_names, dataset_id)
29
+
30
+ data['canonical_names'] = np.array(canonical)
31
+ np.savez(npz_path, **data)
32
+ return canonical
33
+
34
+
35
+ def main():
36
+ base = project_root / 'data' / 'processed'
37
+
38
+ # Human datasets
39
+ human_datasets = ['humanml3d', 'lafan1', '100style', 'bandai_namco', 'cmu_mocap', 'mixamo']
40
+ for ds in human_datasets:
41
+ skel_path = base / ds / 'skeleton.npz'
42
+ if not skel_path.exists():
43
+ print(f' SKIP {ds}: skeleton.npz not found')
44
+ continue
45
+ canon = inject_skeleton(skel_path, ds, is_zoo=False)
46
+ print(f' {ds:15s}: {len(canon)} joints → canonical injected')
47
+
48
+ # Zoo: main skeleton.npz + per-species skeletons
49
+ zoo_dir = base / 'truebones_zoo'
50
+ if zoo_dir.exists():
51
+ # Main representative skeleton
52
+ main_skel = zoo_dir / 'skeleton.npz'
53
+ if main_skel.exists():
54
+ canon = inject_skeleton(main_skel, 'truebones_zoo', is_zoo=True)
55
+ print(f' {"zoo/main":15s}: {len(canon)} joints → canonical injected')
56
+
57
+ # Per-species skeletons
58
+ skel_dir = zoo_dir / 'skeletons'
59
+ if skel_dir.exists():
60
+ count = 0
61
+ for f in sorted(skel_dir.glob('*.npz')):
62
+ inject_skeleton(f, 'truebones_zoo', is_zoo=True)
63
+ count += 1
64
+ print(f' {"zoo/species":15s}: {count} species → canonical injected')
65
+
66
+ print('\nDone!')
67
+
68
+
69
+ if __name__ == '__main__':
70
+ main()