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:
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
andPolarityInversion
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
- Format python code with black
- Use Google-style docstrings
- Use explicit relative imports, not absolute imports
Acknowledgements
The development of torch-audiomentations is kindly backed by Nomono
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for torch-audiomentations-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 909b1bae2633555f302e2d5bc5c0a4812adcad0c0c8d848ccda57c47fbb6035b |
|
MD5 | f5efd8572b25eed49ae029237c43000e |
|
BLAKE2b-256 | ed245be7349c79b27a9357ec6771276f166e6d9d5bd495b08b63bf0006e9aeb4 |
Hashes for torch_audiomentations-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 161de6f2d9d67d1382eb2d7b982e0ea133a222b82dfa1b6404473b751d10cac5 |
|
MD5 | 8fa90b38d412dccc846d0f5e307c6ef5 |
|
BLAKE2b-256 | 7a3d517f2ee981e317e340d357ab8f8995504e3e18e33569417d22917831beb2 |