Skip to main content

A Pytorch library for audio data augmentation. Inspired by audiomentations. Useful for deep learning.

Project description

torch-audiomentations

Audio data augmentation in PyTorch. Inspired by audiomentations.

Setup

pip install torch-audiomentations

Usage example

import torch
from torch_audiomentations import Gain


# Initialize augmentation callable
apply_gain_augmentation = Gain(
    min_gain_in_db=-15.0,
    max_gain_in_db=5.0,
    p=0.5,
)

# Note: torch-audiomentations can run on CPU or GPU
torch_device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

# Make an example tensor with white noise.
# This tensor represents 8 audio snippets with 2 channels (stereo) and 2 seconds of 16 kHz audio.
audio_samples = torch.rand(size=(8, 2, 32000), dtype=torch.float32, device=torch_device) - 0.5

# Apply gain augmentation. This varies the gain of (some of) the audio snippets in the batch independently.
perturbed_audio_samples = apply_gain_augmentation(audio_samples, sample_rate=16000)

Contribute

Contributors welcome! Join the Asteroid's slack to start discussing about torch-audiomentations with us.

Motivation: Speed

We don't want data augmentation to be a bottle neck in model training speed. Here is a comparison of the time it takes to run 1D convolution:

Convolve execution times

Current state

torch-audiomentations is in a very early development stage, so it's not ready for prime time yet. Meanwhile, star the repo and stay tuned!

Version history

v0.2.0 (2020-10-19)

  • Simplify API for using CUDA tensors. The device is now inferred from the input tensor.
  • Implement PeakNormalization
  • Expose convolve in the API

v0.1.0 (2020-10-12)

  • Initial release with Gain and PolarityInversion

Development

Setup

A GPU-enabled development environment for torch-audiomentations can be created with conda:

  • conda create --name torch-audiomentations python=3.7.3
  • conda activate torch-audiomentations
  • conda install pytorch cudatoolkit=10.1 -c pytorch
  • conda env update

Run tests

pytest

Conventions

Acknowledgements

The development of torch-audiomentations is kindly backed by Nomono

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torch-audiomentations-0.2.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torch_audiomentations-0.2.0-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file torch-audiomentations-0.2.0.tar.gz.

File metadata

  • Download URL: torch-audiomentations-0.2.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.3

File hashes

Hashes for torch-audiomentations-0.2.0.tar.gz
Algorithm Hash digest
SHA256 909b1bae2633555f302e2d5bc5c0a4812adcad0c0c8d848ccda57c47fbb6035b
MD5 f5efd8572b25eed49ae029237c43000e
BLAKE2b-256 ed245be7349c79b27a9357ec6771276f166e6d9d5bd495b08b63bf0006e9aeb4

See more details on using hashes here.

File details

Details for the file torch_audiomentations-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: torch_audiomentations-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.3

File hashes

Hashes for torch_audiomentations-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 161de6f2d9d67d1382eb2d7b982e0ea133a222b82dfa1b6404473b751d10cac5
MD5 8fa90b38d412dccc846d0f5e307c6ef5
BLAKE2b-256 7a3d517f2ee981e317e340d357ab8f8995504e3e18e33569417d22917831beb2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page