File size: 2,424 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
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Materialize portable test manifests as inference and rendering jobs."""
import argparse
import json
from pathlib import Path
import os
ROOT = Path(os.environ.get("ELLSA2_DATA_ROOT", Path(__file__).resolve().parents[1])).expanduser().resolve()

def read_manifest():
    return [json.loads(s) for s in (ROOT / "testset/manifest.jsonl").read_text().splitlines() if s]

def prepare(output_dir, test_id=None, limit=0):
    output_dir = Path(output_dir).resolve()
    output_dir.mkdir(parents=True, exist_ok=True)
    rows = read_manifest()
    if test_id:
        rows = [r for r in rows if r["group_id"] == test_id]
        assert rows, f"Unknown test id: {test_id}"
    rows = rows[:limit or None]
    jobs = []
    render = []
    for r in rows:
        gid = r["group_id"]
        motion = output_dir / (gid + ".npz")
        jobs.append({"group_id": gid, "audio_file": str(ROOT / r["audio20_target"]),
                     "audio_file_listen": str(ROOT / r["audio20_partner"]),
                     "word_file": str(ROOT / r["metadata20_target"]),
                     "word_file_listen": str(ROOT / r["metadata20_partner"]),
                     "motion_style_pose_path": str(ROOT / r["motion_style_pose_path"]),
                     "motion_style_flame_path": str(ROOT / r["motion_style_flame_path"]) if r.get("motion_style_flame_path") else "",
                     "motion_style_start": 0, "motion_style_length": 612,
                     "output_path": str(motion), "sampling_seed": 0})
        render.append({"group_id": gid, "system_id": "ELLSA2", "npz_path": str(motion),
                       "wav_path": str(ROOT / r["audio20_target"]),
                       "video_path": str(output_dir / "videos" / (gid + ".mp4")),
                       "ready_path": str(output_dir / "render_ready" / (gid + ".ready")),
                       "tmp_dir": str(output_dir / "render_tmp" / gid)})
    job_file = output_dir / "inference_jobs.json"
    job_file.write_text(json.dumps({"data": jobs}, indent=2))
    (output_dir / "render_jobs.json").write_text(json.dumps(render, indent=2))
    return job_file

def main():
    p = argparse.ArgumentParser()
    p.add_argument("--output-dir", default="outputs/test")
    p.add_argument("--test-id")
    p.add_argument("--limit", type=int, default=0)
    args = p.parse_args()
    print(prepare(args.output_dir, args.test_id, args.limit))


if __name__ == "__main__":
    main()