Skip to content

kwon-young/pytorch-nsynth

Repository files navigation

pytorch-nsynth

Documentation Status

pytorch dataset for nsynth data

How to use

import torch.utils.data as data
import torchvision.transforms as transforms
from pytorch_nsynth.nsynth import NSynth

# audio samples are loaded as an int16 numpy array
# rescale intensity range as float [-1, 1]
toFloat = transforms.Lambda(lambda x: x / np.iinfo(np.int16).max)
# use instrument_family and instrument_source as classification targets
dataset = NSynth(
        "../nsynth-test",
        transform=toFloat,
        blacklist_pattern=["string"],  # blacklist string instrument
        categorical_field_list=["instrument_family", "instrument_source"])
loader = data.DataLoader(dataset, batch_size=32, shuffle=True)
for samples, instrument_family_target, instrument_source_target, targets \
                in loader:
        print(samples.shape, instrument_family_target.shape,
              instrument_source_target.shape)
        print(torch.min(samples), torch.max(samples))

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

About

pytorch dataset for nsynth data

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published