albumentations.augmentations.dropout.mask_dropout
Implementation of mask-based dropout augmentation. This module provides the MaskDropout transform, which identifies objects in a segmentation mask and drops out random objects completely. This augmentation is particularly useful for instance segmentation and object detection tasks, as it simulates occlusions or missing objects in a semantically meaningful way, rather than dropping out random pixels or regions.
Members
- classMaskDropout
MaskDropoutclass
MaskDropout(
max_objects: tuple[int, int] | int = (1, 1),
fill: float | Literal['inpaint_telea', 'inpaint_ns'] = 0,
fill_mask: float = 0,
p: float = 0.5
)
Apply dropout to random objects in a mask, zeroing out the corresponding regions in both the image and mask. This transform identifies objects in the mask (where each unique non-zero value represents a distinct object), randomly selects a number of these objects, and sets their corresponding regions to zero in both the image and mask. It can also handle bounding boxes and keypoints, removing or adjusting them based on the dropout regions.
Parameters
Name | Type | Default | Description |
---|---|---|---|
max_objects | One of:
| (1, 1) | Maximum number of objects to dropout. If a single int is provided, it's treated as the upper bound. If a tuple of two ints is provided, it's treated as a range [min, max]. |
fill | One of:
| 0 | Value to fill dropped out regions in the image. Can be one of: - float: Constant value to fill the regions (e.g., 0 for black, 255 for white) - "inpaint_telea": Use Telea inpainting algorithm (for 3-channel images only) - "inpaint_ns": Use Navier-Stokes inpainting algorithm (for 3-channel images only) |
fill_mask | float | 0 | Value to fill the dropped out regions in the mask. |
p | float | 0.5 | Probability of applying the transform. Default: 0.5. |
Example
>>> import numpy as np
>>> import albumentations as A
>>>
>>> # Define a sample image, mask, and bounding boxes
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>> mask = np.zeros((100, 100), dtype=np.uint8)
>>> mask[20:40, 20:40] = 1 # Object 1
>>> mask[60:80, 60:80] = 2 # Object 2
>>> bboxes = np.array([[20, 20, 40, 40], [60, 60, 80, 80]])
>>>
>>> # Define the transform
>>> transform = A.Compose([
... A.MaskDropout(max_objects=1, mask_fill_value=0, min_area=100, min_visibility=0.5, p=1.0),
... ], bbox_params=A.BboxParams(format='pascal_voc', min_area=1, min_visibility=0.1))
>>>
>>> # Apply the transform
>>> transformed = transform(image=image, mask=mask, bboxes=bboxes)
>>>
>>> # The result will have one of the objects dropped out in both image and mask,
>>> # and the corresponding bounding box removed if it doesn't meet the area and visibility criteria
Notes
- The mask should be a single-channel image where 0 represents the background and non-zero values represent different object instances. - For bounding box and keypoint augmentation, make sure to set up the corresponding processors in the pipeline.