-
Notifications
You must be signed in to change notification settings - Fork 739
Data points remain tuples #330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,7 @@ | ||
| import os | ||
|
|
||
| from torch.utils.data import Dataset | ||
|
|
||
| import torchaudio | ||
| from torch.utils.data import Dataset | ||
| from torchaudio.datasets.utils import ( | ||
| download_url, | ||
| extract_archive, | ||
|
|
@@ -16,38 +15,43 @@ | |
|
|
||
| def load_librispeech_item(fileid, path, ext_audio, ext_txt): | ||
|
|
||
| speaker, chapter, utterance = fileid.split("-") | ||
| speaker_id, chapter_id, utterance_id = fileid.split("-") | ||
|
|
||
| file_text = speaker + "-" + chapter + ext_txt | ||
| file_text = os.path.join(path, speaker, chapter, file_text) | ||
| file_text = speaker_id + "-" + chapter_id + ext_txt | ||
| file_text = os.path.join(path, speaker_id, chapter_id, file_text) | ||
|
|
||
| fileid_audio = speaker + "-" + chapter + "-" + utterance | ||
| fileid_audio = speaker_id + "-" + chapter_id + "-" + utterance_id | ||
| file_audio = fileid_audio + ext_audio | ||
| file_audio = os.path.join(path, speaker, chapter, file_audio) | ||
| file_audio = os.path.join(path, speaker_id, chapter_id, file_audio) | ||
|
|
||
| # Load audio | ||
| waveform, sample_rate = torchaudio.load(file_audio) | ||
|
|
||
| # Load text | ||
| for line in open(file_text): | ||
| fileid_text, content = line.strip().split(" ", 1) | ||
| if fileid_audio == fileid_text: | ||
| break | ||
| else: | ||
| # Translation not found | ||
| raise FileNotFoundError("Translation not found for " + fileid_audio) | ||
|
|
||
| return { | ||
| "speaker_id": speaker, | ||
| "chapter_id": chapter, | ||
| "utterance_id": utterance, | ||
| "utterance": content, | ||
| "waveform": waveform, | ||
| "sample_rate": sample_rate, | ||
| } | ||
| with open(file_text) as ft: | ||
| for line in ft: | ||
| fileid_text, utterance = line.strip().split(" ", 1) | ||
| if fileid_audio == fileid_text: | ||
| break | ||
| else: | ||
| # Translation not found | ||
| raise FileNotFoundError("Translation not found for " + fileid_audio) | ||
|
|
||
| return ( | ||
| waveform, | ||
| sample_rate, | ||
| utterance, | ||
| int(speaker_id), | ||
| int(chapter_id), | ||
| int(utterance_id), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also converting to int though they come from file names. |
||
| ) | ||
|
|
||
|
|
||
| class LIBRISPEECH(Dataset): | ||
| """ | ||
| Create a Dataset for LibriSpeech. Each item is a tuple of the form: | ||
| waveform, sample_rate, utterance, speaker_id, chapter_id, utterance_id | ||
| """ | ||
|
|
||
| _ext_txt = ".trans.txt" | ||
| _ext_audio = ".flac" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,16 +11,20 @@ | |
|
|
||
| def load_yesno_item(fileid, path, ext_audio): | ||
| # Read label | ||
| label = fileid.split("_") | ||
| labels = [int(c) for c in fileid.split("_")] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also converting to int though they come from file names. |
||
|
|
||
| # Read wav | ||
| file_audio = os.path.join(path, fileid + ext_audio) | ||
| waveform, sample_rate = torchaudio.load(file_audio) | ||
|
|
||
| return {"label": label, "waveform": waveform, "sample_rate": sample_rate} | ||
| return waveform, sample_rate, labels | ||
|
|
||
|
|
||
| class YESNO(Dataset): | ||
| """ | ||
| Create a Dataset for YesNo. Each item is a tuple of the form: | ||
| (waveform, sample_rate, labels) | ||
| """ | ||
|
|
||
| _ext_audio = ".wav" | ||
|
|
||
|
|
@@ -32,17 +36,8 @@ def __init__( | |
| download=False, | ||
| transform=None, | ||
| target_transform=None, | ||
| return_dict=False, | ||
| ): | ||
|
|
||
| if not return_dict: | ||
| warnings.warn( | ||
| "In the next version, the item returned will be a dictionary. " | ||
| "Please use `return_dict=True` to enable this behavior now, " | ||
| "and suppress this warning.", | ||
| DeprecationWarning, | ||
| ) | ||
|
|
||
| if transform is not None or target_transform is not None: | ||
| warnings.warn( | ||
| "In the next version, transforms will not be part of the dataset. " | ||
|
|
@@ -53,7 +48,6 @@ def __init__( | |
|
|
||
| self.transform = transform | ||
| self.target_transform = target_transform | ||
| self.return_dict = return_dict | ||
|
|
||
| archive = os.path.basename(url) | ||
| archive = os.path.join(root, archive) | ||
|
|
@@ -79,20 +73,15 @@ def __getitem__(self, n): | |
| fileid = self._walker[n] | ||
| item = load_yesno_item(fileid, self._path, self._ext_audio) | ||
|
|
||
| waveform = item["waveform"] | ||
| # TODO Upon deprecation, uncomment line below and remove following code | ||
| # return item | ||
|
|
||
| waveform, sample_rate, labels = item | ||
| if self.transform is not None: | ||
| waveform = self.transform(waveform) | ||
| item["waveform"] = waveform | ||
|
|
||
| label = item["label"] | ||
| if self.target_transform is not None: | ||
| label = self.target_transform(label) | ||
| item["label"] = label | ||
|
|
||
| if self.return_dict: | ||
| return item | ||
|
|
||
| return item["waveform"], item["label"] | ||
| labels = self.target_transform(labels) | ||
| return waveform, sample_rate, labels | ||
|
|
||
| def __len__(self): | ||
| return len(self._walker) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this as part of this PR to make sure that the file is closed.