Skip to content

Commit

Permalink
Raising RuntimeErrors when datasets missing (#2430)
Browse files Browse the repository at this point in the history
Summary:
Checks download flag and raises error when dataset is missing given download flag exists. Unit tested manually.

edit: Changed path to check as well as comment that is returned.

Pull Request resolved: #2430

Reviewed By: carolineechen

Differential Revision: D36815729

Pulled By: skim0514

fbshipit-source-id: f062db7919271665b88ec9754d85cfa83b4f6fa3
  • Loading branch information
Sean Kim authored and facebook-github-bot committed Jun 1, 2022
1 parent 6e56383 commit a61b90c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
7 changes: 6 additions & 1 deletion torchaudio/datasets/cmuarctic.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ def __init__(
checksum = _CHECKSUMS.get(url, None)
download_url_to_file(url, archive, hash_prefix=checksum)
extract_archive(archive)

else:
if not os.path.exists(self._path):
raise RuntimeError(
f"The path {self._path} doesn't exist. "
"Please check the ``root`` path or set `download=True` to download it"
)
self._text = os.path.join(self._path, self._folder_text, self._file_text)

with open(self._text, "r") as text:
Expand Down
6 changes: 6 additions & 0 deletions torchaudio/datasets/libritts.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ def __init__(
checksum = _CHECKSUMS.get(url, None)
download_url_to_file(url, archive, hash_prefix=checksum)
extract_archive(archive)
else:
if not os.path.exists(self._path):
raise RuntimeError(
f"The path {self._path} doesn't exist. "
"Please check the ``root`` path or set `download=True` to download it"
)

self._walker = sorted(str(p.stem) for p in Path(self._path).glob("*/*/*" + self._ext_audio))

Expand Down
6 changes: 6 additions & 0 deletions torchaudio/datasets/ljspeech.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ def _parse_filesystem(self, root: str, url: str, folder_in_archive: str, downloa
checksum = _RELEASE_CONFIGS["release1"]["checksum"]
download_url_to_file(url, archive, hash_prefix=checksum)
extract_archive(archive)
else:
if not os.path.exists(self._path):
raise RuntimeError(
f"The path {self._path} doesn't exist. "
"Please check the ``root`` path or set `download=True` to download it"
)

with open(self._metadata_path, "r", newline="") as metadata:
flist = csv.reader(metadata, delimiter="|", quoting=csv.QUOTE_NONE)
Expand Down
6 changes: 6 additions & 0 deletions torchaudio/datasets/speechcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ def __init__(
checksum = _CHECKSUMS.get(url, None)
download_url_to_file(url, archive, hash_prefix=checksum)
extract_archive(archive, self._path)
else:
if not os.path.exists(self._path):
raise RuntimeError(
f"The path {self._path} doesn't exist. "
"Please check the ``root`` path or set `download=True` to download it"
)

if subset == "validation":
self._walker = _load_list(self._path, "validation_list.txt")
Expand Down
6 changes: 6 additions & 0 deletions torchaudio/datasets/tedlium.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ def __init__(
checksum = _RELEASE_CONFIGS[release]["checksum"]
download_url_to_file(url, archive, hash_prefix=checksum)
extract_archive(archive)
else:
if not os.path.exists(self._path):
raise RuntimeError(
f"The path {self._path} doesn't exist. "
"Please check the ``root`` path or set `download=True` to download it"
)

# Create list for all samples
self._filelist = []
Expand Down

0 comments on commit a61b90c

Please sign in to comment.