File size: 2,894 Bytes
422e038
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
preprocess_step4_o3dml.py
==========================
NEST3D Pre-processing Step 4: Convert Pointcept format to Open3D-ML format
for RandLA-Net / KPConv.

Input:  <pointcept-dir>/train|val|test/sampleXXX/{coord,color,segment}.npy
Output: <out-dir>/train|val|test/sampleXXX.npy  [N, 7] = x, y, z, r, g, b, label

Uses the same train/val/test split as the Pointcept-format data (Step 3),
since it is derived directly from that data's folder structure.

Labels: 0=grass, 1=tree, 2=nest, -1=ignore (no remapping applied; ignore
points are passed through unchanged from the Pointcept-format segment.npy).

Usage:
  python preprocess_step4_o3dml.py \\
      --pointcept-dir /path/to/pointcept/format/data \\
      --out-dir /path/to/o3dml/output

Author: NEST3D team
"""

import argparse
import numpy as np
from pathlib import Path

def main():
    parser = argparse.ArgumentParser(description="NEST3D Step 4: convert to Open3D-ML format")
    parser.add_argument("--pointcept-dir", type=Path, required=True,
                         help="Path to the Pointcept-format data (output of Step 3), "
                              "containing train/val/test subfolders")
    parser.add_argument("--out-dir", type=Path, required=True,
                         help="Output directory for the Open3D-ML-format .npy files")
    args = parser.parse_args()

    nest_dir = args.pointcept_dir
    out_dir  = args.out_dir

    for split in ["train", "val", "test"]:
        (out_dir / split).mkdir(parents=True, exist_ok=True)

    for split in ["train", "val", "test"]:
        src_dir = nest_dir / split
        print(f"\n=== {split.upper()} ===")
        samples = sorted([p.name for p in src_dir.iterdir()
                           if p.is_dir() and p.name.startswith("sample")])
        for sample_id in samples:
            out_path = out_dir / split / f"{sample_id}.npy"
            if out_path.exists():
                print(f"  [SKIP] {sample_id}")
                continue

            src = src_dir / sample_id
            coord   = np.load(src / "coord.npy")
            color   = np.load(src / "color.npy")
            segment = np.load(src / "segment.npy")
            lbl = segment.copy()  # -1 (ignore) passed through unchanged

            data = np.concatenate([
                coord.astype(np.float32),
                color.astype(np.float32),
                lbl.reshape(-1,1).astype(np.float32)
            ], axis=1)
            np.save(str(out_path), data)

            n  = len(data)
            n0 = int((lbl==0).sum())
            n1 = int((lbl==1).sum())
            n2 = int((lbl==2).sum())
            n_ign = int((lbl==-1).sum())
            print(f"  [OK] {sample_id}: {n:,} | grass={100*n0/n:.1f}% tree={100*n1/n:.1f}% "
                  f"nest={100*n2/n:.1f}% ignore={100*n_ign/n:.1f}%")

    print("\nDone!")

if __name__ == "__main__":
    main()