Package: demucs
Demucs Music Source SeparationThis is the 4th release of Demucs (v4), featuring Hybrid Transformer based source separation.For the classic Hybrid Demucs (v3):Go this commit.
If you are experiencing issues and want the old Demucs back, please fill an issue, and then you can get back to the v3 withgit checkout v3. You can also goDemucs v2.Demucs is a state-of-the-art music source separation model, currently capable of separating
drums, bass, and vocals from the rest of the accompaniment.
Demucs is based on a U-Net convolutional architecture inspired byWave-U-Net.
The v4 version featuresHybrid Transformer Demucs, a hybrid spectrogram/waveform separation model using Transformers.
It is based onHybrid Demucs(also provided in this repo) with the innermost layers are
replaced by a cross-domain Transformer Encoder. This Transformer uses self-attention within each domain,
and cross-attention across domains.
The model achieves a SDR of 9.00 dB on the MUSDB HQ test set. Moreover, when using sparse attention
kernels to extend its receptive field and per source fine-tuning, we achieve state-of-the-art 9.20 dB of SDR.Samples are availableon our sample page.
Checkoutour paperfor more information.
It has been trained on theMUSDB HQdataset + an extra training dataset of 800 songs.
This model separates drums, bass and vocals and other stems for any song.As Hybrid Transformer Demucs is brand new, it is not activated by default, you can activate it in the usual
commands described hereafter with-n htdemucs_ft.
The single, non fine-tuned model is provided as-n htdemucs, and the retrained baseline
as-n hdemucs_mmi. The Sparse Hybrid Transformer model decribed in our paper is not provided as its
requires custom CUDA code that is not ready for release yet.
We are also releasing an experimental 6 sources model, that adds aguitarandpianosource.
Quick testing seems to show okay quality forguitar, but a lot of bleeding and artifacts for thepianosource.Important news if you are already using DemucsSee therelease notesfor more details.22/02/2023: added support for theSDX 2023 Challenge,
see the dedicateddoc page07/12/2022: Demucs v4 now on PyPI.htdemucsmodel now used by default. Also releasing
a 6 sources models (addingguitarandpiano, although the latter doesn't work so well at the moment).16/11/2022: Added the newHybrid Transformer Demucs v4models.
Adding support for thetorchaudio implementation of HDemucs.30/08/2022: added reproducibility and ablation grids, along with an updated version of the paper.17/08/2022: Releasing v3.0.5: Set split segment length to reduce memory. Compatible with pyTorch 1.12.24/02/2022: Releasing v3.0.4: split into two stems (i.e. karaoke mode).
Export as float32 or int24.17/12/2021: Releasing v3.0.3: bug fixes  (thanks @keunwoochoi), memory drastically
reduced on GPU (thanks @famzah) and new multi-core evaluation on CPU (-jflag).12/11/2021: ReleasingDemucs v3with hybrid domain separation. Strong improvements
on all sources. This is the model that won Sony MDX challenge.11/05/2021: Adding support for MusDB-HQ and arbitrary wav set, for the MDX challenge. For more information
on joining the challenge with Demucs seethe Demucs MDX instructionsComparison with other modelsWe provide hereafter a summary of the different metrics presented in the paper.
You can also compare Hybrid Demucs (v3),KUIELAB-MDX-Net,Spleeter, Open-Unmix, Demucs (v1), and Conv-Tasnet on one of my favorite
songs on mysoundcloud playlist.Comparison of accuracyOverall SDRis the mean of the SDR for each of the 4 sources,MOS Qualityis a rating from 1 to 5
of the naturalness and absence of artifacts given by human listeners (5 = no artifacts),MOS Contaminationis a rating from 1 to 5 with 5 being zero contamination by other sources. We refer the reader to ourpaper,
for more details.ModelDomainExtra data?Overall SDRMOS QualityMOS ContaminationWave-U-Netwaveformno3.2--Open-Unmixspectrogramno5.3--D3Netspectrogramno6.0--Conv-Tasnetwaveformno5.7-Demucs (v2)waveformno6.32.372.36ResUNetDecouple+spectrogramno6.7--KUIELAB-MDX-Nethybridno7.52.862.55Band-Spit RNNspectrogramno8.2--Hybrid Demucs (v3)hybridno7.72.833.04MMDenseLSTMspectrogram804 songs6.0--D3Netspectrogram1.5k songs6.7--Spleeterspectrogram25k songs5.9--Band-Spit RNNspectrogram1.7k (mixes only)9.0--HT Demucs f.t. (v4)hybrid800 songs9.0--RequirementsYou will need at least Python 3.8. Seerequirements_minimal.txtfor requirements for separation only,
andenvironment-[cpu|cuda].yml(orrequirements.txt) if you want to train a new model.For Windows usersEverytime you seepython3, replace it withpython.exe. You should always run commands from the
Anaconda console.For musiciansIf you just want to use Demucs to separate tracks, you can install it withpython3-mpipinstall-UdemucsFor bleeding edge versions, you can install directly from this repo usingpython3-mpipinstall-Ugit+https://github.com/facebookresearch/demucs#egg=demucsAdvanced OS support are provided on the following page,you must read the page for your OS before posting an issues:If you are using Windows:Windows support.If you are using MAC OS X:Mac OS X support.If you are using Linux:Linux support.For machine learning scientistsIf you have anaconda installed, you can run from the root of this repository:condaenvupdate-fenvironment-cpu.yml# if you don't have GPUscondaenvupdate-fenvironment-cuda.yml# if you have GPUscondaactivatedemucs
pipinstall-e.This will create ademucsenvironment with all the dependencies installed.You will also need to installsoundstretch/soundtouch: on Mac OSX you can dobrew install sound-touch,
and on Ubuntusudo apt-get install soundstretch. This is used for the
pitch/tempo augmentation.Running in DockerThanks to @xserrat, there is now a Docker image definition ready for using Demucs. This can ensure all libraries are correctly installed without interfering with the host OS. See his repoDocker Facebook Demucsfor more information.Running from ColabI made a Colab to easily separate track with Demucs. Note that
transfer speeds with Colab are a bit slow for large media files,
but it will allow you to use Demucs without installing anything.Demucs on Google ColabWeb DemoIntegrated toHugging Face SpaceswithGradio. See demo:Graphical Interface@CarlGao4 has released a GUI for Demucs:CarlGao4/Demucs-Gui. Downloads for Windows and macOS is availablehere. UseFossHub mirrorto speed up your download.@Anjok07 is providing a self contained GUI inUVR (Ultimate Vocal Remover)that supports Demucs.Other providersAudiostrip is providing free online separation with Demucs on their websitehttps://audiostrip.co.uk/.MVSepalso provides free online separation, selectDemucs3 model Bfor the best quality.Neutoneprovides a realtime Demucs model in their free VST/AU plugin that can be used in your favorite DAW.Separating tracksIn order to try Demucs, you can just run from any folder (as long as you properly installed it)demucsPATH_TO_AUDIO_FILE_1[PATH_TO_AUDIO_FILE_2...]# for Demucs# If you used `pip install --user` you might need to replace demucs with python3 -m demucspython3-mdemucs--mp3--mp3-bitrateBITRATEPATH_TO_AUDIO_FILE_1# output files saved as MP3# use --mp3-preset to change encoder preset, 2 for best quality, 7 for fastest# If your filename contain spaces don't forget to quote it !!!demucs"my music/my favorite track.mp3"# You can select different models with `-n` mdx_q is the quantized model, smaller but maybe a bit less accurate.demucs-nmdx_qmyfile.mp3# If you only want to separate vocals out of an audio, use `--two-stems=vocals` (You can also set to drums or bass)demucs--two-stems=vocalsmyfile.mp3If you have a GPU, but you run out of memory, please use--segment SEGMENTto reduce length of each split.SEGMENTshould be changed to a integer. Personally recommend not less than 10 (the bigger the number is, the more memory is required, but quality may increase). Create an environment variablePYTORCH_NO_CUDA_MEMORY_CACHING=1is also helpful. If this still cannot help, please add-d cputo the command line. See the section hereafter for more details on the memory requirements for GPU acceleration.Separated tracks are stored in theseparated/MODEL_NAME/TRACK_NAMEfolder. There you will find four stereo wav files sampled at 44.1 kHz:drums.wav,bass.wav,other.wav,vocals.wav(or.mp3if you used the--mp3option).All audio formats supported bytorchaudiocan be processed (i.e. wav, mp3, flac, ogg/vorbis on Linux/Mac OS X etc.). On Windows,torchaudiohas limited support, so we rely onffmpeg, which should support pretty much anything.
Audio is resampled on the fly if necessary.
The output will be a wave file encoded as int16.
You can save as float32 wav files with--float32, or 24 bits integer wav with--int24.
You can pass--mp3to save as mp3 instead, and set the bitrate with--mp3-bitrate(default is 320kbps).It can happen that the output would need clipping, in particular due to some separation artifacts.
Demucs will automatically rescale each output stem so as to avoid clipping. This can however break
the relative volume between stems. If instead you prefer hard clipping, pass--clip-mode clamp.
You can also try to reduce the volume of the input mixture before feeding it to Demucs.Other pre-trained models can be selected with the-nflag.
The list of pre-trained models is:htdemucs: first version of Hybrid Transformer Demucs. Trained on MusDB + 800 songs. Default model.htdemucs_ft: fine-tuned version ofhtdemucs, separation will take 4 times more time
but might be a bit better. Same training set ashtdemucs.htdemucs_6s: 6 sources version ofhtdemucs, withpianoandguitarbeing added as sources.
Note that thepianosource is not working great at the moment.hdemucs_mmi: Hybrid Demucs v3, retrained on MusDB + 800 songs.mdx: trained only on MusDB HQ, winning model on track A at theMDXchallenge.mdx_extra: trained with extra training data (including MusDB test set), ranked 2nd on the track B
of theMDXchallenge.mdx_q,mdx_extra_q: quantized version of the previous models. Smaller download and storage
but quality can be slightly worse.SIG: whereSIGis a single model from themodel zoo.The--two-stems=vocalsoption allows to separate vocals from the rest (e.g. karaoke mode).vocalscan be changed into any source in the selected model.
This will mix the files after separating the mix fully, so this won't be faster or use less memory.The--shifts=SHIFTSperforms multiple predictions with random shifts (a.k.a theshift trick) of the input and average them. This makes predictionSHIFTStimes
slower. Don't use it unless you have a GPU.The--overlapoption controls the amount of overlap between prediction windows. Default is 0.25 (i.e. 25%) which is probably fine.
It can probably be reduced to 0.1 to improve a bit speed.The-jflag allow to specify a number of parallel jobs (e.g.demucs -j 2 myfile.mp3).
This will multiply by the same amount the RAM used so be careful!Memory requirements for GPU accelerationIf you want to use GPU acceleration, you will need at least 3GB of RAM on your GPU fordemucs. However, about 7GB of RAM will be required if you use the default arguments. Add--segment SEGMENTto change size of each split. If you only have 3GB memory, set SEGMENT to 8 (though quality may be worse if this argument is too small). Creating an environment variablePYTORCH_NO_CUDA_MEMORY_CACHING=1can help users with even smaller RAM such as 2GB (I separated a track that is 4 minutes but only 1.5GB is used), but this would make the separation slower.If you do not have enough memory on your GPU, simply add-d cputo the command line to use the CPU. With Demucs, processing time should be roughly equal to 1.5 times the duration of the track.Calling from another Python programThe main function provides aoptparameter as a simple API. You can just pass the parsed command line as this parameter:# Assume that your command is `demucs --mp3 --two-stems vocals -n mdx_extra "track with space.mp3"`# The following codes are same as the command above:importdemucs.separatedemucs.separate.main(["--mp3","--two-stems","vocals","-n","mdx_extra","track with space.mp3"])# Or like thisimportdemucs.separateimportshlexdemucs.separate.main(shlex.split('--mp3 --two-stems vocals -n mdx_extra "track with space.mp3"'))Training DemucsIf you want to train (Hybrid) Demucs, please follow thetraining doc.MDX Challenge reproductionIn order to reproduce the results from the Track A and Track B submissions, checkout theMDX Hybrid Demucs submission repo.How to cite@inproceedings{rouard2022hybrid,
  title={Hybrid Transformers for Music Source Separation},
  author={Rouard, Simon and Massa, Francisco and D{\'e}fossez, Alexandre},
  booktitle={ICASSP 23},
  year={2023}
}

@inproceedings{defossez2021hybrid,
  title={Hybrid Spectrogram and Waveform Source Separation},
  author={D{\'e}fossez, Alexandre},
  booktitle={Proceedings of the ISMIR 2021 Workshop on Music Source Separation},
  year={2021}
}LicenseDemucs is released under the MIT license as found in theLICENSEfile.