diff --git a/monai/data/dataset.py b/monai/data/dataset.py index 871b523289..8c53338d66 100644 --- a/monai/data/dataset.py +++ b/monai/data/dataset.py @@ -22,6 +22,7 @@ import warnings from collections.abc import Callable, Sequence from copy import copy, deepcopy +from inspect import signature from multiprocessing.managers import ListProxy from multiprocessing.pool import ThreadPool from pathlib import Path @@ -371,7 +372,10 @@ def _cachecheck(self, item_transformed): if hashfile is not None and hashfile.is_file(): # cache hit try: - return torch.load(hashfile) + if "weights_only" in signature(torch.load).parameters: + return torch.load(hashfile, weights_only=False) + else: + return torch.load(hashfile) except PermissionError as e: if sys.platform != "win32": raise e @@ -1670,4 +1674,7 @@ def _load_meta_cache(self, meta_hash_file_name): if meta_hash_file_name in self._meta_cache: return self._meta_cache[meta_hash_file_name] else: - return torch.load(self.cache_dir / meta_hash_file_name) + if "weights_only" in signature(torch.load).parameters: + return torch.load(self.cache_dir / meta_hash_file_name, weights_only=False) + else: + return torch.load(self.cache_dir / meta_hash_file_name)