File size: 2,461 Bytes
e95f494
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Generate the exact train / val / test split used by City3D-MultiGen.

This replicates the deterministic split from the training dataloader:

    all_files = sorted(list(Path(data_root).glob('**/grid_*.las')))
    n_train = int(n_total * train_split)
    n_val   = int(n_total * val_split)
    train = all_files[:n_train]
    val   = all_files[n_train:n_train + n_val]
    test  = all_files[n_train + n_val:]

There is **no shuffling and no random seed** — the split is a sequential slice of
the path-sorted tile list. Running this on the same assembled `output/` directory
therefore reproduces exactly the split used to produce the paper's results.

Because tile filenames (`grid_<id>`) are ordered along the spatial grid, this
path-sorted sequential split yields spatially contiguous train/val/test regions.

Usage:
    python scripts/make_splits.py \
        --data_root /path/to/output \
        --train_split 0.8 --val_split 0.1 \
        --out_dir metadata/splits
"""
import argparse
from pathlib import Path


def main():
    ap = argparse.ArgumentParser(description="Reproduce the City3D-MultiGen tile split.")
    ap.add_argument("--data_root", required=True,
                    help="Directory containing the assembled tiles (grid_*/grid_*.las).")
    ap.add_argument("--train_split", type=float, default=0.8)
    ap.add_argument("--val_split", type=float, default=0.1)
    ap.add_argument("--out_dir", default="metadata/splits")
    args = ap.parse_args()

    # Identical to the training dataloader: recursive glob, sorted by path.
    all_files = sorted(list(Path(args.data_root).glob("**/grid_*.las")))
    n = len(all_files)
    if n == 0:
        raise SystemExit(f"No grid_*.las files found under {args.data_root}")

    n_train = int(n * args.train_split)
    n_val = int(n * args.val_split)
    splits = {
        "train": all_files[:n_train],
        "val":   all_files[n_train:n_train + n_val],
        "test":  all_files[n_train + n_val:],
    }

    out = Path(args.out_dir)
    out.mkdir(parents=True, exist_ok=True)
    for name, files in splits.items():
        ids = [f.stem for f in files]          # e.g. "grid_120256"
        (out / f"{name}.txt").write_text("\n".join(ids) + "\n")
        print(f"{name:5s}: {len(ids):6d} tiles -> {out / (name + '.txt')}")
    print(f"total: {n} tiles "
          f"(train={n_train}, val={n_val}, test={n - n_train - n_val})")


if __name__ == "__main__":
    main()