Dataset
SubjectsDataset
Bases: Dataset
Base TorchIO dataset.
Reader of 3D medical images that directly inherits from the PyTorch
Dataset. It can be used with a
SubjectsLoader for efficient loading and
augmentation. It receives a list of instances of Subject
and an optional transform applied to the volumes after loading.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subjects
|
Sequence[Subject]
|
List of instances of |
required |
transform
|
Callable | None
|
An instance of |
None
|
load_getitem
|
bool
|
Load all subject images before returning it in
|
True
|
Examples:
>>> import torchio as tio
>>> subject_a = tio.Subject(
... t1=tio.ScalarImage('t1.nrrd',),
... t2=tio.ScalarImage('t2.mha',),
... label=tio.LabelMap('t1_seg.nii.gz'),
... age=31,
... name='Fernando Perez',
... )
>>> subject_b = tio.Subject(
... t1=tio.ScalarImage('colin27_t1_tal_lin.minc',),
... t2=tio.ScalarImage('colin27_t2_tal_lin_dicom/',),
... label=tio.LabelMap('colin27_seg1.nii.gz'),
... age=56,
... name='Colin Holmes',
... )
>>> subjects_list = [subject_a, subject_b]
>>> transforms = [
... tio.RescaleIntensity(out_min_max=(0, 1)),
... tio.RandomAffine(),
... ]
>>> transform = tio.Compose(transforms)
>>> subjects_dataset = tio.SubjectsDataset(subjects_list, transform=transform)
>>> subject = subjects_dataset[0]
Iterating without loading
To quickly iterate over the subjects without loading the images,
use dry_iter().
from_batch(batch)
classmethod
Instantiate a dataset from a batch generated by a data loader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
dict
|
Dictionary generated by a data loader, containing data that can be converted to instances of [Subject][.torchio.Subject]. |
required |
dry_iter()
set_transform(transform)
Set the transform attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transform
|
Callable | None
|
Callable object, typically an subclass of
|
required |