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 batch is the tuple returned by a windowed dataset’s __getitem__: either (X, y, crop_inds) or, when return_ch_pos=True (see braindecode.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 to max_ch (the largest channel count in the batch) so they can be stacked into a single tensor, and a boolean ch_mask marks the real (non-padded) channels.

The time dimension is assumed uniform (fixed-length windows); a ValueError is 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:
  • batch (list of tuple) – Samples from a windowed dataset (see above).

  • pad_value (float) – Value used to pad the signal X channel rows (default 0.0).

  • pos_pad_value (float) – Value used to pad the position ch_pos rows (default 0.0).

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); True for real channels, False for padding.

Examples using braindecode.datasets.pad_channels_collate#

Training on recordings with different channels (heterogeneous montages)

Training on recordings with different channels (heterogeneous montages)