Instructions to use moonbox-dev/DeepFilterNet3-MLX with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use moonbox-dev/DeepFilterNet3-MLX with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] hf download moonbox-dev/DeepFilterNet3-MLX --local-dir DeepFilterNet3-MLX
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
File size: 17,557 Bytes
12f47a5 bd7b742 12f47a5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | ---
license: mit
pipeline_tag: audio-to-audio
library_name: mlx-audio
tags:
- mlx
- moonbox
- mlx-audio
- deepfilternet
- speech-enhancement
- denoising
- 48khz
---
# DeepFilterNet3 MLX
MLX builds of [DeepFilterNet3](https://github.com/Rikorose/DeepFilterNet), made by Moonbox for Apple Silicon Macs. Each precision is a folder; keep a folder's
files together. Only the parts listed below are converted: the rest of the pipeline comes from the original
repository unless the section below says otherwise.
## Files
The last column is how far each build is from the original PyTorch model on the same inputs (see the section below
for what was measured).
| Precision | File | Size | sha256 | Checked against the original |
|---|---|---|---|---|
| bf16 | [`bf16/config.json`](https://huggingface.co/moonbox-dev/DeepFilterNet3-MLX/blob/main/bf16/config.json) | 0.9 kB | `cc96fe1bf688` | below threshold (experimental): SI-SDR 8.58 dB, 0.66 dB below the original on one clip; DNSMOS 2.93; output vs the original's 25.2 / 16.3 dB |
| bf16 | [`bf16/model.safetensors`](https://huggingface.co/moonbox-dev/DeepFilterNet3-MLX/blob/main/bf16/model.safetensors) | 4.3 MB | `ad9d67c69a00` | below threshold (experimental): SI-SDR 8.58 dB, 0.66 dB below the original on one clip; DNSMOS 2.93; output vs the original's 25.2 / 16.3 dB |
| fp16 | [`fp16/config.json`](https://huggingface.co/moonbox-dev/DeepFilterNet3-MLX/blob/main/fp16/config.json) | 0.9 kB | `cc96fe1bf688` | SI-SDR 8.62 dB (original 8.71), DNSMOS 2.92 (2.95); output vs the original's 25.3 dB mean / 17.7 dB worst clip (mlx-audio float32: 25.3 / 17.7) |
| fp16 | [`fp16/model.safetensors`](https://huggingface.co/moonbox-dev/DeepFilterNet3-MLX/blob/main/fp16/model.safetensors) | 4.3 MB | `a0e5b4f0c96a` | SI-SDR 8.62 dB (original 8.71), DNSMOS 2.92 (2.95); output vs the original's 25.3 dB mean / 17.7 dB worst clip (mlx-audio float32: 25.3 / 17.7) |
## How to run
DeepFilterNet3 (real-time speech enhancement at 48 kHz: ERB-band gains plus deep filtering of the low band) for
[mlx-audio](https://github.com/Blaizzy/mlx-audio). Each folder holds `model.safetensors` (the official checkpoint's
state dict, PyTorch names, cast to the precision) and `config.json` (the model's `config.ini` as mlx-audio reads it).
Tested with `mlx-audio==0.6.5`:
```python
from mlx_audio.sts.models.deepfilternet import DeepFilterNetModel
import soundfile as sf
model = DeepFilterNetModel.from_pretrained("fp16", subfolder=None) # a downloaded folder
model.enhance_file("noisy.wav", "clean.wav") # 48 kHz in and out
```
Only `bf16/` and `fp16/`: the network has 2.2 M parameters, and mlx-audio's DeepFilterNet loader maps the PyTorch
weights by name and takes no quantized tensors.
**How they were checked.** 8 noisy 48 kHz clips (LibriSpeech speech with babble or pink noise, 0-10 dB SNR),
enhanced by the original (the official `deepfilternet` 0.5.6 package: PyTorch, float32, libDF's STFT and features)
and by every MLX build: SI-SDR against the clean speech, DNSMOS P.835, and how close each output is to the
original's. Pass: SI-SDR on every clip at most 0.5 dB below the original's, mean DNSMOS at most 0.1 below.
mlx-audio's DeepFilterNet3 is a reimplementation: even in float32 its output is 25 dB from the original's (17.7 dB on
the worst clip), with the same enhancement quality on these measures.
| Precision | Size | SI-SDR (dB) | DNSMOS | Output vs the original's, mean / worst clip (dB) | Real-time factor, M5 24 GB |
|---|---|---|---|---|---|
| noisy input | - | 4.99 | 2.10 | - | - |
| original (PyTorch fp32, CPU) | - | 8.71 | 2.95 | - | 0.018 |
| `fp16/` | 4.3 MB | 8.62 | 2.92 | 25.3 / 17.7 | 0.022 |
| `bf16/` (experimental) | 4.3 MB | 8.58 (0.66 below the original on one clip) | 2.93 | 25.2 / 16.3 | 0.022 |
## How these were made
From [DeepFilterNet3](https://github.com/Rikorose/DeepFilterNet) at revision `7b14b895fe`: the original weights loaded in MLX and stored as bf16 or fp16, or
quantized with MLX's affine quantization (`8bit`, `6bit`, `4bit`, group size 64; layers MLX can't quantize, such as
convolutions and norms, stay bf16). Every build was checked against the original before upload; the `sha256` column
above is what the files must hash to.
## License
MIT/Apache-2.0. These files are a derivative of the original model and carry its license: it is copied in this
repository, and it governs your use of these files. The original model card follows unchanged.
---
# Original model card
# DeepFilterNet
A Low Complexity Speech Enhancement Framework for Full-Band Audio (48kHz) using on Deep Filtering.

For PipeWire integration as a virtual noise suppression microphone look [here](https://github.com/Rikorose/DeepFilterNet/blob/main/ladspa/README.md).
### Demo
https://github.com/Rikorose/DeepFilterNet/assets/16517898/79679fd7-de73-4c22-948c-891927c7d2ca
To run the demo (linux only) use:
```bash
cargo +nightly run -p df-demo --features ui --bin df-demo --release
```
### News
- New DeepFilterNet Demo: *DeepFilterNet: Perceptually Motivated Real-Time Speech Enhancement*
- Paper: https://arxiv.org/abs/2305.08227
- Video: https://youtu.be/EO7n96YwnyE
- New Multi-Frame Filtering Paper: *Deep Multi-Frame Filtering for Hearing Aids*
- Paper: https://arxiv.org/abs/2305.08225
- Real-time version and a LADSPA plugin
- [Pre-compiled binary](#deep-filter), no python dependencies. Usage: `deep-filter audio-file.wav`
- [LADSPA plugin](ladspa/) with pipewire filter-chain integration for real-time noise reduction on your mic.
- DeepFilterNet2 Paper: *DeepFilterNet2: Towards Real-Time Speech Enhancement on Embedded Devices for Full-Band Audio*
- Paper: https://arxiv.org/abs/2205.05474
- Samples: https://rikorose.github.io/DeepFilterNet2-Samples/
- Demo: https://huggingface.co/spaces/hshr/DeepFilterNet2
- Original DeepFilterNet Paper: *DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio based on Deep Filtering*
- Paper: https://arxiv.org/abs/2110.05588
- Samples: https://rikorose.github.io/DeepFilterNet-Samples/
- Demo: https://huggingface.co/spaces/hshr/DeepFilterNet
- Video Lecture: https://youtu.be/it90gBqkY6k
## Usage
### deep-filter
Download a pre-compiled deep-filter binary from the [release page](https://github.com/Rikorose/DeepFilterNet/releases/).
You can use `deep-filter` to suppress noise in noisy .wav audio files. Currently, only wav files with a sampling rate of 48kHz are supported.
```bash
USAGE:
deep-filter [OPTIONS] [FILES]...
ARGS:
<FILES>...
OPTIONS:
-D, --compensate-delay
Compensate delay of STFT and model lookahead
-h, --help
Print help information
-m, --model <MODEL>
Path to model tar.gz. Defaults to DeepFilterNet2.
-o, --out-dir <OUT_DIR>
[default: out]
--pf
Enable postfilter
-v, --verbose
Logging verbosity
-V, --version
Print version information
```
If you want to use the pytorch backend e.g. for GPU processing, see further below for the Python usage.
### DeepFilterNet Framework
This framework supports Linux, MacOS and Windows. Training is only tested under Linux. The framework is structured as follows:
* `libDF` contains Rust code used for data loading and augmentation.
* `DeepFilterNet` contains DeepFilterNet code training, evaluation and visualization as well as pretrained model weights.
* `pyDF` contains a Python wrapper of libDF STFT/ISTFT processing loop.
* `pyDF-data` contains a Python wrapper of libDF dataset functionality and provides a pytorch data loader.
* `ladspa` contains a LADSPA plugin for real-time noise suppression.
* `models` contains pretrained for usage in DeepFilterNet (Python) or libDF/deep-filter (Rust)
### DeepFilterNet Python: PyPI
Install the DeepFilterNet Python wheel via pip:
```bash
# Install cpu/cuda pytorch (>=1.9) dependency from pytorch.org, e.g.:
pip install torch torchaudio -f https://download.pytorch.org/whl/cpu/torch_stable.html
# Install DeepFilterNet
pip install deepfilternet
# Or install DeepFilterNet including data loading functionality for training (Linux only)
pip install deepfilternet[train]
```
To enhance noisy audio files using DeepFilterNet run
```bash
# Specify an output directory with --output-dir [OUTPUT_DIR]
deepFilter path/to/noisy_audio.wav
```
### Manual Installation
Install cargo via [rustup](https://rustup.rs/). Usage of a `conda` or `virtualenv` recommended.
Please read the comments and only execute the commands that you need.
Installation of python dependencies and libDF:
```bash
cd path/to/DeepFilterNet/ # cd into repository
# Recommended: Install or activate a python env
# Mandatory: Install cpu/cuda pytorch (>=1.8) dependency from pytorch.org, e.g.:
pip install torch torchaudio -f https://download.pytorch.org/whl/cpu/torch_stable.html
# Install build dependencies used to compile libdf and DeepFilterNet python wheels
pip install maturin poetry
# Install remaining DeepFilterNet python dependencies
# *Option A:* Install DeepFilterNet python wheel globally within your environment. Do this if you want use
# this repos as is, and don't want to develop within this repository.
poetry -C DeepFilterNet install -E train -E eval
# *Option B:* If you want to develop within this repo, install only dependencies and work with the repository version
poetry -C DeepFilterNet install -E train -E eval --no-root
export PYTHONPATH=$PWD/DeepFilterNet # And set the python path correctly
# Build and install libdf python package required for enhance.py
maturin develop --release -m pyDF/Cargo.toml
# *Optional*: Install libdfdata python package with dataset and dataloading functionality for training
# Required build dependency: HDF5 headers (e.g. ubuntu: libhdf5-dev)
maturin develop --release -m pyDF-data/Cargo.toml
# If you have troubles with hdf5 you may try to build and link hdf5 statically:
maturin develop --release --features hdf5-static -m pyDF-data/Cargo.toml
```
### Use DeepFilterNet from command line
To enhance noisy audio files using DeepFilterNet run
```bash
$ python DeepFilterNet/df/enhance.py --help
usage: enhance.py [-h] [--model-base-dir MODEL_BASE_DIR] [--pf] [--output-dir OUTPUT_DIR] [--log-level LOG_LEVEL] [--compensate-delay]
noisy_audio_files [noisy_audio_files ...]
positional arguments:
noisy_audio_files List of noise files to mix with the clean speech file.
optional arguments:
-h, --help show this help message and exit
--model-base-dir MODEL_BASE_DIR, -m MODEL_BASE_DIR
Model directory containing checkpoints and config.
To load a pretrained model, you may just provide the model name, e.g. `DeepFilterNet`.
By default, the pretrained DeepFilterNet2 model is loaded.
--pf Post-filter that slightly over-attenuates very noisy sections.
--output-dir OUTPUT_DIR, -o OUTPUT_DIR
Directory in which the enhanced audio files will be stored.
--log-level LOG_LEVEL
Logger verbosity. Can be one of (debug, info, error, none)
--compensate-delay, -D
Add some paddig to compensate the delay introduced by the real-time STFT/ISTFT implementation.
# Enhance audio with original DeepFilterNet
python DeepFilterNet/df/enhance.py -m DeepFilterNet path/to/noisy_audio.wav
# Enhance audio with DeepFilterNet2
python DeepFilterNet/df/enhance.py -m DeepFilterNet2 path/to/noisy_audio.wav
```
### Use DeepFilterNet within your Python script
```py
from df import enhance, init_df
model, df_state, _ = init_df() # Load default model
enhanced_audio = enhance(model, df_state, noisy_audio)
```
See [here](https://github.com/Rikorose/DeepFilterNet/blob/main/scripts/external_usage.py) for a full example.
### Training
The entry point is `DeepFilterNet/df/train.py`. It expects a data directory containing HDF5 dataset
as well as a dataset configuration json file.
So, you first need to create your datasets in HDF5 format. Each dataset typically only
holds training, validation, or test set of noise, speech or RIRs.
```py
# Install additional dependencies for dataset creation
pip install h5py librosa soundfile
# Go to DeepFilterNet python package
cd path/to/DeepFilterNet/DeepFilterNet
# Prepare text file (e.g. called training_set.txt) containing paths to .wav files
#
# usage: prepare_data.py [-h] [--num_workers NUM_WORKERS] [--max_freq MAX_FREQ] [--sr SR] [--dtype DTYPE]
# [--codec CODEC] [--mono] [--compression COMPRESSION]
# type audio_files hdf5_db
#
# where:
# type: One of `speech`, `noise`, `rir`
# audio_files: Text file containing paths to audio files to include in the dataset
# hdf5_db: Output HDF5 dataset.
python df/scripts/prepare_data.py --sr 48000 speech training_set.txt TRAIN_SET_SPEECH.hdf5
```
All datasets should be made available in one dataset folder for the train script.
The dataset configuration file should contain 3 entries: "train", "valid", "test". Each of those
contains a list of datasets (e.g. a speech, noise and a RIR dataset). You can use multiple speech
or noise dataset. Optionally, a sampling factor may be specified that can be used to over/under-sample
the dataset. Say, you have a specific dataset with transient noises and want to increase the amount
of non-stationary noises by oversampling. In most cases you want to set this factor to 1.
<details>
<summary>Dataset config example:</summary>
<p>
`dataset.cfg`
```json
{
"train": [
[
"TRAIN_SET_SPEECH.hdf5",
1.0
],
[
"TRAIN_SET_NOISE.hdf5",
1.0
],
[
"TRAIN_SET_RIR.hdf5",
1.0
]
],
"valid": [
[
"VALID_SET_SPEECH.hdf5",
1.0
],
[
"VALID_SET_NOISE.hdf5",
1.0
],
[
"VALID_SET_RIR.hdf5",
1.0
]
],
"test": [
[
"TEST_SET_SPEECH.hdf5",
1.0
],
[
"TEST_SET_NOISE.hdf5",
1.0
],
[
"TEST_SET_RIR.hdf5",
1.0
]
]
}
```
</p>
</details>
Finally, start the training script. The training script may create a model `base_dir` if not
existing used for logging, some audio samples, model checkpoints, and config. If no config file is
found, it will create a default config. See
[DeepFilterNet/pretrained_models/DeepFilterNet](https://github.com/Rikorose/DeepFilterNet/blob/main/DeepFilterNet/pretrained_models/DeepFilterNet/config.ini)
for a config file.
```py
# usage: train.py [-h] [--debug] data_config_file data_dir base_dir
python df/train.py path/to/dataset.cfg path/to/data_dir/ path/to/base_dir/
```
## Citation Guide
To reproduce any metrics, we recomend to use the python implementation via `pip install deepfilternet`.
If you use this framework, please cite: *DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio based on Deep Filtering*
```bibtex
@inproceedings{schroeter2022deepfilternet,
title={{DeepFilterNet}: A Low Complexity Speech Enhancement Framework for Full-Band Audio based on Deep Filtering},
author = {Schröter, Hendrik and Escalante-B., Alberto N. and Rosenkranz, Tobias and Maier, Andreas},
booktitle={ICASSP 2022 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP)},
year={2022},
organization={IEEE}
}
```
If you use the DeepFilterNet2 model, please cite: *DeepFilterNet2: Towards Real-Time Speech Enhancement on Embedded Devices for Full-Band Audio*
```bibtex
@inproceedings{schroeter2022deepfilternet2,
title = {{DeepFilterNet2}: Towards Real-Time Speech Enhancement on Embedded Devices for Full-Band Audio},
author = {Schröter, Hendrik and Escalante-B., Alberto N. and Rosenkranz, Tobias and Maier, Andreas},
booktitle={17th International Workshop on Acoustic Signal Enhancement (IWAENC 2022)},
year = {2022},
}
```
If you use the DeepFilterNet3 model, please cite: *DeepFilterNet: Perceptually Motivated Real-Time Speech Enhancement*
```bibtex
@inproceedings{schroeter2023deepfilternet3,
title = {{DeepFilterNet}: Perceptually Motivated Real-Time Speech Enhancement},
author = {Schröter, Hendrik and Rosenkranz, Tobias and Escalante-B., Alberto N. and Maier, Andreas},
booktitle={INTERSPEECH},
year = {2023},
}
```
If you use the multi-frame beamforming algorithms. please cite *Deep Multi-Frame Filtering for Hearing Aids*
```bibtex
@inproceedings{schroeter2023deep_mf,
title = {Deep Multi-Frame Filtering for Hearing Aids},
author = {Schröter, Hendrik and Rosenkranz, Tobias and Escalante-B., Alberto N. and Maier, Andreas},
booktitle={INTERSPEECH},
year = {2023},
}
```
## License
DeepFilterNet is free and open source! All code and model weights in this repository are dual-licensed under either:
* MIT License ([LICENSE-MIT](LICENSE-MIT) or [http://opensource.org/licenses/MIT](http://opensource.org/licenses/MIT))
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0))
at your option. This means you can select the license you prefer!
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
|