das.augmentation

Waveform level augmentations.

Individual implementations of Augmentation are callables that accept the signal to augment as an argument and return the augmented signal.

Augmentation parameters can be Constant, or random with Normal or Uniform distribution. Random parameters will be sampled from a given distribution anew for each augmentation.

aug = Gain(gain=Normal(mean=1, std=0.5)); augmented_signal = aug(signal)

Can be configured using a yaml file: ```yaml Gain: # Name of the augmentation class

gain: # arg for the augmentation class
Uniform: # Param type

lower: 0.5 # param args upper: 2 # param args

MaskNoise:
std:
Normal:

mean: 0 std: 0.05

mean:
Constant:

value: 0

NotchFilter:
freq: # Param-type arg
Uniform:

lower: 100 upper: 600

Q: 30 # standard arg samplerate_Hz: 10_000 # standard arg

``` Caution: You need to add a suffix starting with ‘-’ (like “MaskNoise-1”) to the class name if you want to use a class multiple times

augs = Augmentations.from_yaml(filename)

class das.augmentation.Augmentation[source]

Base class for all augmentations.

Augmentations are callables that return the augmented input. Can optionally pass through a second input.

batch_x is expected to be [batch, time, channel]. _apply works on [time, channel] inputs

class das.augmentation.Augmentations(augmentations: List[das.augmentation.Augmentation])[source]

Bundles several augmentations.

Parameters

augmentations (List[Augmentation]) – List of Augmentation instances.

class das.augmentation.CircShift(shift: das.augmentation.Param)[source]

Circularly shift input along the first axis.

Parameters

shift (Param) – Amount of shift, in samples.

class das.augmentation.Constant(value: float = 0.0)[source]

Constant parameter.

Parameters

value (float, optional) – Constant parameter value. Defaults to 0.0.

class das.augmentation.Gain(gain: das.augmentation.Param)[source]

Multiply signal with gain factor.

Parameters

gain (Param) – Gain.

class das.augmentation.HorizontalFlip(flip: das.augmentation.Param)[source]

Horizontally flip signal.

Parameters

flip (Param) – Signal is flipped if >0.

class das.augmentation.MaskMean(duration: das.augmentation.Param)[source]

Replaces stretch of duration samples with mean over that stretch.

Parameters

duration (Param) – Duration of the stretch, in samples.

class das.augmentation.MaskNoise(std: Optional[das.augmentation.Param] = None, mean: Optional[das.augmentation.Param] = None, duration: Optional[das.augmentation.Param] = None, add: bool = True)[source]

Add noise or replace signal by noise for the full duration or a part of it.

Parameters
  • std (Optional[Param]) – std of noise. Defaults to 1.

  • mean (Optional[Param]) – mean of noise. Defaults to 0.

  • duration (Optional[Param]) – nb_samples, Optional. If omitted will mask full duration.

  • add (bool) – add or replace. Defaults to True.

class das.augmentation.Normal(mean: float = 0.0, std: float = 1.0)[source]

Normally distributed parameter.

Parameters
  • mean (float, optional) – Mean of the Normal pdf. Defaults to 0.0.

  • std (float, optional) – Standerd deviation of the Normal pdf. Defaults to 1.0.

class das.augmentation.NotchFilter(freq: das.augmentation.Param, Q: float = 30, samplerate_Hz: float = 10000)[source]

Notch filter.

Parameters

freq (Param) – freq to remove, in Hz.

class das.augmentation.Offset(offset: das.augmentation.Param)[source]

Add horizontal offset.

Parameters

offset (Param) – Offset.

class das.augmentation.Param[source]

Base class for all parameters.

Parameters are callables that return parameter values.

class das.augmentation.Uniform(lower: float = - 1.0, upper: float = 1.0)[source]

Uniformly distributed parameter.

Parameters
  • lower (float, optional) – Lower bound. Defaults to -1.0.

  • upper (float, optional) – Upper bound. Defaults to 1.0.

class das.augmentation.Upsampling(factor: das.augmentation.Param)[source]

Upsample signal.

Parameters

factor (Param) – Upsampling factor.

Raises

ValueError – if ‘lower’ attr of factor is <1 (would correspond to downsampling).