From 0cc64ae0c1f17f3683ea00dea9580d2675f76bb3 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Fri, 18 Oct 2024 13:18:44 +0100 Subject: [PATCH] Dont error when dataset is already downloaded --- torchvision/datasets/inaturalist.py | 11 ++++------- torchvision/datasets/kinetics.py | 5 +---- torchvision/datasets/places365.py | 5 +---- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/torchvision/datasets/inaturalist.py b/torchvision/datasets/inaturalist.py index 0379f3509c9..e041d41f4a2 100644 --- a/torchvision/datasets/inaturalist.py +++ b/torchvision/datasets/inaturalist.py @@ -81,7 +81,7 @@ def __init__( if download: self.download() - if not self._check_integrity(): + if not self._check_exists(): raise RuntimeError("Dataset not found or corrupted. You can use download=True to download it") self.all_categories: List[str] = [] @@ -219,15 +219,12 @@ def category_name(self, category_type: str, category_id: int) -> str: return name raise ValueError(f"Invalid category id {category_id} for {category_type}") - def _check_integrity(self) -> bool: + def _check_exists(self) -> bool: return os.path.exists(self.root) and len(os.listdir(self.root)) > 0 def download(self) -> None: - if self._check_integrity(): - raise RuntimeError( - f"The directory {self.root} already exists. " - f"If you want to re-download or re-extract the images, delete the directory." - ) + if self._check_exists(): + return base_root = os.path.dirname(self.root) diff --git a/torchvision/datasets/kinetics.py b/torchvision/datasets/kinetics.py index 7845e91b5b2..773d9f68ca9 100644 --- a/torchvision/datasets/kinetics.py +++ b/torchvision/datasets/kinetics.py @@ -166,10 +166,7 @@ def _download_videos(self) -> None: RuntimeError: if download folder exists, break to prevent downloading entire dataset again. """ if path.exists(self.split_folder): - raise RuntimeError( - f"The directory {self.split_folder} already exists. " - f"If you want to re-download or re-extract the images, delete the directory." - ) + return tar_path = path.join(self.root, "tars") file_list_path = path.join(self.root, "files") diff --git a/torchvision/datasets/places365.py b/torchvision/datasets/places365.py index 98966e1dc2f..a120e0e217a 100644 --- a/torchvision/datasets/places365.py +++ b/torchvision/datasets/places365.py @@ -145,10 +145,7 @@ def download_devkit(self) -> None: def download_images(self) -> None: if path.exists(self.images_dir): - raise RuntimeError( - f"The directory {self.images_dir} already exists. If you want to re-download or re-extract the images, " - f"delete the directory." - ) + return file, md5 = self._IMAGES_META[(self.split, self.small)] download_and_extract_archive(urljoin(self._BASE_URL, file), self.root, md5=md5)