braindecode.datasets.pad_channels_collate#
- braindecode.datasets.pad_channels_collate(batch, pad_value=0.0, pos_pad_value=0.0)[source]#
Collate variable-channel windows by padding channels to the batch maximum.
Each item of
batchis the tuple returned by a windowed dataset’s__getitem__: either(X, y, crop_inds)or, whenreturn_ch_pos=True(seebraindecode.datasets.BaseConcatDataset.set_return_ch_pos()),(X, y, crop_inds, ch_pos). Signals with different numbers of channels are zero-padded along the channel axis tomax_ch(the largest channel count in the batch) so they can be stacked into a single tensor, and a booleanch_maskmarks the real (non-padded) channels.The time dimension is assumed uniform (fixed-length windows); a
ValueErroris raised otherwise.This makes a heterogeneous collection batchable. Consuming the result (so a model ignores padded channels) requires a position/channel-aware model; fixed-geometry models (e.g.
ShallowFBCSPNet) structurally need a constant channel count and cannot use variable batches.- Parameters:
- Returns:
X (torch.Tensor) – Padded signals, shape
(batch, max_ch, n_times).y (torch.Tensor) – Targets, collated with
default_collate.crop_inds (list) – Crop indices, collated with
default_collate.ch_pos (torch.Tensor) – Only when the samples include positions. Padded positions, shape
(batch, max_ch, 3).ch_mask (torch.Tensor) – Boolean mask, shape
(batch, max_ch);Truefor real channels,Falsefor padding.
Examples using braindecode.datasets.pad_channels_collate#
Training on recordings with different channels (heterogeneous montages)