目录

torchaudio.datasets

所有数据集都是 torch.utils.data.Dataset 的子类,并实现了 __getitem____len__ 方法。因此,它们都可以传递给 torch.utils.data.DataLoader,该加载器可以使用 torch.multiprocessing 个工作进程并行加载多个样本。例如:

yesno_data = torchaudio.datasets.YESNO('.', download=True)
data_loader = torch.utils.data.DataLoader(yesno_data,
                                          batch_size=1,
                                          shuffle=True,
                                          num_workers=args.nThreads)

以下数据集可用:

所有的数据集都有几乎相似的API。它们都有两个通用参数: transformtarget_transform 分别用于转换输入和目标。

CMUARCTIC

class torchaudio.datasets.CMUARCTIC(root: Union[str, pathlib.Path], url: str = 'aew', folder_in_archive: str = 'ARCTIC', download: bool = False)[source]

为 CMU_ARCTIC 创建数据集。

Parameters
  • root (strPath) – 数据集所在或下载的目录路径。

  • url (str, optional) – 要从中下载数据集的 URL,或要下载的数据集类型。 (默认值:"aew") 允许的类型值为 "aew""ahw""aup""awb""axb""bdl""clb""eey""fem""gka""jmk""ksp""ljm""lnh""rms""rxr""slp""slt"

  • folder_in_archive (str, optional) – 数据集的顶层目录。(默认值:"ARCTIC"

  • download (bool, optional) – 如果在根路径下未找到数据集,是否下载该数据集。(默认值:False)。

__getitem__(n: int) → Tuple[torch.Tensor, int, str, str][source]

从数据集中加载第 n 个样本。

Parameters

n (int) – 要加载的样本的索引

Returns

(waveform, sample_rate, utterance, utterance_id)

Return type

元组

COMMONVOICE

class torchaudio.datasets.COMMONVOICE(root: Union[str, pathlib.Path], tsv: str = 'train.tsv', url: Optional[str] = None, folder_in_archive: Optional[str] = None, version: Optional[str] = None, download: Optional[bool] = None)[source]

为 CommonVoice 创建数据集。

Parameters
  • root (strPath) – 数据集所在目录的路径。 (存在 tsv 文件的位置。)

  • tsv (str, optional) – 用于构建元数据的 tsv 文件名,例如 "train.tsv", "test.tsv", "dev.tsv", "invalidated.tsv", "validated.tsv""other.tsv"。(默认值:"train.tsv"

  • url (str, 可选) – 已废弃,不再使用。

  • folder_in_archive (str, optional) – 已废弃,不再使用。

  • 版本 (str) – 已废弃,不再使用。

  • 下载 (bool, 可选) – 已弃用,未使用。

__getitem__(n: int) → Tuple[torch.Tensor, int, Dict[str, str]][source]

从数据集中加载第 n 个样本。

Parameters

n (int) – 要加载的样本的索引

Returns

(waveform, sample_rate, dictionary),其中字典是从具有以下键的TSV文件构建的:client_idpathsentenceup_votesdown_votesagegenderaccent

Return type

元组

GTZAN

class torchaudio.datasets.GTZAN(root: Union[str, pathlib.Path], url: str = 'http://opihi.cs.uvic.ca/sound/genres.tar.gz', folder_in_archive: str = 'genres', download: bool = False, subset: Optional[str] = None)[source]

为 GTZAN 创建数据集。

注意

如果您计划使用此数据集发布结果,请参阅 http://marsyas.info/downloads/datasets.html

Parameters
  • root (strPath) – 数据集所在或下载的目录路径。

  • url (str, optional) – 下载数据集的 URL。 (默认值: "http://opihi.cs.uvic.ca/sound/genres.tar.gz")

  • folder_in_archive (str, optional) – 数据集的顶层目录。

  • download (bool, optional) – 如果在根路径下未找到数据集,是否下载该数据集。(默认值:False)。

  • 子集 (str, 可选) – 使用数据集的哪个子集。 可以是"training""validation""testing"None。 如果为None,则使用整个数据集。(默认值:None)。

__getitem__(n: int) → Tuple[torch.Tensor, int, str][source]

从数据集中加载第 n 个样本。

Parameters

n (int) – 要加载的样本的索引

Returns

(waveform, sample_rate, label)

Return type

元组

LIBRISPEECH

class torchaudio.datasets.LIBRISPEECH(root: Union[str, pathlib.Path], url: str = 'train-clean-100', folder_in_archive: str = 'LibriSpeech', download: bool = False)[source]

为 LibriSpeech 创建数据集。

Parameters
  • root (strPath) – 数据集所在或下载的目录路径。

  • url (str, optional) – 用于下载数据集的 URL, 或要下载的数据集类型。 允许的类型值为 "dev-clean""dev-other""test-clean""test-other""train-clean-100""train-clean-360""train-other-500"。(默认值:"train-clean-100"

  • folder_in_archive (str, optional) – 数据集的顶层目录。(默认值:"LibriSpeech"

  • download (bool, optional) – 如果在根路径下未找到数据集,是否下载该数据集。(默认值:False)。

__getitem__(n: int) → Tuple[torch.Tensor, int, str, int, int, int][source]

从数据集中加载第 n 个样本。

Parameters

n (int) – 要加载的样本的索引

Returns

(waveform, sample_rate, utterance, speaker_id, chapter_id, utterance_id)

Return type

元组

LIBRITTS

class torchaudio.datasets.LIBRITTS(root: Union[str, pathlib.Path], url: str = 'train-clean-100', folder_in_archive: str = 'LibriTTS', download: bool = False)[source]

为 LibriTTS 创建数据集。

Parameters
  • root (strPath) – 数据集所在或下载的目录路径。

  • url (str, optional) – 用于下载数据集的 URL, 或要下载的数据集类型。 允许的类型值为 "dev-clean""dev-other""test-clean""test-other""train-clean-100""train-clean-360""train-other-500"。(默认值:"train-clean-100"

  • folder_in_archive (str, optional) – 数据集的顶层目录。(默认值:"LibriTTS"

  • download (bool, optional) – 如果在根路径下未找到数据集,是否下载该数据集。(默认值:False)。

__getitem__(n: int) → Tuple[torch.Tensor, int, str, str, int, int, str][source]

从数据集中加载第 n 个样本。

Parameters

n (int) – 要加载的样本的索引

Returns

(waveform, sample_rate, original_text, normalized_text, speaker_id, chapter_id, utterance_id)

Return type

元组

LJSPEECH

class torchaudio.datasets.LJSPEECH(root: Union[str, pathlib.Path], url: str = 'https://data.keithito.com/data/speech/LJSpeech-1.1.tar.bz2', folder_in_archive: str = 'wavs', download: bool = False)[source]

为 LJSpeech-1.1 创建数据集。

Parameters
  • root (strPath) – 数据集所在或下载的目录路径。

  • url (str, optional) – 下载数据集的 URL。 (默认值: "https://data.keithito.com/data/speech/LJSpeech-1.1.tar.bz2")

  • folder_in_archive (str, optional) – 数据集的顶层目录。(默认值:"wavs"

  • download (bool, optional) – 如果在根路径下未找到数据集,是否下载该数据集。(默认值:False)。

__getitem__(n: int) → Tuple[torch.Tensor, int, str, str][source]

从数据集中加载第 n 个样本。

Parameters

n (int) – 要加载的样本的索引

Returns

(waveform, sample_rate, transcript, normalized_transcript)

Return type

元组

SPEECHCOMMANDS

class torchaudio.datasets.SPEECHCOMMANDS(root: Union[str, pathlib.Path], url: str = 'speech_commands_v0.02', folder_in_archive: str = 'SpeechCommands', download: bool = False, subset: Optional[str] = None)[source]

创建语音命令数据集。

Parameters
  • root (strPath) – 数据集所在或下载的目录路径。

  • url (str, optional) – 用于下载数据集的 URL,或要下载的数据集类型。允许的 type 值为 "speech_commands_v0.01""speech_commands_v0.02"(默认值:"speech_commands_v0.02"

  • folder_in_archive (str, optional) – 数据集的顶层目录。(默认值:"SpeechCommands"

  • download (bool, optional) – 如果在根路径下未找到数据集,是否下载该数据集。(默认值:False)。

  • 子集 (可选[str]) – 选择数据集的一个子集 [None, “训练”, “验证”, “测试”]。None 表示整个数据集。“验证”和“测试”分别在“validation_list.txt”和“testing_list.txt”中定义,“训练”则是其余部分。关于文件“validation_list.txt”和“testing_list.txt”的详细说明,请参阅数据集的README以及原始论文第7节及其参考文献12。原始论文可以在这里找到。(默认值:None)

__getitem__(n: int) → Tuple[torch.Tensor, int, str, str, int][source]

从数据集中加载第 n 个样本。

Parameters

n (int) – 要加载的样本的索引

Returns

(waveform, sample_rate, label, speaker_id, utterance_number)

Return type

元组

TEDLIUM

class torchaudio.datasets.TEDLIUM(root: Union[str, pathlib.Path], release: str = 'release1', subset: str = None, download: bool = False, audio_ext='.sph')[source]

为 Tedlium 创建数据集。它支持第 1、2 和 3 版发布。

Parameters
  • root (strPath) – 数据集所在或下载的目录路径。

  • release (str, optional) – 发布版本。 允许的值是 "release1""release2""release3"。 (默认值:"release1")。

  • subset (str, optional) – 要使用的数据集子集。有效选项为 "train""dev""test"(适用于版本 1 和 2),以及 None(适用于版本 3)。默认为 "train"None

  • download (bool, optional) – 如果在根路径下未找到数据集,是否下载该数据集。(默认值:False)。

__getitem__(n: int) → Tuple[torch.Tensor, int, str, int, int, int][source]

从数据集中加载第 n 个样本。

Parameters

n (int) – 要加载的样本的索引

Returns

(waveform, sample_rate, transcript, talk_id, speaker_id, identifier)

Return type

元组

property phoneme_dict

音素。从单词到音素元组的映射。 请注意,某些单词的音素为空。

Type

字典[字符串, 元组[字符串]]

VCTK

class torchaudio.datasets.VCTK(root: Union[str, pathlib.Path], url: str = 'https://datashare.is.ed.ac.uk/bitstream/handle/10283/3443/VCTK-Corpus-0.92.zip', folder_in_archive: str = 'VCTK-Corpus', download: bool = False, downsample: bool = False)[source]

为 VCTK 创建数据集。

注意

Parameters
  • root (strPath) – 数据集所在或下载的目录路径。

  • url (str, optional) – 未使用,因为该数据集已不再公开提供。

  • folder_in_archive (str, optional) – 数据集的顶层目录。(默认值:"VCTK-Corpus"

  • download (bool, optional) – 如果未在根路径找到数据集,是否下载该数据集。(默认值:False)。 传入 download=True 将导致错误,因为该数据集已不再公开提供。

  • downsample (bool, optional) – 未使用。

__getitem__(n: int) → Tuple[torch.Tensor, int, str, str, str][source]

从数据集中加载第 n 个样本。

Parameters

n (int) – 要加载的样本的索引

Returns

(waveform, sample_rate, utterance, speaker_id, utterance_id)

Return type

元组

VCTK_092

class torchaudio.datasets.VCTK_092(root: str, mic_id: str = 'mic2', download: bool = False, url: str = 'https://datashare.is.ed.ac.uk/bitstream/handle/10283/3443/VCTK-Corpus-0.92.zip', audio_ext='.flac')[source]

创建 VCTK 0.92 数据集

Parameters
  • root (str) – 找到数据集顶级目录的根目录。

  • mic_id (str) – 麦克风ID。可以是 "mic1""mic2"。(默认: "mic2")

  • download (bool, optional) – 如果在根路径下未找到数据集,是否下载该数据集。(默认值:False)。

  • url (str, optional) – 下载数据集的 URL。 (默认值: "https://datashare.is.ed.ac.uk/bitstream/handle/10283/3443/VCTK-Corpus-0.92.zip")

  • audio_ext (str, optional) – 如果数据集转换为非默认音频格式,则使用自定义音频扩展。

注意

  • 由于缺少相应的文本文件,将跳过演讲者 p315 的所有演讲。

  • 由于缺少音频文件,p280的所有演讲将被跳过 mic_id="mic2"

  • 由于缺少音频文件,说话人 p362 的部分演讲将被跳过。

  • 另请参阅:https://datashare.is.ed.ac.uk/handle/10283/3443

__getitem__(n: int) → Tuple[torch.Tensor, int, str, str, str][source]

从数据集中加载第 n 个样本。

Parameters

n (int) – 要加载的样本的索引

Returns

(waveform, sample_rate, utterance, speaker_id, utterance_id)

Return type

元组

YESNO

class torchaudio.datasets.YESNO(root: Union[str, pathlib.Path], url: str = 'http://www.openslr.org/resources/1/waves_yesno.tar.gz', folder_in_archive: str = 'waves_yesno', download: bool = False)[source]

为 YesNo 创建数据集。

Parameters
  • root (strPath) – 数据集所在或下载的目录路径。

  • url (str, optional) – 下载数据集的 URL。 (默认值: "http://www.openslr.org/resources/1/waves_yesno.tar.gz")

  • folder_in_archive (str, optional) – 数据集的顶层目录。(默认值:"waves_yesno"

  • download (bool, optional) – 如果在根路径下未找到数据集,是否下载该数据集。(默认值:False)。

__getitem__(n: int) → Tuple[torch.Tensor, int, List[int]][source]

从数据集中加载第 n 个样本。

Parameters

n (int) – 要加载的样本的索引

Returns

(waveform, sample_rate, labels)

Return type

元组

文档

访问 PyTorch 的全面开发人员文档

查看文档

教程

获取面向初学者和高级开发人员的深入教程

查看教程

资源

查找开发资源并解答您的问题

查看资源