Download process/map_deepship.py from OpenTSLab/MachineHearing: direct link, hf CLI and curl.
- Browser
- Download file 1.24 kB
-
https://huggingface.co/datasets/OpenTSLab/MachineHearing/resolve/a982f7f0ad14ac2430e8e0e475aca4eaaeda41f6/process/map_deepship.py
- Command line
-
hf download hf://datasets/OpenTSLab/MachineHearing@a982f7f0ad14ac2430e8e0e475aca4eaaeda41f6/process/map_deepship.py
-
curl -L -o map_deepship.py https://huggingface.co/datasets/OpenTSLab/MachineHearing/resolve/a982f7f0ad14ac2430e8e0e475aca4eaaeda41f6/process/map_deepship.py
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() | |