[docs]classRawDataLoader(BaseDataLoader):"""A specialized raw-data-loader for the VISCERAL database."""datadir:pathlib.Path"""This variable contains the base directory where the database raw data is stored."""def__init__(self)->None:self.datadir=pathlib.Path(load_rc().get(CONFIGURATION_KEY_DATADIR,os.path.realpath(os.curdir),),)
[docs]defsample(self,sample:typing.Any)->Sample:"""Load a single volume sample from the disk. Parameters ---------- sample A tuple containing the path suffix, within the database root folder, where to find the volume to be loaded and an integer, representing the sample target. Returns ------- The sample representation. """clamp=tio.Clamp(out_min=-1000,out_max=2000)rescale=tio.RescaleIntensity(percentiles=(0.5,99.5))preprocess=tio.Compose([clamp,rescale])image=tio.ScalarImage(self.datadir/sample[0])image=preprocess(image)image=tv_tensors.Image(image.data)returndict(image=image,target=self.target(sample),name=sample[0])
[docs]deftarget(self,sample:typing.Any)->torch.Tensor:"""Load only sample target from its raw representation. Parameters ---------- sample A tuple containing the path suffix, within the dataset root folder, where to find the image to be loaded, and an integer, representing the sample target. Returns ------- The label corresponding to the specified sample, encapsulated as a 1D torch float tensor. """returntorch.FloatTensor([sample[1]])
[docs]classDataModule(CachingDataModule):"""VISCERAL DataModule for 3D organ binary classification. Parameters ---------- split_path Path or traversable (resource) with the JSON split description to load. """def__init__(self,split_path:pathlib.Path|importlib.resources.abc.Traversable):super().__init__(database_split=JSONDatabaseSplit(split_path),raw_data_loader=RawDataLoader(),database_name=DATABASE_SLUG,split_name=split_path.name.rsplit(".",2)[0],task="classification",)