From 4105e65511eddacce4a07edf7ad1f07bc4c549f3 Mon Sep 17 00:00:00 2001 From: Ishan Dutta Date: Fri, 17 Nov 2023 18:49:28 +0530 Subject: [PATCH 1/2] :hammer: [dataset] Handle corrupted cached file in PersistentDataset Signed-off-by: Ishan Dutta --- monai/data/dataset.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/monai/data/dataset.py b/monai/data/dataset.py index 5e403d6fdb..2c82bc27b3 100644 --- a/monai/data/dataset.py +++ b/monai/data/dataset.py @@ -387,6 +387,12 @@ def _cachecheck(self, item_transformed): except PermissionError as e: if sys.platform != "win32": raise e + except RuntimeError as e: + if "Invalid magic number; corrupt file" in str(e): + print(f"Corrupt cache file detected: {hashfile}. Deleting and recomputing.") + hashfile.unlink() + else: + raise e _item_transformed = self._pre_transform(deepcopy(item_transformed)) # keep the original hashed if hashfile is None: From 970fc2bad86c90bfc629e5689396b9a861e26b95 Mon Sep 17 00:00:00 2001 From: Ishan Dutta Date: Fri, 17 Nov 2023 19:24:02 +0530 Subject: [PATCH 2/2] Update monai/data/dataset.py Co-authored-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> Signed-off-by: Ishan Dutta --- monai/data/dataset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/data/dataset.py b/monai/data/dataset.py index 2c82bc27b3..eba850225d 100644 --- a/monai/data/dataset.py +++ b/monai/data/dataset.py @@ -389,7 +389,7 @@ def _cachecheck(self, item_transformed): raise e except RuntimeError as e: if "Invalid magic number; corrupt file" in str(e): - print(f"Corrupt cache file detected: {hashfile}. Deleting and recomputing.") + warnings.warn(f"Corrupt cache file detected: {hashfile}. Deleting and recomputing.") hashfile.unlink() else: raise e