albumentations.augmentations.dropout.guided_coarse_dropout
Apply coarse dropout within a caller-supplied binary region while preserving selected bounding boxes and filtering annotations by the actual dropout mask.
Members
- classGuidedCoarseDropout
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: float | tuple[float, ...] | random | random_uniform | inpaint_telea | inpaint_ns | grayscale = 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.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| region_key | str | dropout_region | Top-level key containing the binary (H, W) dropout region. Default: "dropout_region". |
| protected_bbox_labels | One of:
| - | Labels of boxes to protect. String labels use the configured bbox label encoder. Default: None. |
| protection_margin | float | 0.0 | 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] | (1, 1) | Inclusive number of holes sampled per image. Default: (1, 1). |
| hole_height_range | tuple[float, float] | (0.05, 0.2) | Hole-height fraction of the full image height. Default: (0.05, 0.20). |
| hole_width_range | tuple[float, float] | (0.05, 0.2) | Hole-width fraction of the full image width. Default: (0.05, 0.20). |
| fill | One of:
| 0 | Value used for dropped image pixels. Default: 0. |
| fill_mask | One of:
| - | Value used for dropped mask pixels. None leaves masks unchanged. Default: None. |
| p | float | 0.5 | Probability of applying the transform. Default: 0.5. |
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.