cmolinac commited on
Commit
422e038
·
verified ·
1 Parent(s): 68afb88

Add scripts/preprocess_step4_o3dml.py

Browse files
Files changed (1) hide show
  1. scripts/preprocess_step4_o3dml.py +79 -0
scripts/preprocess_step4_o3dml.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ preprocess_step4_o3dml.py
4
+ ==========================
5
+ NEST3D Pre-processing Step 4: Convert Pointcept format to Open3D-ML format
6
+ for RandLA-Net / KPConv.
7
+
8
+ Input: <pointcept-dir>/train|val|test/sampleXXX/{coord,color,segment}.npy
9
+ Output: <out-dir>/train|val|test/sampleXXX.npy [N, 7] = x, y, z, r, g, b, label
10
+
11
+ Uses the same train/val/test split as the Pointcept-format data (Step 3),
12
+ since it is derived directly from that data's folder structure.
13
+
14
+ Labels: 0=grass, 1=tree, 2=nest, -1=ignore (no remapping applied; ignore
15
+ points are passed through unchanged from the Pointcept-format segment.npy).
16
+
17
+ Usage:
18
+ python preprocess_step4_o3dml.py \\
19
+ --pointcept-dir /path/to/pointcept/format/data \\
20
+ --out-dir /path/to/o3dml/output
21
+
22
+ Author: NEST3D team
23
+ """
24
+
25
+ import argparse
26
+ import numpy as np
27
+ from pathlib import Path
28
+
29
+ def main():
30
+ parser = argparse.ArgumentParser(description="NEST3D Step 4: convert to Open3D-ML format")
31
+ parser.add_argument("--pointcept-dir", type=Path, required=True,
32
+ help="Path to the Pointcept-format data (output of Step 3), "
33
+ "containing train/val/test subfolders")
34
+ parser.add_argument("--out-dir", type=Path, required=True,
35
+ help="Output directory for the Open3D-ML-format .npy files")
36
+ args = parser.parse_args()
37
+
38
+ nest_dir = args.pointcept_dir
39
+ out_dir = args.out_dir
40
+
41
+ for split in ["train", "val", "test"]:
42
+ (out_dir / split).mkdir(parents=True, exist_ok=True)
43
+
44
+ for split in ["train", "val", "test"]:
45
+ src_dir = nest_dir / split
46
+ print(f"\n=== {split.upper()} ===")
47
+ samples = sorted([p.name for p in src_dir.iterdir()
48
+ if p.is_dir() and p.name.startswith("sample")])
49
+ for sample_id in samples:
50
+ out_path = out_dir / split / f"{sample_id}.npy"
51
+ if out_path.exists():
52
+ print(f" [SKIP] {sample_id}")
53
+ continue
54
+
55
+ src = src_dir / sample_id
56
+ coord = np.load(src / "coord.npy")
57
+ color = np.load(src / "color.npy")
58
+ segment = np.load(src / "segment.npy")
59
+ lbl = segment.copy() # -1 (ignore) passed through unchanged
60
+
61
+ data = np.concatenate([
62
+ coord.astype(np.float32),
63
+ color.astype(np.float32),
64
+ lbl.reshape(-1,1).astype(np.float32)
65
+ ], axis=1)
66
+ np.save(str(out_path), data)
67
+
68
+ n = len(data)
69
+ n0 = int((lbl==0).sum())
70
+ n1 = int((lbl==1).sum())
71
+ n2 = int((lbl==2).sum())
72
+ n_ign = int((lbl==-1).sum())
73
+ print(f" [OK] {sample_id}: {n:,} | grass={100*n0/n:.1f}% tree={100*n1/n:.1f}% "
74
+ f"nest={100*n2/n:.1f}% ignore={100*n_ign/n:.1f}%")
75
+
76
+ print("\nDone!")
77
+
78
+ if __name__ == "__main__":
79
+ main()