(
self,
root_dir: PathLike,
section: str,
transform: Sequence[Callable] | Callable = (),
download: bool = False,
seed: int = 0,
val_frac: float = 0.1,
test_frac: float = 0.1,
cache_num: int = sys.maxsize,
cache_rate: float = 1.0,
num_workers: int | None = 1,
progress: bool = True,
copy_cache: bool = True,
as_contiguous: bool = True,
runtime_cache: bool = False,
)
| 89 | dataset_folder_name = "MedNIST" |
| 90 | |
| 91 | def __init__( |
| 92 | self, |
| 93 | root_dir: PathLike, |
| 94 | section: str, |
| 95 | transform: Sequence[Callable] | Callable = (), |
| 96 | download: bool = False, |
| 97 | seed: int = 0, |
| 98 | val_frac: float = 0.1, |
| 99 | test_frac: float = 0.1, |
| 100 | cache_num: int = sys.maxsize, |
| 101 | cache_rate: float = 1.0, |
| 102 | num_workers: int | None = 1, |
| 103 | progress: bool = True, |
| 104 | copy_cache: bool = True, |
| 105 | as_contiguous: bool = True, |
| 106 | runtime_cache: bool = False, |
| 107 | ) -> None: |
| 108 | root_dir = Path(root_dir) |
| 109 | if not root_dir.is_dir(): |
| 110 | raise ValueError("Root directory root_dir must be a directory.") |
| 111 | self.section = section |
| 112 | self.val_frac = val_frac |
| 113 | self.test_frac = test_frac |
| 114 | self.set_random_state(seed=seed) |
| 115 | tarfile_name = root_dir / self.compressed_file_name |
| 116 | dataset_dir = root_dir / self.dataset_folder_name |
| 117 | self.num_class = 0 |
| 118 | if download: |
| 119 | download_and_extract( |
| 120 | url=self.resource, |
| 121 | filepath=tarfile_name, |
| 122 | output_dir=root_dir, |
| 123 | hash_val=self.md5, |
| 124 | hash_type="md5", |
| 125 | progress=progress, |
| 126 | ) |
| 127 | |
| 128 | if not dataset_dir.is_dir(): |
| 129 | raise RuntimeError( |
| 130 | f"Cannot find dataset directory: {dataset_dir}, please use download=True to download it." |
| 131 | ) |
| 132 | data = self._generate_data_list(dataset_dir) |
| 133 | if transform == (): |
| 134 | transform = LoadImaged("image") |
| 135 | CacheDataset.__init__( |
| 136 | self, |
| 137 | data=data, |
| 138 | transform=transform, |
| 139 | cache_num=cache_num, |
| 140 | cache_rate=cache_rate, |
| 141 | num_workers=num_workers, |
| 142 | progress=progress, |
| 143 | copy_cache=copy_cache, |
| 144 | as_contiguous=as_contiguous, |
| 145 | runtime_cache=runtime_cache, |
| 146 | ) |
| 147 | |
| 148 | def randomize(self, data: np.ndarray) -> None: |
nothing calls this directly
no test coverage detected