Args: data: input data file paths to load and transform to generate dataset for model. `LMDBDataset` expects input data to be a list of serializable and hashes them as cache keys using `hash_func`. transform: transforms to execute oper
(
self,
data: Sequence,
transform: Sequence[Callable] | Callable,
cache_dir: Path | str = "cache",
hash_func: Callable[..., bytes] = pickle_hashing,
db_name: str = "monai_cache",
progress: bool = True,
pickle_protocol=DEFAULT_PROTOCOL,
hash_transform: Callable[..., bytes] | None = None,
reset_ops_id: bool = True,
lmdb_kwargs: dict | None = None,
)
| 549 | """ |
| 550 | |
| 551 | def __init__( |
| 552 | self, |
| 553 | data: Sequence, |
| 554 | transform: Sequence[Callable] | Callable, |
| 555 | cache_dir: Path | str = "cache", |
| 556 | hash_func: Callable[..., bytes] = pickle_hashing, |
| 557 | db_name: str = "monai_cache", |
| 558 | progress: bool = True, |
| 559 | pickle_protocol=DEFAULT_PROTOCOL, |
| 560 | hash_transform: Callable[..., bytes] | None = None, |
| 561 | reset_ops_id: bool = True, |
| 562 | lmdb_kwargs: dict | None = None, |
| 563 | ) -> None: |
| 564 | """ |
| 565 | Args: |
| 566 | data: input data file paths to load and transform to generate dataset for model. |
| 567 | `LMDBDataset` expects input data to be a list of serializable |
| 568 | and hashes them as cache keys using `hash_func`. |
| 569 | transform: transforms to execute operations on input data. |
| 570 | cache_dir: if specified, this is the location for persistent storage |
| 571 | of pre-computed transformed data tensors. The cache_dir is computed once, and |
| 572 | persists on disk until explicitly removed. Different runs, programs, experiments |
| 573 | may share a common cache dir provided that the transforms pre-processing is consistent. |
| 574 | If the cache_dir doesn't exist, will automatically create it. Defaults to "./cache". |
| 575 | hash_func: a callable to compute hash from data items to be cached. |
| 576 | defaults to `monai.data.utils.pickle_hashing`. |
| 577 | db_name: lmdb database file name. Defaults to "monai_cache". |
| 578 | progress: whether to display a progress bar. |
| 579 | pickle_protocol: specifies pickle protocol when saving, with `torch.save`. |
| 580 | Defaults to torch.serialization.DEFAULT_PROTOCOL. For more details, please check: |
| 581 | https://pytorch.org/docs/stable/generated/torch.save.html#torch.save. |
| 582 | hash_transform: a callable to compute hash from the transform information when caching. |
| 583 | This may reduce errors due to transforms changing during experiments. Default to None (no hash). |
| 584 | Other options are `pickle_hashing` and `json_hashing` functions from `monai.data.utils`. |
| 585 | reset_ops_id: whether to set `TraceKeys.ID` to ``Tracekeys.NONE``, defaults to ``True``. |
| 586 | When this is enabled, the traced transform instance IDs will be removed from the cached MetaTensors. |
| 587 | This is useful for skipping the transform instance checks when inverting applied operations |
| 588 | using the cached content and with re-created transform instances. |
| 589 | lmdb_kwargs: additional keyword arguments to the lmdb environment. |
| 590 | for more details please visit: https://lmdb.readthedocs.io/en/release/#environment-class |
| 591 | """ |
| 592 | super().__init__( |
| 593 | data=data, |
| 594 | transform=transform, |
| 595 | cache_dir=cache_dir, |
| 596 | hash_func=hash_func, |
| 597 | pickle_protocol=pickle_protocol, |
| 598 | hash_transform=hash_transform, |
| 599 | reset_ops_id=reset_ops_id, |
| 600 | ) |
| 601 | self.progress = progress |
| 602 | if not self.cache_dir: |
| 603 | raise ValueError("cache_dir must be specified.") |
| 604 | self.db_file = self.cache_dir / f"{db_name}.lmdb" |
| 605 | self.lmdb_kwargs = lmdb_kwargs or {} |
| 606 | if not self.lmdb_kwargs.get("map_size", 0): |
| 607 | self.lmdb_kwargs["map_size"] = 1024**4 # default map_size |
| 608 | # lmdb is single-writer multi-reader by default |
nothing calls this directly
no test coverage detected