Args: data: input data file paths to load and transform to generate dataset for model. `PersistentDataset` expects input data to be a list of serializable and hashes them as cache keys using `hash_func`. transform: transforms to execut
(
self,
data: Sequence,
transform: Sequence[Callable] | Callable,
cache_dir: Path | str | None,
hash_func: Callable[..., bytes] = pickle_hashing,
pickle_module: str = "pickle",
pickle_protocol: int = DEFAULT_PROTOCOL,
hash_transform: Callable[..., bytes] | None = None,
reset_ops_id: bool = True,
track_meta: bool = False,
weights_only: bool = True,
)
| 221 | """ |
| 222 | |
| 223 | def __init__( |
| 224 | self, |
| 225 | data: Sequence, |
| 226 | transform: Sequence[Callable] | Callable, |
| 227 | cache_dir: Path | str | None, |
| 228 | hash_func: Callable[..., bytes] = pickle_hashing, |
| 229 | pickle_module: str = "pickle", |
| 230 | pickle_protocol: int = DEFAULT_PROTOCOL, |
| 231 | hash_transform: Callable[..., bytes] | None = None, |
| 232 | reset_ops_id: bool = True, |
| 233 | track_meta: bool = False, |
| 234 | weights_only: bool = True, |
| 235 | ) -> None: |
| 236 | """ |
| 237 | Args: |
| 238 | data: input data file paths to load and transform to generate dataset for model. |
| 239 | `PersistentDataset` expects input data to be a list of serializable |
| 240 | and hashes them as cache keys using `hash_func`. |
| 241 | transform: transforms to execute operations on input data. |
| 242 | cache_dir: If specified, this is the location for persistent storage |
| 243 | of pre-computed transformed data tensors. The cache_dir is computed once, and |
| 244 | persists on disk until explicitly removed. Different runs, programs, experiments |
| 245 | may share a common cache dir provided that the transforms pre-processing is consistent. |
| 246 | If `cache_dir` doesn't exist, will automatically create it. |
| 247 | If `cache_dir` is `None`, there is effectively no caching. |
| 248 | hash_func: a callable to compute hash from data items to be cached. |
| 249 | defaults to `monai.data.utils.pickle_hashing`. |
| 250 | pickle_module: string representing the module used for pickling metadata and objects, |
| 251 | default to `"pickle"`. due to the pickle limitation in multi-processing of Dataloader, |
| 252 | we can't use `pickle` as arg directly, so here we use a string name instead. |
| 253 | if want to use other pickle module at runtime, just register like: |
| 254 | >>> from monai.data import utils |
| 255 | >>> utils.SUPPORTED_PICKLE_MOD["test"] = other_pickle |
| 256 | this arg is used by `torch.save`, for more details, please check: |
| 257 | https://pytorch.org/docs/stable/generated/torch.save.html#torch.save, |
| 258 | and ``monai.data.utils.SUPPORTED_PICKLE_MOD``. |
| 259 | pickle_protocol: specifies pickle protocol when saving, with `torch.save`. |
| 260 | Defaults to torch.serialization.DEFAULT_PROTOCOL. For more details, please check: |
| 261 | https://pytorch.org/docs/stable/generated/torch.save.html#torch.save. |
| 262 | hash_transform: a callable to compute hash from the transform information when caching. |
| 263 | This may reduce errors due to transforms changing during experiments. Default to None (no hash). |
| 264 | Other options are `pickle_hashing` and `json_hashing` functions from `monai.data.utils`. |
| 265 | reset_ops_id: whether to set `TraceKeys.ID` to ``Tracekys.NONE``, defaults to ``True``. |
| 266 | When this is enabled, the traced transform instance IDs will be removed from the cached MetaTensors. |
| 267 | This is useful for skipping the transform instance checks when inverting applied operations |
| 268 | using the cached content and with re-created transform instances. |
| 269 | track_meta: whether to track the meta information, if `True`, will convert to `MetaTensor`. |
| 270 | default to `False`. Cannot be used with `weights_only=True`. |
| 271 | weights_only: keyword argument passed to `torch.load` when reading cached files. |
| 272 | default to `True`. When set to `True`, `torch.load` restricts loading to tensors and |
| 273 | other safe objects. Setting this to `False` is required for loading `MetaTensor` |
| 274 | objects saved with `track_meta=True`, however this creates the possibility of remote |
| 275 | code execution through `torch.load` so be aware of the security implications of doing so. |
| 276 | |
| 277 | Raises: |
| 278 | ValueError: When both `track_meta=True` and `weights_only=True`, since this combination |
| 279 | prevents cached MetaTensors from being reloaded and causes perpetual cache regeneration. |
| 280 | """ |
nothing calls this directly
no test coverage detected