← Open Source
keunwoochoi

kapre

kapre: Keras Audio Preprocessors.

Model DevelopmentDomain-specific trainingPython
Open on GitHub
Momentum
+0stars in 24 hours0.0%
947
Stars
145
Forks
+0
This week
9
Contributors
Created 2016-12-14 · Updated 2026-07-06 · #12459 today
Top developers
keunwoochoiXReyRobert-IBMjamesmishra

keunwoochoi/kapre is ranked 12,459 with 947 stars.

Same-category comparison

keunwoochoi/kapre is ranked 12,459 among these 8 peers; f90/Wave-U-Net is ranked 12,457.

Same-category comparison
NameRankMetrics
StanfordVL/GibsonEnv12,450
Language:
C
Stars:
948
Forks:
150
Description:
Gibson Environments: Real-World Perception for Embodied Agents.
stanfordnmbl/osim-rl12,454
Language:
Python
Stars:
948
Forks:
252
Description:
Reinforcement learning environments with musculoskeletal models.
ZhendongWang6/Uformer12,456
Language:
Python
Stars:
947
Forks:
133
Description:
[CVPR 2022] Official implementation of the paper "Uformer: A General U-Shaped Transformer for Image Restoration".
f90/Wave-U-Net12,457
Language:
Python
Stars:
947
Forks:
182
Description:
Implementation of the Wave-U-Net for audio source separation.
pranz24/pytorch-soft-actor-critic12,462
Language:
Python
Stars:
947
Forks:
189
Description:
PyTorch implementation of soft actor critic.
LeapLabTHU/DAT12,465
Language:
Python
Stars:
946
Forks:
86
Description:
Repository of Vision Transformer with Deformable Attention (CVPR2022) and DAT++: Spatially Dynamic Vision Transformerwith Deformable Attention.
DingXiaoH/RepLKNet-pytorch12,468
Language:
Python
Stars:
945
Forks:
90
Description:
Scaling Up Your Kernels to 31x31: Revisiting Large Kernel Design in CNNs (CVPR 2022).
MushroomRL/mushroom-rl12,469
Language:
Python
Stars:
945
Forks:
164
Description:
Python library for Reinforcement Learning.
Key parameters and specifications
Key parameters and specifications
ParameterValue
LanguagePython
CategoryModel Development
SubcategoryDomain-specific training
Stars947
Forks145
Contributors9
Created date2016-12-14
Updated date2026-07-06
Stars in 1 day0
Stars in 7 days0
Rank12,459
Previous rank12,385
Rank change-74
7-day stars rank13,435
Previous 7-day stars rank13,446
7-day stars rank change11
Total stars rank11,630
Previous total stars rank11,612
Total stars rank change-18
CountryUSA
README summary

Kapre Keras Audio Preprocessors - compute STFT, ISTFT, Melspectrogram, and others on GPU real-time. 20, with type hints for better development experience Why Kapre? Pre-computation You can optimize DSP parameters Your model deployment becomes much simpler and consistent. Your code and model has less dependencies vs. Consistent with 1D/2D tensorflow batch shapes Data format agnostic ( and ) Less error prone - Kapre layers are tested against Librosa (stft, decibel, etc) - which is (trust me) *trickier* than you think. Kapre layers

have some extended APIs from the default implementation such as. A perfectly invertible and pair Mel-spectrogram with more options Reproducibility - Kapre is available on pip with versioning Workflow with Kapre 1. Resample the audio to the right sampling rate and store the audio signals (waveforms). The data loader simply loads audio signals and feed them into the model 4. In your hyperparameter search, include DSP parameters like to boost the performance. When deploying the final model, all you need

to remember is the sampling rate of the signal. Installation Development Kapre includes comprehensive type hints for better IDE support and development experience. Type Checking Run type checking with our included script: Or use your preferred type checker: Development Setup API Documentation Please refer to Kapre API Documentation at One-shot example See the Jupyter notebook at the example folder TFLite compatibility The layer is not TFLite compatible (due to ). To create a TFLite compatible model, first train using the

normal layers then create a new model replacing and with , . TFLite compatible layers are restricted to a batch size of 1 which prevents use of them during training. Citation Please cite this paper if you use Kapre for your work.

Frequently asked questions

How many stars and forks are recorded?

keunwoochoi/kapre has 947 stars and 145 forks.

What is the repository rank?

keunwoochoi/kapre is ranked 12,459.

What language and category are recorded?

keunwoochoi/kapre has 947 stars, uses Python and belongs to Model Development.

Which repository is closest in rank?

keunwoochoi/kapre is compared with f90/Wave-U-Net, ranked 12,457 with 947 stars.

README

Kapre

Keras Audio Preprocessors - compute STFT, ISTFT, Melspectrogram, and others on GPU real-time.

Tested on Python 3.9+ with TensorFlow 2.16-2.20, with type hints for better development experience

Why Kapre?

vs. Pre-computation

  • You can optimize DSP parameters
  • Your model deployment becomes much simpler and consistent.
  • Your code and model has less dependencies

vs. Your own implementation

  • Quick and easy!
  • Consistent with 1D/2D tensorflow batch shapes
  • Data format agnostic (channels_first and channels_last)
  • Less error prone - Kapre layers are tested against Librosa (stft, decibel, etc) - which is (trust me) trickier than you think.
  • Kapre layers have some extended APIs from the default tf.signals implementation such as..
    • A perfectly invertible STFT and InverseSTFT pair
    • Mel-spectrogram with more options
  • Reproducibility - Kapre is available on pip with versioning

Workflow with Kapre

  1. Preprocess your audio dataset. Resample the audio to the right sampling rate and store the audio signals (waveforms).
  2. In your ML model, add Kapre layer e.g. kapre.time_frequency.STFT() as the first layer of the model.
  3. The data loader simply loads audio signals and feed them into the model
  4. In your hyperparameter search, include DSP parameters like n_fft to boost the performance.
  5. When deploying the final model, all you need to remember is the sampling rate of the signal. No dependency or preprocessing!

Installation

pip install kapre

Development

Kapre includes comprehensive type hints for better IDE support and development experience.

Type Checking

Run type checking with our included script:

python scripts/check_types.py

Or use your preferred type checker:

# With mypy
pip install mypy
mypy kapre/

# With pyright
pip install pyright
pyright kapre/

Development Setup

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest tests/

# Run type checking
python scripts/check_types.py

# Format code
black kapre/ tests/

# Lint code
flake8 kapre/ tests/

API Documentation

Please refer to Kapre API Documentation at https://kapre.readthedocs.io

One-shot example

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Input, Conv2D, BatchNormalization, ReLU, GlobalAveragePooling2D, Dense, Softmax
from kapre import STFT, Magnitude, MagnitudeToDecibel
from kapre.composed import get_melspectrogram_layer, get_log_frequency_spectrogram_layer

# 6 channels (!), maybe 1-sec audio signal, for an example.
input_shape = (44100, 6)
sr = 44100
model = Sequential()
model.add(Input(shape=input_shape))
# A STFT layer
model.add(STFT(n_fft=2048, win_length=2048, hop_length=1024,
               window_name=None, pad_end=False,
               input_data_format='channels_last', output_data_format='channels_last'))
model.add(Magnitude())
model.add(MagnitudeToDecibel())  # these three layers can be replaced with get_stft_magnitude_layer()
# Alternatively, you may want to use a melspectrogram layer
# melgram_layer = get_melspectrogram_layer()
# or log-frequency layer
# log_stft_layer = get_log_frequency_spectrogram_layer() 

# add more layers as you want
model.add(Conv2D(32, (3, 3), strides=(2, 2)))
model.add(BatchNormalization())
model.add(ReLU())
model.add(GlobalAveragePooling2D())
model.add(Dense(10))
model.add(Softmax())

# Compile the model
model.compile('adam', 'categorical_crossentropy') # if single-label classification

# train it with raw audio sample inputs
# for example, you may have functions that load your data as below.
x = load_x() # e.g., x.shape = (10000, 44100, 6)
y = load_y() # e.g., y.shape = (10000, 10) if it's 10-class classification
# then..
model.fit(x, y)
# Done!

TFLite compatibility

The STFT layer is not TFLite compatible (due to tf.signal.stft). To create a TFLite compatible model, first train using the normal kapre layers then create a new model replacing STFT and Magnitude with STFTTflite, MagnitudeTflite. TFLite compatible layers are restricted to a batch size of 1 which prevents use of them during training.

# assumes you have run the one-shot example above.
from kapre import STFTTflite, MagnitudeTflite
model_tflite = Sequential()
model_tflite.add(Input(shape=input_shape))

model_tflite.add(STFTTflite(n_fft=2048, win_length=2048, hop_length=1024,
               window_name=None, pad_end=False,
               input_data_format='channels_last', output_data_format='channels_last'))
model_tflite.add(MagnitudeTflite())
model_tflite.add(MagnitudeToDecibel())  
model_tflite.add(Conv2D(32, (3, 3), strides=(2, 2)))
model_tflite.add(BatchNormalization())
model_tflite.add(ReLU())
model_tflite.add(GlobalAveragePooling2D())
model_tflite.add(Dense(10))
model_tflite.add(Softmax())

# load the trained weights into the tflite compatible model.
model_tflite.set_weights(model.get_weights())

Citation

Please cite this paper if you use Kapre for your work.

@inproceedings{choi2017kapre,
  title={Kapre: On-GPU Audio Preprocessing Layers for a Quick Implementation of Deep Neural Network Models with Keras},
  author={Choi, Keunwoo and Joo, Deokjin and Kim, Juho},
  booktitle={Machine Learning for Music Discovery Workshop at 34th International Conference on Machine Learning},
  year={2017},
  organization={ICML}
}
Nearby in the ranking
Similar items