bdck commited on
Commit
4e56ffc
·
verified ·
1 Parent(s): 72dfa8b

Upload scripts/stage_data.py

Browse files
Files changed (1) hide show
  1. scripts/stage_data.py +61 -0
scripts/stage_data.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ stage_data.py
3
+ =============
4
+
5
+ Generate staged training data from labeled point clouds.
6
+
7
+ Requires point clouds with instance labels. For PLY/PCD files without labels,
8
+ you can provide a separate label file (e.g. .npy with shape (N,)).
9
+
10
+ Example:
11
+ python stage_data.py --input scene.ply --labels scene_labels.npy \
12
+ --output scene_staged.h5 --resolution 0.1
13
+ """
14
+
15
+ import argparse
16
+ import numpy as np
17
+ from pathlib import Path
18
+
19
+ from learn_region_grow.io import load_point_cloud
20
+ from learn_region_grow.stage_data import stage_labeled_cloud, save_staged_h5
21
+
22
+
23
+ def main():
24
+ parser = argparse.ArgumentParser(description="Stage labeled point clouds into training H5")
25
+ parser.add_argument("--input", required=True, help="Input .ply or .pcd")
26
+ parser.add_argument("--labels", default=None, help="Optional .npy file with (N,) instance labels")
27
+ parser.add_argument("--output", required=True, help="Output .h5 file")
28
+ parser.add_argument("--resolution", type=float, default=0.1)
29
+ parser.add_argument("--add_mistake_prob", type=float, default=0.2)
30
+ parser.add_argument("--remove_mistake_prob", type=float, default=0.2)
31
+ parser.add_argument("--seeds_per_instance", type=int, default=5)
32
+ parser.add_argument("--max_steps_per_seed", type=int, default=20)
33
+ args = parser.parse_args()
34
+
35
+ xyz, rgb, _ = load_point_cloud(args.input)
36
+ print(f"Loaded {len(xyz)} points")
37
+
38
+ if args.labels:
39
+ labels = np.load(args.labels)
40
+ else:
41
+ # Try to read labels from PLY / PCD if present
42
+ # For now, raise
43
+ raise ValueError("--labels is required. Provide a .npy file with shape (N,) integer instance IDs.")
44
+
45
+ print(f"Staging data ...")
46
+ inliers, neighbors, add_lbl, rmv_lbl = stage_labeled_cloud(
47
+ xyz, rgb, labels,
48
+ add_mistake_prob=args.add_mistake_prob,
49
+ remove_mistake_prob=args.remove_mistake_prob,
50
+ resolution=args.resolution,
51
+ seeds_per_instance=args.seeds_per_instance,
52
+ max_steps_per_seed=args.max_steps_per_seed,
53
+ )
54
+
55
+ print(f"Generated {len(inliers)} training tuples")
56
+ save_staged_h5(args.output, inliers, neighbors, add_lbl, rmv_lbl)
57
+ print(f"Saved to {args.output}")
58
+
59
+
60
+ if __name__ == "__main__":
61
+ main()