Skip to content

Commit

Permalink
Add: Warning when AC is not prepared to specify which file/dir is mis…
Browse files Browse the repository at this point in the history
…sing.
  • Loading branch information
Labbeti committed Jul 17, 2023
1 parent c4f4814 commit 27cb8bb
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/aac_datasets/datasets/audiocaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,24 @@ def _get_audio_subset_dpath(root: str, subset: str, sr: int) -> str:
)


def _is_prepared(root: str, subset: str, sr: int) -> bool:
def _is_prepared(root: str, subset: str, sr: int, verbose: int) -> bool:
links = _AUDIOCAPS_LINKS[subset]
captions_fname = links["captions"]["fname"]
captions_fpath = osp.join(_get_audiocaps_dpath(root, sr), captions_fname)
audio_subset_dpath = _get_audio_subset_dpath(root, subset, sr)
return osp.isdir(audio_subset_dpath) and osp.isfile(captions_fpath)

msgs = []

if not osp.isdir(audio_subset_dpath):
msgs.append(f"Cannot find directory '{audio_subset_dpath}'.")
if not osp.isfile(captions_fpath):
msgs.append(f"Cannot find file '{captions_fpath}'.")

if verbose >= 0:
for msg in msgs:
pylog.warning(msg)

return len(msgs) == 0


def _load_audiocaps_dataset(
Expand All @@ -351,7 +363,7 @@ def _load_audiocaps_dataset(
verbose: int,
audio_format: str = "flac",
) -> Tuple[Dict[str, List[Any]], List[str]]:
if not _is_prepared(root, subset, sr):
if not _is_prepared(root, subset, sr, verbose):
raise RuntimeError(
f"Cannot load data: audiocaps_{subset} is not prepared in data root={root}. Please use download=True in dataset constructor."
)
Expand Down Expand Up @@ -537,7 +549,7 @@ def _prepare_audiocaps_dataset(
pylog.error(f"Cannot use ffmpeg path '{ffmpeg_path}'. ({err})")
raise err

if _is_prepared(root, subset, sr) and not force:
if _is_prepared(root, subset, sr, -1) and not force:
return None

links = _AUDIOCAPS_LINKS[subset]
Expand Down

0 comments on commit 27cb8bb

Please sign in to comment.