Skip to content

Commit 41865eb

Browse files
committed
separate caching logic from download
1 parent fc33c46 commit 41865eb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

torchvision/datasets/phototour.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ def __init__(
8282
self.download()
8383

8484
if not self._check_datafile_exists():
85-
raise RuntimeError('Dataset not found.' +
86-
' You can use download=True to download it')
85+
try:
86+
self.cache()
87+
except Exception as error:
88+
raise RuntimeError("Dataset not found. You can use download=True to download it") from error
8789

8890
# load the serialized data
8991
self.data, self.labels, self.matches = torch.load(self.data_file)
@@ -141,6 +143,7 @@ def download(self) -> None:
141143

142144
os.unlink(fpath)
143145

146+
def cache(self) -> None:
144147
# process and save as torch files
145148
print('# Caching data {}'.format(self.data_file))
146149

0 commit comments

Comments
 (0)