File size: 6,484 Bytes
0be07b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env bash
set -euo pipefail

SRC="${SRC:-/lumos-vePFS/suda/FastUMI_data/processed_data/umi_bechmark_dual/dual_arm_task5}"
RELEASE="${RELEASE:-/lumos-vePFS/suda/FastUMI_release/UMI-Benchmark-v1}"
TASK_NAME="${TASK_NAME:-dual_arm_task5}"
DATA_DIR="$RELEASE/data/$TASK_NAME"
META_DIR="$RELEASE/metadata/$TASK_NAME"
LIST_DIR="$META_DIR/lists"
CHUNK_SIZE="${CHUNK_SIZE:-50}"

mkdir -p "$DATA_DIR" "$LIST_DIR"

cd "$SRC"

python - <<'PY'
from pathlib import Path
import csv
import os
import subprocess

src = Path(os.environ.get("SRC", "/lumos-vePFS/suda/FastUMI_data/processed_data/umi_bechmark_dual/dual_arm_task5"))
release = Path(os.environ.get("RELEASE", "/lumos-vePFS/suda/FastUMI_release/UMI-Benchmark-v1"))
task_name = os.environ.get("TASK_NAME", "dual_arm_task5")
chunk_size = int(os.environ.get("CHUNK_SIZE", "50"))
data_dir = release / "data" / task_name
meta_dir = release / "metadata" / task_name
list_dir = meta_dir / "lists"

scene_targets = [
    ("T9_Pink_Cup_Plate_Set_Scene_B", 393, "pink cup-plate set", "scene B", "Ab", "background b", "pink cup-plate set scene B"),
    ("T9_Green_Cup_Plate_Set_Scene_B", 400, "green cup-plate set", "scene B", "Ad", "background b", "green cup-plate set scene B"),
    ("T9_Pink_Cup_Plate_Set_Scene_A", 400, "pink cup-plate set", "scene A", "Aa", "background a", "pink cup-plate set scene A"),
    ("T9_Green_Cup_Plate_Set_Scene_A", 407, "green cup-plate set", "scene A", "Ac", "background a", "green cup-plate set scene A"),
]

def session_key(path: Path):
    return (path.parent.name.replace("multi_session_", ""), path.name.replace("session_", ""))

def find_sessions(setting_root: Path):
    sessions = []
    for session in setting_root.rglob("session_*"):
        if not session.is_dir():
            continue
        if not session.parent.name.startswith("multi_session_"):
            continue
        if "background" not in session.parts:
            continue
        sessions.append(session)
    return sorted(sessions, key=session_key)

data_dir.mkdir(parents=True, exist_ok=True)
list_dir.mkdir(parents=True, exist_ok=True)

for old in data_dir.glob("T9_*/*.tar"):
    old.unlink()
for old in list_dir.glob("*.txt"):
    old.unlink()

mapping_rows = []
manifest_rows = []
all_session_rows = []

for setting, expected, set_color, scene, source_suffix, background, description in scene_targets:
    root = src / setting
    sessions = find_sessions(root)
    if len(sessions) != expected:
        raise SystemExit(f"{setting}: expected {expected} sessions, got {len(sessions)}")

    setting_data_dir = data_dir / setting
    setting_data_dir.mkdir(parents=True, exist_ok=True)

    setting_list = list_dir / f"{setting}_all_sessions.txt"
    with setting_list.open("w") as f:
        for session in sessions:
            rel = session.relative_to(src)
            f.write(f"{rel}\n")
            date, sess = session_key(session)
            all_session_rows.append({
                "task": task_name,
                "setting": setting,
                "source_suffix": source_suffix,
                "set_color": set_color,
                "scene": scene,
                "background": background,
                "date": date,
                "session": sess,
                "session_path": str(rel),
            })

    mapping_rows.append({
        "task": task_name,
        "setting": setting,
        "source_suffix": source_suffix,
        "set_color": set_color,
        "scene": scene,
        "background": background,
        "description": description,
        "session_count": len(sessions),
        "release_subdir": f"data/{task_name}/{setting}",
        "session_list": f"metadata/{task_name}/lists/{setting}_all_sessions.txt",
    })

    for chunk_idx, start in enumerate(range(0, len(sessions), chunk_size)):
        chunk_sessions = sessions[start:start + chunk_size]
        chunk_name = f"{setting}_chunk_{chunk_idx:03d}.tar"
        chunk_list = list_dir / f"{setting}_chunk_{chunk_idx:03d}.txt"
        tar_path = setting_data_dir / chunk_name
        with chunk_list.open("w") as f:
            for session in chunk_sessions:
                f.write(f"{session.relative_to(src)}\n")
        subprocess.run(["tar", "-C", str(src), "-cf", str(tar_path), "-T", str(chunk_list)], check=True)

        first_date, first_session = session_key(chunk_sessions[0])
        last_date, last_session = session_key(chunk_sessions[-1])
        manifest_rows.append({
            "task": task_name,
            "setting": setting,
            "source_suffix": source_suffix,
            "set_color": set_color,
            "scene": scene,
            "background": background,
            "chunk_index": chunk_idx,
            "tar_path": f"data/{task_name}/{setting}/{chunk_name}",
            "session_list": f"metadata/{task_name}/lists/{setting}_chunk_{chunk_idx:03d}.txt",
            "session_count": len(chunk_sessions),
            "first_date": first_date,
            "first_session": first_session,
            "last_date": last_date,
            "last_session": last_session,
        })

with (meta_dir / "scene_mapping.csv").open("w", newline="") as f:
    fields = ["task", "setting", "source_suffix", "set_color", "scene", "background", "description", "session_count", "release_subdir", "session_list"]
    writer = csv.DictWriter(f, fieldnames=fields)
    writer.writeheader()
    writer.writerows(mapping_rows)

with (meta_dir / "chunk_manifest.csv").open("w", newline="") as f:
    fields = ["task", "setting", "source_suffix", "set_color", "scene", "background", "chunk_index", "tar_path", "session_list", "session_count", "first_date", "first_session", "last_date", "last_session"]
    writer = csv.DictWriter(f, fieldnames=fields)
    writer.writeheader()
    writer.writerows(manifest_rows)

with (meta_dir / "all_sessions.csv").open("w", newline="") as f:
    fields = ["task", "setting", "source_suffix", "set_color", "scene", "background", "date", "session", "session_path"]
    writer = csv.DictWriter(f, fieldnames=fields)
    writer.writeheader()
    writer.writerows(all_session_rows)

print(f"packed {len(manifest_rows)} tar files under {data_dir}")
PY

cd "$DATA_DIR"
find . -name '*.tar' -type f -print0 | sort -z | xargs -0 sha256sum > "$META_DIR/sha256.txt"
find . -name '*.tar' -type f -print0 | sort -z | xargs -0 du -h > "$META_DIR/sizes.txt"
find . -name '*.tar' -type f -print0 | sort -z | xargs -0 du -sb > "$META_DIR/sizes_bytes.txt"

echo "Done: $DATA_DIR"