albumentations.augmentations.dropout.guided_coarse_dropout


Guided coarse dropout constrained to a caller-supplied binary region.

GuidedCoarseDropoutclass

GuidedCoarseDropout(
    region_key: str = dropout_region,
    protected_bbox_labels: list[str | int | float] | None,
    protection_margin: float = 0.0,
    num_holes_range: tuple[int, int] = (1, 1),
    hole_height_range: tuple[float, float] = (0.05, 0.2),
    hole_width_range: tuple[float, float] = (0.05, 0.2),
    fill: DropoutFillValue = 0,
    fill_mask: tuple[float, ...] | float | None,
    p: float = 0.5
)

Apply coarse dropout within a caller-supplied binary region while preserving selected bounding boxes and filtering annotations by the actual dropout mask. The caller supplies a two-dimensional binary region as top-level metadata. A pixel value of True or 1 permits dropout; False or 0 leaves the pixel unchanged. Hole centers are sampled uniformly over the entire eligible region, after subtracting protected bounding boxes and their margins. Args: region_key (str): Top-level key containing the binary (H, W) dropout region. Default: "dropout_region". protected_bbox_labels (list[str | int | float] | None): Labels of boxes to protect. String labels use the configured bbox label encoder. Default: None. protection_margin (float): Relative expansion applied to every protected box side. A margin m expands horizontally by m * box_width and vertically by m * box_height. Default: 0.0. num_holes_range (tuple[int, int]): Inclusive number of holes sampled per image. Default: (1, 1). hole_height_range (tuple[float, float]): Hole-height fraction of the full image height. Default: (0.05, 0.20). hole_width_range (tuple[float, float]): Hole-width fraction of the full image width. Default: (0.05, 0.20). fill (float | tuple[float, ...] | str): Value used for dropped image pixels. Default: 0. fill_mask (float | tuple[float, ...] | None): Value used for dropped mask pixels. None leaves masks unchanged. Default: None. p (float): Probability of applying the transform. Default: 0.5. Targets: image, mask, bboxes, keypoints Image types: uint8, float32 Supported bboxes: hbb Examples: >>> import albumentations as A >>> import numpy as np >>> image = np.full((100, 100, 3), 255, dtype=np.uint8) >>> dropout_region = np.zeros((100, 100), dtype=np.uint8) >>> dropout_region[20:80, 20:80] = 1 >>> transform = A.Compose( ... [A.GuidedCoarseDropout(fill=0, p=1.0)], ... bbox_params=A.BboxParams(coord_format="pascal_voc", label_fields=["labels"]), ... ) >>> result = transform( ... image=image, ... dropout_region=dropout_region, ... bboxes=[[40, 40, 60, 60]], ... labels=["person"], ... ) Notes: - The region is aligned metadata and is returned unchanged. Place this transform before geometry changes unless the caller has already aligned the region to their coordinates. - If no eligible pixels remain, the transform is a no-op. - fill="random_uniform" samples one value per original hole, including holes whose rectangular footprint is clipped by the eligible region.

Parameters

NameTypeDefaultDescription
region_keystrdropout_region-
protected_bbox_labels
One of:
  • list[str | int | float]
  • None
--
protection_marginfloat0.0-
num_holes_rangetuple[int, int](1, 1)-
hole_height_rangetuple[float, float](0.05, 0.2)-
hole_width_rangetuple[float, float](0.05, 0.2)-
fillDropoutFillValue0-
fill_mask
One of:
  • tuple[float, ...]
  • float
  • None
--
pfloat0.5-