File size: 1,524 Bytes
de254b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Attach extracted raw FLAME files and keep samples with both modalities."""
import argparse
import json
from pathlib import Path

def rows(obj):
    return obj["data"] if isinstance(obj, dict) else obj

def main():
    p = argparse.ArgumentParser()
    p.add_argument("--input", required=True)
    p.add_argument("--flame-manifest", required=True, help="JSON rows with pose_file and raw flame_file")
    p.add_argument("--output", required=True)
    a = p.parse_args()
    data = rows(json.loads(Path(a.input).read_text()))
    flame = rows(json.loads(Path(a.flame_manifest).read_text()))
    index = {}
    for row in flame:
        stem = Path(row["pose_file"]).stem
        if stem in index:
            raise ValueError(f"Ambiguous FLAME pairing for pose stem: {stem}")
        index[stem] = row
    selected = []
    for r in data:
        entry = index.get(Path(r["pose_file"]).stem)
        if entry is None:
            continue
        path = entry.get("flame_file_original", entry.get("flame_file"))
        if not path or not Path(path).is_file():
            continue
        selected.append(dict({key: value for key, value in r.items() if not key.startswith('flame_')},
                             flame_file=path))
    assert selected, "No paired SMPL-H / FLAME samples remain"
    Path(a.output).parent.mkdir(parents=True, exist_ok=True)
    Path(a.output).write_text(json.dumps({"data": selected}, indent=2))
    print(f"Kept {len(selected)} / {len(data)} samples")

if __name__ == "__main__":
    main()