CalgarySliceDataset#
- class deepinv.datasets.CalgarySliceDataset(root, transform=None, **kwargs)[source]#
Bases:
FastMRISliceDatasetDataset for Calgary-Campinas 12-coil raw brain kspace.
Loads Calgary
h5volumes of shape(num_slices, H, W, 2N), where slice dim is in image domain andH,Wis kspace. The dataset loads and preprocesses all kspace slices per volume, of shape(2, N, H, W). These are fully-sampled for train/val volumes and masked for the test set.Also computes the GT
x, the magnitude root-sum-square reconstructions of shape(1, H, W), ortorch.nanfor the masked test set.The dataset is loaded as a dict with keys
'x', 'y', 'params'whenuse_dict_output=True(default) or tuples(x, y, params)whenFalse, whereparamsoptionally contains the samplingmaskand, if desired, estimatedcoil_maps.Note
The test set comes already masked, which
deepinv.datasets.CalgarySliceTransformestimates. For the validation set, the data is fully-sampled. You can simulate masked data using precomputed Poisson-disk masks as followsmask_file = f"R{acceleration}_{y.shape[-2]}x{y.shape[-1]}.npy" torch.hub.download_url_to_file(f"https://huggingface.co/datasets/NKI-AI/direct-mri-masks/resolve/main/calgary_campinas_masks/{mask_file.name}", str(mask_file)) masks = np.load(mask_file) # (100, H, W) bool mask = torch.from_numpy(masks[0]).float().unsqueeze(0).unsqueeze(0) # (1, 1, H, W) y *= mask
Calgary kspace uses the opposite centering convention to deepinv, so it is converted here (a half-FOV checkerboard shift) so that
yworks directly withdeepinv.physics.MultiCoilMRI.- Parameters:
root (str, pathlib.Path) – path to the dataset.
transform (Callable) – transform taking
(target, kspace), defaults todeepinv.datasets.CalgarySliceTransform.kwargs – passed to
deepinv.datasets.FastMRISliceDataset(e.g.slice_index,filter_id, metadata cache,use_dict_output).
- Examples:
Download a Calgary test volume and load its middle slice:
>>> import deepinv as dinv >>> from deepinv.datasets import CalgarySliceDataset, download_archive >>> root = dinv.utils.get_cache_home() / "calgary" >>> download_archive(dinv.utils.get_image_url("demo_calgary_test_e13991s3_P01536.7.h5"), root / "vol.h5") >>> batch = CalgarySliceDataset(root, slice_index="middle", use_dict_output=True)[0] >>> batch['y'].shape # (2, N, H, W) multicoil k-space torch.Size([2, 12, 218, 170])
Examples using CalgarySliceDataset:#
Reconstruct undersampled k-space for cardiac and brain MRI