File size: 4,401 Bytes
13cc860
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""Prepare short, exactly training-caption-matched inputs for the original v4 protocol."""
import argparse
import csv
import hashlib
import json
from pathlib import Path
import sys

ROOT = Path(__file__).resolve().parents[2]
CASES = (
    ('simple_walk_forward', 't0000103', 'g00', '直行(训练原文)'),
    ('simple_walk_circle', 't0003078', 'g02', '逆时针行走(训练原文)'),
    ('simple_squats', 't0003075', 'g02', '三次深蹲(训练原文)'),
)


def prepare(run, output):
    import numpy as np
    runtime = json.loads((ROOT / 'config/runtime.json').read_text())
    code = Path(runtime['visualization_resources']).parent
    sys.path.insert(0, str(code / 'OmniHM_bench'))
    from video_motion import load_motion36, sample_motion36, motion36_to_qpos, G1_MUJOCO_JOINT_NAMES
    from preview_scale import save
    manifest_path = output / 'manifest.json'
    if manifest_path.exists():
        m = json.loads(manifest_path.read_text())
        if m['source_run'] != str(run) or [c['id'] for c in m['cases']] != [c[0] for c in CASES]:
            raise ValueError('Existing simple-text selection does not match this run')
        return
    manifest = dict(source_run=str(run), selection_only=True, checkpoint_step=None,
        representation='root40_v1', normalization='g1_root40_fixed_v1', inference_fps=50,
        denoising_steps=10, action_chunk=30, execution_horizon=20, selection_seed=20261002,
        protocol='GT frame 0 initialization; free autoregressive rollout; no future GT poses',
        selection_version='simple_training_text_v1', cases=[])
    hashes = {}
    for index, (identity, motion_id, group, label) in enumerate(CASES):
        source_manifest = ROOT / f'training_set/text/index/{group}.csv'
        row = next(r for r in csv.DictReader(source_manifest.open()) if r['move_name'] == motion_id)
        source = ROOT / 'training_set/text' / row['move_g1_path']
        motion = load_motion36(source)
        # Keep the entire training sequence and the original gallery's 30 Hz display.
        times = np.arange(int(np.floor((len(motion)-1)*30/50))+1) / 30
        qpos = motion36_to_qpos(sample_motion36(motion, source_fps=50, sample_times=times)).astype(np.float32)
        directory = output / 'text' / identity
        directory.mkdir(parents=True, exist_ok=True)
        record = dict(sample_id=identity, caption=row['content_short_description'], source_motion_path=str(source),
            training_id=f'text_{group} / {motion_id}', source_manifest=str(source_manifest),
            data_split='训练集内固定样例(不是独立验证集)', label=label,
            source_sha256={n:hashlib.sha256((source/n).read_bytes()).hexdigest()
                           for n in ('joint_pos.csv','body_pos.csv','body_quat.csv')})
        save(directory / 'selection_record.json', record)
        np.savez_compressed(directory / 'gt.npz', qpos_36=qpos, valid=np.ones(len(qpos),bool), fps=30.,
                            joint_names=np.asarray(G1_MUJOCO_JOINT_NAMES), sample_id=identity, score_start_frame=1)
        case = dict(id=identity, modality='text', directory=f'text/{identity}', caption=row['content_short_description'],
                    seed=20261002+index, fps=30., frames=len(qpos), source_sequence=motion_id, input_media=None,
                    status='selected', label=label)
        manifest['cases'].append(case)
        for name in ('selection_record.json','gt.npz'):
            hashes[f'text/{identity}/{name}'] = hashlib.sha256((directory/name).read_bytes()).hexdigest()
    contract = [{k:c[k] for k in ('id','directory','seed','fps','frames','source_sequence')} for c in manifest['cases']]
    manifest['fixed_input_sha256'] = hashes
    manifest['fixed_case_contract_sha256'] = hashlib.sha256(json.dumps(contract,sort_keys=True,separators=(',',':')).encode()).hexdigest()
    save(manifest_path, manifest)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--run', type=Path, required=True)
    parser.add_argument('--output', type=Path, required=True)
    args = parser.parse_args()
    run, output = args.run.resolve(strict=True), args.output.resolve()
    if not run.is_relative_to(ROOT/'scale/groups') or not output.is_relative_to(ROOT/'scale/groups'):
        parser.error('Only scale experiment inputs may be prepared')
    prepare(run, output)