SequentialAug

class selfeeg.augmentation.compose.SequentialAug(*augmentations)[source]

Multiple augmentations applied sequentially.

SequentialAug applies a sequence of augmentations in a specified order. No random choice between the given list of augmentation is performed, just pure call of all the augmentations in the specified order.

To perform an augmentation, simply call the instantiated class (see provided example or check the introductory notebook)

Parameters:

*augmentations ("callable objects") – The sequence of augmentations to apply at each call. It can be any callable object, but the first argument to pass must be the element to augment. It is suggested to give a sequence of StaticSingleAug or DynamicSingleAug instantiations.

Note

If you provide an augmentation implemented outside of this this library, be sure that the function will return a single output with the element to pass to the next augmentation function of the list.

Note

The function will automatically handle RandomAug instances with return_index set to True. In this case, an internal deepcopy with return_index set to false will be automatically created.

perform_augmentation(X: ArrayLike)[source]

Apply the augmentations with the given arguments and specified order. __call__() will call this method.

Example

>>> import selfeeg.augmentation as aug
>>> import torch
>>> BatchEEG = torch.zeros(16,32,1024) + torch.sin(torch.linspace(0, 8*np.pi,1024))
>>> Aug_eye = aug.StaticSingleAug(aug.add_eeg_artifact,{'Fs': 64, 'artifact': 'eye', 'amplitude': 0.5})
>>> Aug_warp = aug.DynamicSingleAug(
...     aug.warp_signal,
...     discrete_arg = {'batch_equal': [True, False]},
...     range_arg= {'segments': [5,15], 'stretch_strength': [1.5,1.8],
...                 'squeeze_strength': [0.5,2/3]},
...     range_type={'segments': True, 'stretch_strength': False,
...                 'squeeze_strength': False}
... )
>>> Sequence1= aug.SequentialAug(Aug_eye, Aug_warp)
>>> BatchEEGaug1 = Sequence1(BatchEEG)
>>> BatchEEGaug2 = Sequence1(BatchEEG)

plot the augmentations (require matplotlib to be installed)

>>> import matplotlib.pyplot as plt
>>> plt.style.use('seaborn-v0_8-white')
>>> plt.rcParams['figure.figsize'] = (15.0, 6.0)
>>> plt.plot(BatchEEG[0,0],linewidth=2.5)
>>> plt.plot(BatchEEGaug1[0,0])
>>> plt.plot(BatchEEGaug2[0,0])
>>> plt.tick_params(axis='both', which='major', labelsize=12)
>>> plt.title(
...     'Sequential Aug with eye blink artifact and warp augmentation',
...     fontsize=15)
>>> plt.legend(['original sample', 'augmented sample 1', 'augmented sample 2'])
>>> plt.show()