[docs]classRawDataLoader(ClassificationRawDataLoader):"""A specialized raw-data-loader for the Shenzhen dataset. Parameters ---------- config_variable Key to search for in the configuration file for the root directory of this database. """datadir:pathlib.Path"""This variable contains the base directory where the database raw data is stored."""# config_variable: required so this loader can be used for the Indian# database as well.def__init__(self,config_variable:str=CONFIGURATION_KEY_DATADIR):self.datadir=pathlib.Path(load_rc().get(config_variable,os.path.realpath(os.curdir)),)
[docs]defsample(self,sample:tuple[str,int,typing.Any|None])->Sample:"""Load a single image sample from the disk. 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 sample representation. """# N.B.: Image.convert("L") is required to normalize grayscale back to# normal (instead of inverted).image=PIL.Image.open(self.datadir/sample[0]).convert("L")image,_=remove_black_borders(image)image=tv_tensors.Image(to_tensor(image))# use the code below to view generated images# from torchvision.transforms.functional import to_pil_image# to_pil_image(tensor).show()# __import__("pdb").set_trace()returndict(image=image),dict(target=sample[1],name=sample[0])# type: ignore[arg-type]
[docs]deftarget(self,k:typing.Any)->int|list[int]:"""Load a single image sample target from the disk. Parameters ---------- k 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 ------- int The integer target associated with the sample. """returnk[1]
[docs]classDataModule(CachingDataModule):"""Shenzhen DataModule for computer-aided diagnosis. 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",)