albumentations.augmentations.dropout.channel_dropout


Replace a fraction of eligible channels with a fill value to model missing spectral bands or unavailable sensors while retaining at least one input channel.

Members

ChannelDropoutclass

ChannelDropout(
    channels_to_drop: tuple[int, ...] | None,
    dropout_ratio: float = 0.5,
    fill: float | mean = 0,
    p: float = 0.5
)

Replace a fraction of eligible channels with a fill value to model missing spectral bands or unavailable sensors while retaining at least one input channel.

Parameters

NameTypeDefaultDescription
channels_to_drop
One of:
  • tuple[int, ...]
  • None
-Unique, non-negative channel indices eligible for dropout. None makes every input channel eligible. An explicit sequence must be non-empty, and every index must exist in each image-like target. Default: None.
dropout_ratiofloat0.5Fraction of eligible channels to replace, in [0, 1]. The count is rounded to the nearest integer using decimal half-up rounding, then capped at the total number of input channels minus one. Default: 0.5.
fill
One of:
  • float
  • mean
0A constant in the input dtype's image range, or "mean" to replace each selected channel with its own spatial mean. Means are computed separately for each image or volume, over all pixels or voxels in that channel. For uint8, the mean is rounded to the nearest integer. Positive and negative zero are equivalent. Default: 0.
pfloat0.5Probability of applying the transform, in [0, 1]. Default: 0.5.

Examples

>>> import numpy as np
>>> import albumentations as A
>>> image = np.ones((64, 96, 10), dtype=np.float32)
>>> transform = A.ChannelDropout(
...     channels_to_drop=(0, 2, 4, 6), dropout_ratio=0.5, p=1.0,
... )
>>> result = transform(image=image)["image"]
>>> assert np.count_nonzero(np.all(result == 0, axis=(0, 1))) == 2
>>> np.testing.assert_array_equal(result[..., (1, 3, 5, 7, 8, 9)], 1)

Notes

- Channels are selected uniformly without replacement from the eligible set. - The fraction is measured against eligible channels, not all input channels. With four eligible channels, dropout_ratio=0.5 selects two of them. - At least one input channel is retained. A single-channel input is unchanged. - A zero ratio or a count rounded to zero leaves the input unchanged. - Targets with equal channel counts share the selected indices, including all frames in an image batch and all slices in a volume. Different channel counts receive separate selections. - Retained channel values are unchanged; no dropout rescaling is applied.