albumentations.augmentations.dropout.channel_dropout
Implementation of the Channel Dropout transform for multi-channel images. This module provides the ChannelDropout transform, which randomly drops (sets to a fill value) one or more channels in multi-channel images. This augmentation can help models become more robust to missing or corrupted channel information and encourage learning from all available channels rather than relying on a subset.
Members
- classChannelDropout
ChannelDropoutclass
Randomly drop channels in the input image. This transform randomly selects a number of channels to drop from the input image and replaces them with a specified fill value. This can improve model robustness to missing or corrupted channels. The technique is conceptually similar to: - Dropout layers in neural networks, which randomly set input units to 0 during training. - CoarseDropout augmentation, which drops out regions in the spatial dimensions of the image. However, ChannelDropout operates on the channel dimension, effectively "dropping out" entire color channels or feature maps.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| channel_drop_range | tuple[int, int] | (1, 1) | Range from which to choose the number of channels to drop. The actual number will be randomly selected from the inclusive range [min, max]. Default: (1, 1). |
| fill | float | 0 | Pixel value used to fill the dropped channels. Default: 0. |
| p | float | 0.5 | Probability of applying the transform. Must be in the range [0, 1]. Default: 0.5. |
Examples
>>> import numpy as np
>>> import albumentations as A
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>> transform = A.ChannelDropout(channel_drop_range=(1, 2), fill=128, p=1.0)
>>> result = transform(image=image)
>>> dropped_image = result['image']
>>> assert dropped_image.shape == image.shape
>>> assert np.any(dropped_image != image) # Some channels should be differentNotes
- The number of channels to drop is randomly chosen within the specified range. - Channels are randomly selected for dropping. - This transform is not applicable to single-channel (grayscale) images. - The transform will raise an error if it's not possible to drop the specified number of channels (e.g., trying to drop 3 channels from an RGB image). - This augmentation can be particularly useful for training models to be robust against missing or corrupted channel data in multi-spectral or hyperspectral imagery.