Skip to content

Commit 0cc64ae

Browse files
committed
Dont error when dataset is already downloaded
1 parent 945bdad commit 0cc64ae

File tree

3 files changed

+6
-15
lines changed

3 files changed

+6
-15
lines changed

torchvision/datasets/inaturalist.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init__(
8181
if download:
8282
self.download()
8383

84-
if not self._check_integrity():
84+
if not self._check_exists():
8585
raise RuntimeError("Dataset not found or corrupted. You can use download=True to download it")
8686

8787
self.all_categories: List[str] = []
@@ -219,15 +219,12 @@ def category_name(self, category_type: str, category_id: int) -> str:
219219
return name
220220
raise ValueError(f"Invalid category id {category_id} for {category_type}")
221221

222-
def _check_integrity(self) -> bool:
222+
def _check_exists(self) -> bool:
223223
return os.path.exists(self.root) and len(os.listdir(self.root)) > 0
224224

225225
def download(self) -> None:
226-
if self._check_integrity():
227-
raise RuntimeError(
228-
f"The directory {self.root} already exists. "
229-
f"If you want to re-download or re-extract the images, delete the directory."
230-
)
226+
if self._check_exists():
227+
return
231228

232229
base_root = os.path.dirname(self.root)
233230

torchvision/datasets/kinetics.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,7 @@ def _download_videos(self) -> None:
166166
RuntimeError: if download folder exists, break to prevent downloading entire dataset again.
167167
"""
168168
if path.exists(self.split_folder):
169-
raise RuntimeError(
170-
f"The directory {self.split_folder} already exists. "
171-
f"If you want to re-download or re-extract the images, delete the directory."
172-
)
169+
return
173170
tar_path = path.join(self.root, "tars")
174171
file_list_path = path.join(self.root, "files")
175172

torchvision/datasets/places365.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,7 @@ def download_devkit(self) -> None:
145145

146146
def download_images(self) -> None:
147147
if path.exists(self.images_dir):
148-
raise RuntimeError(
149-
f"The directory {self.images_dir} already exists. If you want to re-download or re-extract the images, "
150-
f"delete the directory."
151-
)
148+
return
152149

153150
file, md5 = self._IMAGES_META[(self.split, self.small)]
154151
download_and_extract_archive(urljoin(self._BASE_URL, file), self.root, md5=md5)

0 commit comments

Comments
 (0)