Datasets:
File size: 6,255 Bytes
78f9d77 | 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 | #!/usr/bin/env bash
set -euo pipefail
SRC="${SRC:-/lumos-vePFS/suda/FastUMI_data/processed_data/umi_bechmark_dual/single_arm_task3}"
RELEASE="${RELEASE:-/lumos-vePFS/suda/FastUMI_release/UMI-Benchmark-v1}"
TASK_NAME="${TASK_NAME:-single_arm_task3}"
DATA_DIR="$RELEASE/data/$TASK_NAME"
META_DIR="$RELEASE/metadata/$TASK_NAME"
LIST_DIR="$META_DIR/lists"
CHUNK_SIZE="${CHUNK_SIZE:-100}"
mkdir -p "$DATA_DIR" "$LIST_DIR"
cd "$SRC"
python3 - <<'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/single_arm_task3"))
release = Path(os.environ.get("RELEASE", "/lumos-vePFS/suda/FastUMI_release/UMI-Benchmark-v1"))
task_name = os.environ.get("TASK_NAME", "single_arm_task3")
chunk_size = int(os.environ.get("CHUNK_SIZE", "100"))
data_dir = release / "data" / task_name
meta_dir = release / "metadata" / task_name
list_dir = meta_dir / "lists"
scene_targets = [
("T3_Black_Ink_Gray_Paper", 482, "Aa", "black ink", "gray paper", "Black Ink + Gray Paper"),
("T3_Black_Ink_Yellow_Paper", 492, "Fa", "black ink", "yellow paper", "Black Ink + Yellow Paper"),
("T3_Black_Ink_White_Paper", 499, "Ea", "black ink", "white paper", "Black Ink + White Paper"),
("T3_Red_Ink_Gray_Paper", 500, "Da", "red ink", "gray paper", "Red Ink + Gray Paper"),
("T3_Red_Ink_Yellow_Paper", 505, "Ca", "red ink", "yellow paper", "Red Ink + Yellow Paper"),
("T3_Red_Ink_White_Paper", 518, "Ba", "red ink", "white paper", "Red Ink + White Paper"),
]
def session_key(path: Path):
return (path.parent.name.replace("multi_session_", ""), path.name.replace("session_", ""))
data_dir.mkdir(parents=True, exist_ok=True)
list_dir.mkdir(parents=True, exist_ok=True)
for old in data_dir.glob("T3_*/*.tar"):
old.unlink()
for old in list_dir.glob("*.txt"):
old.unlink()
mapping_rows = []
manifest_rows = []
all_session_rows = []
for setting, expected, source_suffix, ink_color, paper_color, description in scene_targets:
root = src / setting / "good" / "background"
sessions = sorted([p for p in root.glob("multi_session_*/session_*") if p.is_dir()], key=session_key)
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,
"ink_color": ink_color,
"paper_color": paper_color,
"date": date,
"session": sess,
"session_path": str(rel),
})
mapping_rows.append({
"task": task_name,
"setting": setting,
"source_suffix": source_suffix,
"ink_color": ink_color,
"paper_color": paper_color,
"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")
print(f"Packing {setting}/{chunk_name} ({len(chunk_sessions)} sessions)", flush=True)
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,
"ink_color": ink_color,
"paper_color": paper_color,
"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", "ink_color", "paper_color", "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", "ink_color", "paper_color", "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", "ink_color", "paper_color", "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}", flush=True)
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"
|