HardExampleCrop#
- class HardExampleCrop(point_max=80000, sample_rate=None, hard_labels=(2, 3), min_hard_points=1, attempts=5, fallback='none', p=0.5)[source]#
Bases:
objectSpherical crop biased toward rare (“hard”) segment labels.
Like
SphereCrop, but when the cloud is over budget it centers the crop on a point whosesegmentis one ofhard_labels, retrying up toattemptstimes until the kept set contains at leastmin_hard_pointshard points (otherwise the last attempt is used). Only fires with probabilityp; sub-budget clouds are returned unchanged. If no hard points are present, behaviour followsfallback. Keeps the closestpoint_max(orsample_rate-fraction) points viaindex_operator. Requirescoord(asserted) and readssegmentwhen present. Registered asHardExampleCrop– use this string as thetypein atransform=[...]config list.- Parameters:
point_max (int) – maximum number of points to keep when
sample_rateisNone. Defaults to80000.sample_rate (float, optional) – if set, the budget is
sample_rate * num_pointsinstead ofpoint_max. Defaults toNone.hard_labels (Sequence[int]) –
segmentlabel values treated as hard examples to center on. Defaults to(2, 3).min_hard_points (int) – minimum hard points the crop must contain to accept an attempt early. Defaults to
1.attempts (int) – number of random hard-centered crops to try. Defaults to
5.fallback (str) – behaviour when no hard points exist, one of
"random","center", or"none"(return unchanged). Defaults to"none".p (float) – probability of applying the crop at all. Defaults to
0.5.
Note
With no
segmentkey all points are treated as non-hard, so thefallbackpath is taken.Example
>>> import numpy as np >>> from pimm.datasets.transform import HardExampleCrop >>> np.random.seed(0) >>> coord = np.random.rand(100, 3).astype("f4") >>> segment = np.zeros(100, dtype=int); segment[[5, 50]] = 3 # two rare points >>> data = {"coord": coord.copy(), "segment": segment.copy()} >>> # over budget: crop centers on a hard (label 3) point, keeping it in-frame >>> out = HardExampleCrop(point_max=10, hard_labels=(2, 3), ... min_hard_points=1, p=1.0)(data) >>> len(out["coord"]) # 100 -> 10 points (closest to a hard center) 10 >>> int(np.isin(out["segment"], (2, 3)).sum()) >= 1 # at least one hard point survives True