Skip to content

Instantly share code, notes, and snippets.

@jcreinhold
Created January 3, 2019 15:16
Show Gist options
  • Save jcreinhold/5b8ae8a675139aeb4c33ef071a85e864 to your computer and use it in GitHub Desktop.
Save jcreinhold/5b8ae8a675139aeb4c33ef071a85e864 to your computer and use it in GitHub Desktop.
dataloaders for fastai
import fastai.vision as faiv
import nibabel as nib
def open_nii(fn:str) -> faiv.Image:
""" Return fastai `Image` object created from NIfTI image in file `fn`."""
x = nib.load(str(fn)).get_data()
return faiv.Image(torch.Tensor(x))
class NiftiItemList(faiv.ImageItemList):
""" custom item list for nifti files """
def open(self, fn:faiv.PathOrStr)->faiv.Image: return open_nii(fn)
class NiftiNiftiList(NiftiItemList):
""" item list suitable for synthesis tasks """
_label_cls = NiftiItemList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment