braindecode.augmentation.LabelSmoothing#
- class braindecode.augmentation.LabelSmoothing(epsilon, num_classes=None, random_state=None)[source]#
Label smoothing from Szegedy et al. (2016) [1].
Replaces each target with its convex combination with the uniform distribution over the classes, penalizing over-confident predictions. The signals are returned unchanged; only the targets change.
The smoothed targets are floating-point distributions of shape
batch_size, num_classes(each row sums to one), so the training loss must accept target distributions, e.g. soft cross-entropy-(y * torch.log_softmax(logits, dim=-1)).sum(-1).mean()ortorch.nn.KLDivLoss. The transform composes before target-mixing transforms such asbraindecode.augmentation.Mixup, whose fractional-target path then mixes the smoothed distributions. The fixed-expansion mode (n_augmentation > 0) ofbraindecode.augmentation.AugmentedDataLoaderis not supported: it cannot concatenate the unsmoothed original targets with the reshaped smoothed copies and rejects the combination with aValueErrorpointing ton_augmentation = 0.- Parameters:
epsilon (float) – Smoothing parameter between 0 and 1: the weight of the uniform distribution mixed into the targets.
0disables smoothing.num_classes (int | None, optional) – Number of classes. Required when the targets are class indices; when the targets are already distributions of shape
batch_size, num_classes, it must match their last dimension. Defaults to None.random_state (int | numpy.random.Generator, optional) – Seed to be used to instantiate numpy random number generator instance. The transform is deterministic, so the seed only feeds the application-probability machinery, which is inactive here. Defaults to None.
References
[1]Christian Szegedy, Vincent Vanhoucke, Jonathon Shlens and Zbigniew Wojna (2016). Rethinking the Inception Architecture for Computer Vision. In 2016 IEEE Conference on Computer Vision and Pattern Recognition (CVPR), pp. 2818-2826. Online: https://arxiv.org/abs/1512.00567
Methods
- get_augmentation_params(*batch)[source]#
Return transform parameters.
- Parameters:
X (tensor.Tensor) – The data.
y (tensor.Tensor) – The labels.
- Returns:
params – Contains
- epsilonfloat
Smoothing parameter between 0 and 1.
- num_classesint | None
The number of classes.
- Return type:
- static operation(X, y, epsilon, num_classes=None)[source]#
Smooth targets toward the uniform distribution over the classes.
See [1] for details.
- Parameters:
X (
Tensor) – EEG data in formbatch_size, n_channels, n_times. Returned unchanged.y (
Tensor) – Target of lengthbatch_sizeholding class indices (float values are accepted when they are integral), or a floating-point tensor of shapebatch_size, num_classesholding target distributions.epsilon (
float) – Smoothing parameter between 0 and 1: the weight of the uniform distribution mixed into the targets.0returns the unsmoothed targets.num_classes (
int|None) – Number of classes. Required whenyholds class indices; whenyalready holds distributions, it must match the size of the last dimension ofy. Defaults to None.
- Returns:
X,y. WhereXis unchanged andyis a floating-point tensor of shapebatch_size, num_classeswhose rows sum to one.- Return type:
References
[1]Christian Szegedy, Vincent Vanhoucke, Jonathon Shlens and Zbigniew Wojna (2016). Rethinking the Inception Architecture for Computer Vision. In 2016 IEEE Conference on Computer Vision and Pattern Recognition (CVPR), pp. 2818-2826. Online: https://arxiv.org/abs/1512.00567