braindecode.augmentation.CutMix#
- class braindecode.augmentation.CutMix(alpha, beta_per_sample=False, random_state=None)[source]#
Implements CutMix for EEG data.
A random time region of each example is replaced by the same region of a shuffled example of the batch, see [1]. As in the reference code [2], a coefficient
lamis drawn from a Beta distribution, the region is(1 - lam) * n_timeslong (the 1-D analogue of the cut area ratio1 - lam) around a uniformly drawn center, it is clipped at the trial boundaries, andlamis then recomputed from the pasted length.Like
Mixup, it applies to whole batches and returns targets(y_a, y_b, lam)forbraindecode.training.mixup_criterion().- Parameters:
alpha (float) – Parameter of the Beta distribution of
lam.alpha <= 0cuts nothing.beta_per_sample (bool (default=False)) – By default, one
lamper batch is drawn. If True, one per sample.random_state (int | numpy.random.Generator, optional) – Seed to be used to instantiate numpy random number generator instance. Defaults to None.
References
[1]Sangdoo Yun, Dongyoon Han, Seong Joon Oh, Sanghyuk Chun, Junsuk Choe, Youngjoon Yoo (2019). CutMix: Regularization Strategy to Train Strong Classifiers with Localizable Features. In 2019 IEEE/CVF International Conference on Computer Vision (ICCV) Online: https://arxiv.org/abs/1905.04899
Methods
- get_augmentation_params(*batch)[source]#
Return idx_perm and the cut_t_start, cut_t_len of each region.
- static operation(X, y, idx_perm, cut_t_start, cut_t_len)[source]#
Paste a time region of shuffled examples into the original examples.
See [1] for details.
- Parameters:
X (
Tensor) – EEG data in formbatch_size, n_channels, n_timesy (
Tensor) – Target of lengthbatch_sizeidx_perm (
Tensor) – Permuted indices of example that are mixed into original examples.cut_t_start (
Tensor) – Start index of the pasted time region for each example.cut_t_len (
Tensor) – Length of the pasted time region for each example.
- Returns:
X,y. WhereXis augmented andyis a tuple of length 3 containing the labels of the two mixed examples and the fraction of each example kept from the original,1 - cut_t_len / n_times.- Return type:
References
[1]Sangdoo Yun, Dongyoon Han, Seong Joon Oh, Sanghyuk Chun, Junsuk Choe, Youngjoon Yoo (2019). CutMix: Regularization Strategy to Train Strong Classifiers with Localizable Features. In 2019 IEEE/CVF International Conference on Computer Vision (ICCV) Online: https://arxiv.org/abs/1905.04899