From 601230d6b0ed554f7fff91e14306e8ed4bcd9652 Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Wed, 3 Feb 2021 17:48:49 +0800 Subject: [PATCH 1/2] [DLMED] update SmartCacheDataset docs and warning Signed-off-by: Nic Ma --- monai/data/dataset.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/monai/data/dataset.py b/monai/data/dataset.py index e67c7a2954..bc732af61c 100644 --- a/monai/data/dataset.py +++ b/monai/data/dataset.py @@ -571,6 +571,10 @@ class SmartCacheDataset(CacheDataset): 3. Call `update_cache()` before every epoch to replace training items. 4. Call `shutdown()` when training ends. + Note: + This replacement will not work if set the `multiprocessing_context` of DataLoader to `spawn` + or on windows(the default multiprocessing method is `spawn`) and set `num_workers` greater than 0 . + """ def __init__( @@ -601,7 +605,7 @@ def __init__( if self._cache is None: self._cache = self._fill_cache() if self.cache_num >= len(data): - raise ValueError("cache_num must be smaller than dataset length to support replacement.") + warnings.warn("cache_num is greater or equal than dataset length, fall back to regular CacheDataset.") if replace_rate <= 0: raise ValueError("replace_rate must be greater than 0, otherwise, please use CacheDataset.") self.num_replace_workers: int = num_replace_workers From cdb67d668681313ec64da83c5752e48b5093d200 Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Wed, 3 Feb 2021 12:38:46 +0000 Subject: [PATCH 2/2] isAlive => is_alive Signed-off-by: Wenqi Li --- monai/data/dataset.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monai/data/dataset.py b/monai/data/dataset.py index bc732af61c..11a5682de6 100644 --- a/monai/data/dataset.py +++ b/monai/data/dataset.py @@ -641,7 +641,7 @@ def is_started(self): """ if self._replace_mgr is None: return False - return self._replace_mgr.isAlive() + return self._replace_mgr.is_alive() def start(self): """ @@ -692,7 +692,7 @@ def update_cache(self): If the cache has been shutdown before, need to restart the `_replace_mgr` thread. """ - if not self._replace_mgr.isAlive(): + if not self._replace_mgr.is_alive(): self._restart() # make sure update is done