← Back to all transforms
CoarseDropout
Description
CoarseDropout randomly drops out rectangular regions from the image and optionally, the corresponding regions in an associated mask, to simulate occlusion and varied object sizes found in real-world settings. This transformation is an evolution of CutOut and RandomErasing, offering more flexibility in the size, number of dropout regions, and fill values. Args: num_holes_range (tuple[int, int]): Range (min, max) for the number of rectangular regions to drop out. Default: (1, 1) hole_height_range (tuple[ScalarType, ScalarType]): Range (min, max) for the height of dropout regions. If int, specifies absolute pixel values. If float, interpreted as a fraction of the image height. Default: (8, 8) hole_width_range (tuple[ScalarType, ScalarType]): Range (min, max) for the width of dropout regions. If int, specifies absolute pixel values. If float, interpreted as a fraction of the image width. Default: (8, 8) fill_value (int | float | Literal["random"] | tuple[int | float,...]): Value for the dropped pixels. Can be: - int or float: all channels are filled with this value. - tuple: tuple of values for each channel. - 'random': filled with random values. Default: 0. mask_fill_value (ColorType | None): Fill value for dropout regions in the mask. If None, mask regions corresponding to image dropouts are unchanged. Default: None p (float): Probability of applying the transform. Default: 0.5 Targets: image, mask, bboxes, keypoints Image types: uint8, float32 Note: - The actual number and size of dropout regions are randomly chosen within the specified ranges for each application. - When using float values for hole_height_range and hole_width_range, ensure they are between 0 and 1. - This implementation includes deprecation warnings for older parameter names (min_holes, max_holes, etc.). Example: >>> import numpy as np >>> import albumentations as A >>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8) >>> mask = np.random.randint(0, 2, (100, 100), dtype=np.uint8) >>> augmentation = A.CoarseDropout(num_holes_range=(3, 6), ... hole_height_range=(10, 20), ... hole_width_range=(10, 20), ... fill_value=0, ... p=1.0) >>> transformed = augmentation(image=image, mask=mask) >>> transformed_image, transformed_mask = transformed["image"], transformed["mask"] References: - CutOut: https://arxiv.org/abs/1708.04552 - Random Erasing: https://arxiv.org/abs/1708.04896
Parameters
- fill_value: float | Sequence[float] | Literal['random'] (default: 0)
- mask_fill_value: float | Sequence[float] | None (default: null)
- num_holes_range: tuple[int, int] (default: (1, 1))
- hole_height_range: tuple[int | float, int | float] (default: (8, 8))
- hole_width_range: tuple[int | float, int | float] (default: (8, 8))
- p: float (default: 0.5)
Targets
- Image
- Mask
- BBoxes
- Keypoints
Try it out
ⓘ