braindecode.training.iter_trial_prediction_chunks#

braindecode.training.iter_trial_prediction_chunks(module, dataset, *, windows_per_chunk, return_targets=True, batch_size=1, num_workers=0, loader_kwargs=None)[source]#

Yield predictions in chunks of at most windows_per_chunk windows.

Takes the arguments of iter_trial_predictions() and has the same lifecycle. A chunk never spans two trials and overlap removal carries across chunks, so concatenating a trial’s chunks along axis 1 gives its iter_trial_predictions() output exactly, for the predictions and for time targets. Memory holds one chunk, the loader batches and one window of lookahead, so it does not depend on the trial length.

Parameters:
Yields:

chunk (TrialPredictionChunk)

Examples

Read the first chunk of a two-window trial and stop. contextlib.closing() closes the iterator at the end of the block, which gives the model back its training mode.

>>> import torch
>>> from contextlib import closing
>>> from braindecode.training import iter_trial_prediction_chunks
>>> model = torch.nn.Conv1d(1, 1, kernel_size=1, bias=False)
>>> _ = model.train()
>>> windows = [(torch.ones(1, 4), 7, (i, 4 * i, 4 * (i + 1))) for i in range(2)]
>>> with closing(
...     iter_trial_prediction_chunks(
...         model,
...         windows,
...         windows_per_chunk=1,
...         return_targets=False,
...     )
... ) as chunks:
...     chunk = next(chunks)
...     print(
...         chunk.trial_index,
...         chunk.prediction_start,
...         chunk.prediction.shape,
...         chunk.target,
...         model.training,
...     )
...
0 0 (1, 4) None False
>>> model.training
True

Examples using braindecode.training.iter_trial_prediction_chunks#

Cropped Decoding on BCIC IV 2a Dataset

Cropped Decoding on BCIC IV 2a Dataset