InstanceParser#

class InstanceParser(segment_ignore_index=(-1, 0, 1), instance_ignore_index=-1, compute_axis_stats=False, axis_min_points=5, axis_eps=1e-06, axis_default=(1.0, 0.0, 0.0), axis_normalize_half_extent=True)[source]#

Bases: object

Compact instance ids and derive per-instance bounding boxes and centroids.

Reads data_dict["coord"], data_dict["segment"], and data_dict["instance"]. Points whose semantic label is in segment_ignore_index have their instance set to instance_ignore_index; remaining instances are relabeled to a dense 0..K-1 range. Writes back the compacted instance, a per-point instance_centroid (N, 3), and a per-instance bbox (K, 8) (center xyz, size xyz, theta, shifted class). When compute_axis_stats is enabled it also runs a per-instance PCA and writes per-point instance_axis (N, 3), instance_axis_coord, instance_axis_coord_normalized, instance_axis_length, instance_axis_weight, and instance_axis_coord_weight. Registered as InstanceParser — use this string as the type in a transform=[...] config list.

Parameters:
  • segment_ignore_index (tuple) – Semantic labels excluded from instances; their class indices are also vacated/shifted out of the bbox class. Defaults to (-1, 0, 1).

  • instance_ignore_index (int) – Instance id assigned to ignored points and used to fill uninitialized centroid/bbox entries. Defaults to -1.

  • compute_axis_stats (bool) – If True, compute the per-instance principal-axis statistics. Defaults to False.

  • axis_min_points (int) – Minimum points an instance needs for a valid PCA axis (clamped to >= 1). Defaults to 5.

  • axis_eps (float) – Numerical tolerance for axis/eigenvalue validity and normalization. Defaults to 1e-6.

  • axis_default (tuple) – Fallback unit axis (normalized internally, must be non-zero, shape (3,)) used when PCA is invalid. Defaults to (1.0, 0.0, 0.0).

  • axis_normalize_half_extent (bool) – If True, normalize the axis coordinate by the half-extent rather than the full extent. Defaults to True.

Example

>>> import numpy as np
>>> data = {
...     "coord": np.array([[0,0,0],[1,0,0],[0,0,0],[5,5,5],[6,5,5]], dtype="f4"),
...     "segment": np.array([2, 2, 1, 3, 3]),   # class 1 is ignored
...     "instance": np.array([10, 10, 7, 20, 20]),
... }
>>> out = InstanceParser(segment_ignore_index=(-1, 0, 1))(data)
>>> out["instance"]            # ignored point -> -1, rest densified 0..K-1
array([ 0,  0, -1,  1,  1])
>>> out["bbox"].shape          # (K instances, 8): center xyz, size xyz, theta, class
(2, 8)