albumentations.augmentations.dropout.transforms
Transform classes for dropout-based augmentations. This module contains transform classes for various dropout techniques used in image augmentation. It provides the base dropout class and specialized implementations like PixelDropout. These transforms randomly remove or modify pixels, channels, or regions in images, which can help models become more robust to occlusions and missing information.
Members
- classBaseDropout
- classPixelDropout
BaseDropoutclass
BaseDropout(
fill: tuple[float, ...] | float | Literal['random', 'random_uniform', 'inpaint_telea', 'inpaint_ns'],
fill_mask: tuple[float, ...] | float | None,
p: float
)
Base class for dropout-style transformations. This class provides common functionality for various dropout techniques, including applying cutouts to images and masks.
Parameters
Name | Type | Default | Description |
---|---|---|---|
fill | One of:
| - | Value to fill dropped regions. |
fill_mask | One of:
| - | Value to fill dropped regions in the mask. If None, the mask is not modified. |
p | float | - | Probability of applying the transform. |
PixelDropoutclass
PixelDropout(
dropout_prob: float = 0.01,
per_channel: bool = False,
drop_value: tuple[float, ...] | float | None = 0,
mask_drop_value: tuple[float, ...] | float | None = None,
p: float = 0.5
)
Drops random pixels from the image. This transform randomly sets pixels in the image to a specified value, effectively "dropping out" those pixels. It can be applied to both the image and its corresponding mask.
Parameters
Name | Type | Default | Description |
---|---|---|---|
dropout_prob | float | 0.01 | Probability of dropping out each pixel. Should be in the range [0, 1]. Default: 0.01 |
per_channel | bool | False | If True, the dropout mask will be generated independently for each channel. If False, the same dropout mask will be applied to all channels. Default: False |
drop_value | One of:
| 0 | Value to assign to the dropped pixels. If None, the value will be randomly sampled for each application: - For uint8 images: Random integer in [0, 255] - For float32 images: Random float in [0, 1] If a single number, that value will be used for all dropped pixels. If a sequence, it should contain one value per channel. Default: 0 |
mask_drop_value | One of:
| None | Value to assign to dropped pixels in the mask. If None, the mask will remain unchanged. If a single number, that value will be used for all dropped pixels in the mask. If a sequence, it should contain one value per channel. Default: None |
p | float | 0.5 | Probability of applying the transform. Should be in the range [0, 1]. Default: 0.5 |
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)
>>> transform = A.PixelDropout(dropout_prob=0.1, per_channel=True, p=1.0)
>>> result = transform(image=image, mask=mask)
>>> dropped_image, dropped_mask = result['image'], result['mask']
Notes
- When applied to bounding boxes, this transform may cause some boxes to have zero area if all pixels within the box are dropped. Such boxes will be removed. - When applied to keypoints, keypoints that fall on dropped pixels will be removed if the keypoint processor is configured to remove invisible keypoints.