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¶
Add zero-mean Gaussian noise to feature values (feature corruption). |
|
Drop entire features ("stream"/modality dropout). |
|
Zero contiguous spans of sequence features (SpecAugment-style masking). |
|
Randomly stretch/squeeze the sequence in time (speed perturbation). |
|
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.TransformAdd zero-mean Gaussian noise to feature values (feature corruption).
- Parameters:
keys – Feature keys to corrupt. When
None, every feature in the schema is eligible (requiresschema).std – Standard deviation of the additive noise.
p – Per-sample probability of applying noise to each key.
schema – Schema used to resolve
keyswhen it isNone.
- 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.TransformDrop entire features (“stream”/modality dropout).
With probability
pa feature’s value is zeroed and its mask set to allFalse, 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 (requiresschema).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
keyswhen it isNone.
- 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.TransformZero contiguous spans of sequence features (SpecAugment-style masking).
For each configured sequence feature, up to
num_spanscontiguous spans of lengthspan_lenare 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 (requiresschema).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
keyswhen it isNone.
- apply(sample: omniloader.transforms.base.Sample, generator: torch.Generator | None) omniloader.transforms.base.Sample[source]¶
Zero up to
num_spansspans 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.TransformRandomly stretch/squeeze the sequence in time (speed perturbation).
A single warp rate
rin[min_rate, max_rate]is shared across the targeted keys (so aligned features stay in sync): each sequence is resampled toround(T * r)steps via linear interpolation and resized back toT. Only floating-point sequence features are warped by default (interpolating integer class labels would be meaningless).- Parameters:
min_rate – Minimum warp rate (
< 1squeezes,> 1stretches).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
keyswhen it isNone.
- 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.TransformZero contiguous bands of feature dimensions (channel/frequency masking).
For each targeted key with a feature axis,
num_masksbands of width up tomax_widthare zeroed across all time steps — the feature-axis analogue ofSpanMasking.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
schemawhen available (either passed directly, or viakeys=None); useSpanMaskingto 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 (requiresschema).p – Per-sample probability of masking each eligible key.
schema – Schema used to resolve
keyswhen it isNone, 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_masksfeature bands per eligible key.