clinicadl.data.dataloader.collate.ToBatchesCollate

class clinicadl.data.dataloader.collate.ToBatchesCollate[source]

To return a sequence of batches.

This is the default collating mode when the Dataset returns a sequence of Sample.

Examples

from clinicadl.data.dataloader import ToBatchesCollate
from clinicadl.data.structures.examples import Colin27Sample

sample_1 = Colin27Sample(participant_id="sub-001")
sample_2 = Colin27Sample(participant_id="sub-002")
sample_3 = Colin27Sample(participant_id="sub-003")
sample_4 = Colin27Sample(participant_id="sub-004")
batch = ToBatchesCollate()([(sample_1, sample_2), (sample_3, sample_4)])
>>> batch[0]
[Colin27Sample(Keys: ('head', 'file_type', 'image_path', 'sample_type', 'sample_position', 'image', 'participant_id', 'session_id'); images: 2),
 Colin27Sample(Keys: ('head', 'file_type', 'image_path', 'sample_type', 'sample_position', 'image', 'participant_id', 'session_id'); images: 2)]
>>> batch[0][0].participant_id
'sub-001'
>>> batch[0][1].participant_id
'sub-003'

See also

MergeBatchesCollate

To merge several batches into a single batch.

__call__(samples: Sequence[Sequence[T]]) tuple[Batch[T], ...][source]

Puts a sequence of sequences of Sample in a tuple of Batch.

E.g., if the dataset returns two samples, the output here will be a tuple of two batches.

Parameters:

samples (Sequence[Sequence[T]]) – A sequence of sequences of Sample.

Returns:

tuple[Batch[T], …] – A tuple of Batch, whose dimension is equal to the 2nd dimension of samples.