omniloader.transforms.augment

Augmentation transforms: feature corruption, dropout and span masking.

These transforms are train_only — they self-skip during evaluation. Each one respects the validity mask and is fully reproducible from an optional torch.Generator.

Literature techniques covered: Gaussian noise injection (feature corruption), whole-feature (“stream”/modality) dropout, and contiguous span masking over sequences (SpecAugment-style temporal masking).

Classes

GaussianNoise

Add zero-mean Gaussian noise to feature values (feature corruption).

FeatureDropout

Drop entire features ("stream"/modality dropout).

SpanMasking

Zero contiguous spans of sequence features (SpecAugment-style masking).

TimeWarp

Randomly stretch/squeeze the sequence in time (speed perturbation).

FeatureMasking

Zero contiguous bands of feature dimensions (channel/frequency masking).

Module Contents

class omniloader.transforms.augment.GaussianNoise(keys: collections.abc.Sequence[str] | None = None, std: float = 0.1, p: float = 0.5, schema: omniloader.schema.spec.UnifiedSchema | None = None)[source]

Bases: omniloader.transforms.base.Transform

Add zero-mean Gaussian noise to feature values (feature corruption).

Parameters:
  • keys – Feature keys to corrupt. When None, every feature in the schema is eligible (requires schema).

  • std – Standard deviation of the additive noise.

  • p – Per-sample probability of applying noise to each key.

  • schema – Schema used to resolve keys when it is None.

apply(sample: omniloader.transforms.base.Sample, generator: torch.Generator | None) → omniloader.transforms.base.Sample[source]

Add noise to each eligible key with probability p.

class omniloader.transforms.augment.FeatureDropout(keys: collections.abc.Sequence[str] | None = None, p: float = 0.2, keep_at_least_one: bool = True, schema: omniloader.schema.spec.UnifiedSchema | None = None)[source]

Bases: omniloader.transforms.base.Transform

Drop entire features (“stream”/modality dropout).

With probability p a feature’s value is zeroed and its mask set to all False, so a model treats it as absent. This generalises modality dropout to any set of feature streams. Optionally guarantees at least one eligible feature survives.

Parameters:
  • keys – Feature keys eligible for dropout. When None, every feature in the schema is eligible (requires schema).

  • p – Per-sample probability of dropping each eligible feature.

  • keep_at_least_one – When True, never drop the last surviving feature.

  • schema – Schema used to resolve keys when it is None.

apply(sample: omniloader.transforms.base.Sample, generator: torch.Generator | None) → omniloader.transforms.base.Sample[source]

Zero and invalidate each eligible feature with probability p.

class omniloader.transforms.augment.SpanMasking(keys: collections.abc.Sequence[str] | None = None, num_spans: int = 1, span_len: int = 5, p: float = 0.5, schema: omniloader.schema.spec.UnifiedSchema | None = None)[source]

Bases: omniloader.transforms.base.Transform

Zero contiguous spans of sequence features (SpecAugment-style masking).

For each configured sequence feature, up to num_spans contiguous spans of length span_len are zeroed within the valid region. The validity mask is left intact — the positions still exist for the model and for targets; only their input content is corrupted, encouraging temporal robustness.

Parameters:
  • keys – Sequence-feature keys to mask. When None, every sequence feature in the schema is eligible (requires schema).

  • num_spans – Number of spans to mask per key.

  • span_len – Length of each span along the sequence axis.

  • p – Per-sample probability of masking each eligible key.

  • schema – Schema used to resolve sequence keys when it is None.

apply(sample: omniloader.transforms.base.Sample, generator: torch.Generator | None) → omniloader.transforms.base.Sample[source]

Zero up to num_spans spans per eligible sequence feature.

class omniloader.transforms.augment.TimeWarp(min_rate: float = 0.8, max_rate: float = 1.25, keys: collections.abc.Sequence[str] | None = None, p: float = 0.5, schema: omniloader.schema.spec.UnifiedSchema | None = None)[source]

Bases: omniloader.transforms.base.Transform

Randomly stretch/squeeze the sequence in time (speed perturbation).

A single warp rate r in [min_rate, max_rate] is shared across the targeted keys (so aligned features stay in sync): each sequence is resampled to round(T * r) steps via linear interpolation and resized back to T. Only floating-point sequence features are warped by default (interpolating integer class labels would be meaningless).

Parameters:
  • min_rate – Minimum warp rate (< 1 squeezes, > 1 stretches).

  • max_rate – Maximum warp rate.

  • keys – Sequence keys to warp with a shared rate. When None, all floating-point sequence feature keys in the schema are used.

  • p – Per-sample probability of warping.

  • schema – Schema used to resolve keys when it is None.

apply(sample: omniloader.transforms.base.Sample, generator: torch.Generator | None) → omniloader.transforms.base.Sample[source]

Resample each targeted key by a single shared random rate.

class omniloader.transforms.augment.FeatureMasking(num_masks: int = 1, max_width: int = 4, keys: collections.abc.Sequence[str] | None = None, p: float = 0.5, schema: omniloader.schema.spec.UnifiedSchema | None = None)[source]

Bases: omniloader.transforms.base.Transform

Zero contiguous bands of feature dimensions (channel/frequency masking).

For each targeted key with a feature axis, num_masks bands of width up to max_width are zeroed across all time steps — the feature-axis analogue of SpanMasking.

Not supported for structured (e.g. image-sequence) specs, which have no single trailing feature axis to band-mask — a spec’s trailing shape is checked against schema when available (either passed directly, or via keys=None); use SpanMasking to mask whole time steps instead.

Parameters:
  • num_masks – Number of feature-dimension bands to zero per key.

  • max_width – Maximum band width along the feature axis.

  • keys – Feature keys to mask. When None, every feature in the schema is used (requires schema).

  • p – Per-sample probability of masking each eligible key.

  • schema – Schema used to resolve keys when it is None, and to reject structured (image-sequence) keys ahead of time.

apply(sample: omniloader.transforms.base.Sample, generator: torch.Generator | None) → omniloader.transforms.base.Sample[source]

Zero up to num_masks feature bands per eligible key.