MachineHearing / process /map_deepship.py
lwLiu's picture
Upload folder using huggingface_hub (part 22)
9b6e0aa verified
Raw History Blame
1.24 kB
import argparse
import json
import shutil
from pathlib import Path
MHB_ROOT = Path(__file__).resolve().parent.parent
def main():
parser = argparse.ArgumentParser()
parser.add_argument("test_dir", type=Path)
args = parser.parse_args()
test_dir = args.test_dir.expanduser().resolve()
assert test_dir.is_dir(), f"Not found: {test_dir}"
count = 0
with (MHB_ROOT / "meta_data.jsonl").open("r", encoding="utf-8") as f:
for line in f:
if not line.strip():
continue
record = json.loads(line)
if record["task_name"] != "DeepShip":
continue
category, event, recording, segment = record["id"].split("_")
src = test_dir / category / event / f"{recording}.wav" / f"{segment}.wav"
dst = MHB_ROOT / record["input_ts"]["path"]
assert src.is_file(), f"Missing DeepShip segment: {src}"
assert dst.name == f"{record['id']}.wav"
dst.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(src, dst)
count += 1
assert count == 527, f"Expected 527, got {count}"
print(f"DeepShip: copied {count} files")
if __name__ == "__main__":
main()