FastMRISliceDataset
- class deepinv.datasets.FastMRISliceDataset(root: str | ~pathlib.Path, test: bool, challenge: str, load_metadata_from_cache: bool = False, save_metadata_to_cache: bool = False, metadata_cache_file: str | ~pathlib.Path = 'dataset_cache.pkl', sample_filter: ~typing.Callable = <function FastMRISliceDataset.<lambda>>, sample_rate: float | None = None, volume_sample_rate: float | None = None, transform_kspace: ~typing.Callable | None = None, transform_target: ~typing.Callable | None = None)[source]
Bases:
Dataset
Dataset for fastMRI that provides access to MR image slices.
1) The fastMRI dataset includes two types of MRI scans: knee MRIs andthe brain (neuro) MRIs, and containing training, validation, and masked test sets.2) MRIs are volumes (3D) made of slices (2D).3) This class in particular considers one data sample as one slice of a MRI scan,thus slices of the same MRI scan are considered independently in the dataset.Raw data file structure:
self.root --- file1000005.h5 | -- xxxxxxxxxxx.h5
0) To download raw data, please go to the bottom of the page https://fastmri.med.nyu.edu/1) Each MRI scan is stored in a HDF5 file and can be read with the h5py package.Each file contains the k-space data, ground truth and some meta data related to the scan.2) MRI scans can either be single-coil or multi-coil with each coil ina multi-coil MRI scan focusses on a different region of the image.3) In multi-coil MRIs, k-space data has the following shape:(number of slices, number of coils, height, width)4) For single-coil MRIs, k-space data has the following shape:(number of slices, height, width)- Parameters:
root (Union[str, Path]) – Path to the dataset.
test (bool) – Whether the split is the “test” set.
challenge (str) – “singlecoil” or “multicoil” depending on the type of mri scan.
load_metadata_from_cache (bool) – Whether to load dataset metadata from cache.
save_metadata_to_cache (bool) – Whether to cache dataset metadata.
metadata_cache_file (Union[str, Path]) – A file used to cache dataset information for faster load times.
sample_filter (callable, optional) – A callable object that takes a
SliceSampleFileIdentifier()
as input and returns a boolean indicating whether the sample should be included in the dataset.sample_rate (float, optional) – A float between 0 and 1. This controls what fraction of all slices should be loaded. Defaults to 1. When creating a sampled dataset either set sample_rate (sample by slices) or volume_sample_rate (sample by volumes) but not both.
volume_sample_rate (float, optional) – A float between 0 and 1. This controls what fraction of the volumes should be loaded. Defaults to 1 if no value is given. When creating a sampled dataset either set sample_rate (sample by slices) or volume_sample_rate (sample by volumes) but not both.
transform_kspace (callable, optional) – A function/transform that takes in the kspace and returns a transformed version. E.g,
torchvision.transforms.RandomCrop
transform_target (callable, optional) – A function/transform that takes in the target and returns a transformed version. E.g,
torchvision.transforms.RandomCrop
- Examples:
Instanciate dataset without transform
from deepinv.datasets import FastMRISliceDataset root = "/path/to/dataset/fastMRI/knee_singlecoil/train" dataset = FastMRISliceDataset(root=root, test=False, challenge="singlecoil") target, kspace = dataset[0] print(target.shape) print(kspace.shape)
Instanciate dataset with transform
from torchvision import transforms transform = transforms.Compose([ transforms.ToTensor(), transforms.RandomCrop((256, 256), pad_if_needed=True), transforms.RandomHorizontalFlip(p=0.5), transforms.RandomVerticalFlip(p=0.5), ]) # Define the transform pipeline root = "/path/to/dataset/fastMRI/knee_singlecoil/train" dataset = FastMRISliceDataset(root=root, test=False, challenge="multicoil", transform_kspace=transform, transform_target=transform) target, kspace = dataset[0] print(target.shape) print(kspace.shape)