in datasets.py [0:0]
def raw_iter(self) -> Iterator[Tuple[torch.Tensor, torch.Tensor]]:
"""
Iterate over the dataset without extracting clips or batching.
Yields:
Samples from the dataset. The first element is the spectrograms and
the second is the waveforms.
Spectrogram shape: [num_bands, num_frames]
Waveform shape: [num_frames * hop_samples]
"""
# Split data among workers.
worker_info = torch.utils.data.get_worker_info()
if worker_info is not None:
indices = [
idx
for i, idx in enumerate(self.indices)
if i % worker_info.num_workers # pylint: disable=no-member
== worker_info.id # pylint: disable=no-member
]
else:
indices = self.indices
for key in indices:
waveform, sr = self.dataset[key][:2]
# Resample the waveform to a fixed sample rate
waveform = librosa.resample(waveform[0].numpy(), sr, AUDIO_SAMPLE_RATE)
waveform = torch.clip(torch.tensor([waveform]), -1, 1)
# Pad to make sure waveform is a multiple of hop length.
padding = (
MEL_HOP_SAMPLES - waveform.numel() % MEL_HOP_SAMPLES
) % MEL_HOP_SAMPLES
# pyre-fixme[6]: Expected `List[int]` for 2nd param but got `Tuple[int,
# typing.Any]`.
waveform = torch.nn.functional.pad(waveform, (0, padding))
# Compute spectrogram of waveform.
# Length of spectrogram is exactly waveform length over hop length.
spectrogram = self.mel(waveform)
yield spectrogram.squeeze(0), waveform.squeeze(0)