Kapre: On-GPU Audio Preprocessing Layers for a Quick Implementation of Deep Neural Network Models with Keras

Keunwoo Choi, Deokjin Joo, Juho KimarXiv 2017 · OpenReview

Abstract

We introduce Kapre, Keras layers for audio and music signal preprocessing. Music research using deep neural networks requires a heavy and tedious preprocessing stage, for which audio processing parameters are often ignored in parameter optimisation. To solve this problem, Kapre implements time-frequency conversions, normalisation, and data augmentation as Keras layers. We report simple benchmark results, showing real-time on-GPU preprocessing adds a reasonable amount of computation.

Introduction

Deep learning for audio applications, such as music tagging or acoustic event detection, typically involves a multi-stage pipeline: decoding audio files, resampling, and converting raw waveforms into time-frequency representations like spectrograms. Traditionally, the final stage is performed "offline," where spectrograms are pre-calculated and stored on disk. This approach introduces significant challenges: massive storage requirements for uncompressed features, inflexibility when experimenting with different signal processing parameters, and an optimization gap where preprocessing parameters remain fixed and unoptimized.

Methods

Kapre addresses these issues by providing a library of "plug-and-play" Keras layers that perform audio conversion on-the-fly on the GPU. The core component is the Spectrogram layer, which implements the Discrete Fourier Transform (DFT) using two 1D convolutional layers initialized with the real and imaginary parts of the DFT kernels. Because these are standard layers, the kernels can be updated during training, potentially learning task-specific frequency representations. The library also includes Melspectrogram for Mel-scale conversion, Normalization2D for feature scaling, and AdditiveNoise for data augmentation.

Experimental Setup

To evaluate the computational overhead of integrated preprocessing, the authors benchmarked a specific model architecture using dummy 30-second mono signals sampled at 32,000 Hz. The benchmark model consisted of five convolutional layers followed by global average pooling and a dense output layer.

Architecture of the 5-layer Convolutional Neural Network used for benchmarking.

Results and Discussion

The performance of the model was tested across several GPU architectures, comparing a standard ConvNet against one utilizing Kapre layers for integrated spectrogram conversion.

Comparison of training times for a standard ConvNet versus a ConvNet with integrated Kapre spectrogram layers across various GPU architectures.

As shown in the results, adding on-GPU Mel-spectrogram conversion increases total training time by approximately 20%. While this represents a measurable overhead, it is a constant cost regardless of model depth. For larger, more complex state-of-the-art architectures, this preprocessing time would constitute a significantly smaller fraction of the total computation. The trade-off—re-calculating spectrograms versus managing terabytes of pre-computed files—favors the flexibility and storage efficiency of the on-GPU approach.

Conclusion

Kapre successfully moves audio preprocessing into the neural network architecture, enabling real-time processing and hyperparameter optimization of signal processing parameters. While CPU-based decoding and resampling remain potential bottlenecks, the integration of time-frequency conversion into the GPU pipeline offers a scalable and flexible solution for modern deep learning research in audio and music.

Summary updated

Abstract

We introduce Kapre, Keras layers for audio and music signal preprocessing. Music research using deep neural networks requires a heavy and tedious preprocessing stage, for which audio processing parameters are often ignored in parameter optimisation. To solve this problem, Kapre implements time-frequency conversions, normalisation, and data augmentation as Keras layers. We report simple benchmark results, showing real-time on-GPU preprocessing adds a reasonable amount of computation.
BibTeX
@misc{choi2017kapre,
  author = {Keunwoo Choi and Deokjin Joo and Juho Kim},
  title = {{Kapre: On-GPU Audio Preprocessing Layers for a Quick Implementation of Deep Neural Network Models with Keras}},
  year = {2017},
  eprint = {1706.05781},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1706.05781},
}
Figure