Music Source Separation Training

repository·main·Indexed 23 days ago

https://github.com/zfturbo/music-source-separation-training

A universal training framework for music source separation models. It provides modular code to train, validate, and run inference on various architectures including MDX, Demucs, RoFormers (Band Split and Mel-Band), BSMamba2, Conformer, and others. The framework supports multiple dataset organization types (MUSDB, stem-based, CSV mapping, and class-balanced) and includes tools for audio augmentations and multi-GPU training via Distributed Data Parallel.

Tokens
18.9K
Snippets
21
Records
35
Agent score
81%

What's inside music-source-separation-training

  1. Project file structure and component overview

    main

    The repository is organized as follows:

    • configs/config_*.yaml: Configuration files for model hyperparameters and training settings.
    • models/*: Implementation of available models for training and inference.
    • train.py: Main entry point for single-GPU training.
    • train_ddp.py: Entry point for Multi-GPU training (Distributed Data Parallel). Use this for 2 or more GPUs for faster training.
    • inference.py: Script to process a folder of music files for source separation.
    • dataset.py: Logic for creating training samples.
    • valid.py: Validation logic and metric calculation.
    • utils.py: Common utility functions.
    • ensemble.py: Script to combine results from different models to improve separation quality.
    • gui-wx.py: Graphical user interface for the code.
  2. Best practices for audio ensembling

    main

    When using ensemble.py, consider the following guidelines to optimize the Signal-to-Distortion Ratio (SDR):

    • Model Quality: It is best to ensemble models of equal quality. If one model is significantly worse than the others, ensembling it will reduce the overall quality of the output.
    • Method Selection: In experimental testing, avg_wave consistently performs better than or equal to other methods in terms of SDR score.
    • Aggressiveness Control: If your models are too aggressive, use min_fft to perform a more conservative ensemble and reduce their influence.
  3. Use Class-Balanced Aligned Datasets (Type 7)

    main

    Type 7 is designed to reduce class frequency bias and improve the learning of rare instruments in sparse multi-instrument datasets.

    How it works:

    1. A random instrument (class) is selected.
    2. A random track containing that instrument is chosen.
    3. An aligned chunk is loaded from that track.
    4. The dataset returns the active_stem_ids (indices of instruments actually present).

    Class Frequency Filtering: Instruments that appear in more than max_class_presence_ratio (default: 0.4) of the total tracks are excluded to prevent dominant classes (like vocals) from overwhelming the training.

    Returned Values:

    • Stems tensor
    • Mixture tensor (from mixture.wav if available, otherwise sum of stems)
    • active_stem_ids: indices of instruments present in the current sample.
    --- Song 1:
    ------ flute.wav
    ------ violin.wav
    ------ mixture.wav
  4. Use admin_test.py for bulk configuration testing

    main

    The admin_test.py script is designed for bulk testing of all configurations and models. Unlike tests.py, it does not require you to specify model weights or datasets manually.

    By default, it performs validation and inference. You can modify the configurations and parameters being tested by editing the MODEL_CONFIGS variable within the script. This is useful for ensuring that multiple model/config combinations are valid before committing to full-scale training or detailed testing.

  5. Organize datasets by stem name (Type 2)

    main

    In this structure, each folder represents a single instrument (stem). The folder contains all audio files belonging to that specific stem.

    Structure:

    --- vocals:
    ------ vocals_1.wav
    ------ vocals_2.wav
    --- bass:
    ------ bass_1.wav
    ------ bass_2.wav
    --- vocals:
    ------ vocals_1.wav
    ------ vocals_2.wav
    ------ vocals_3.wav
    ------ vocals_4.wav
    ------ ...
    --- bass:
    ------ bass_1.wav
    ------ bass_2.wav
    ------ bass_3.wav
    ------ bass_4.wav
    ------ ...
  6. Organize datasets using the MUSDB structure (Type 1)

    main

    The MUSDB structure is used when each song is contained within its own folder. Each folder must contain all required stems as individual audio files (e.g., .wav or .flac).

    Structure:

    --- Song 1:
    ------ vocals.wav
    ------ bass.wav
    ------ drums.wav
    ------ other.wav
    --- Song 2:
    ------ vocals.wav
    ------ bass.wav
    ------ drums.wav
    ------ other.wav
  7. Use MUSDB Aligned with Explicit Mixture (Type 6)

    main

    Type 6 is an extension of Type 4 designed for scenarios where the mixture is treated as a separate signal (e.g., for distillation or consistency losses) rather than just the sum of stems.

    Key Features:

    • Stems are loaded aligned from the same song position.
    • If a mixture.wav file is present in the song folder, it is loaded explicitly.
    • If mixture.wav is missing, the mixture is computed as the sum of the stems.
    • Supports precomputed random chunks.

    Recommended Structure:

    --- Song 1:
    ------ vocals.wav
    ------ bass.wav
    ------ drums.wav
    ------ other.wav
    ------ mixture.wav
  8. Configure the validation dataset structure

    main

    Regardless of the type used for training, the validation dataset must follow the Type 1 (MUSDB) structure and must include a mixture.wav file for every song. The mixture.wav should be the sum of all stems for that song.

    Required Structure:

    --- Song 1:
    ------ vocals.wav  
    ------ bass.wav  
    ------ drums.wav  
    ------ other.wav  
    ------ mixture.wav
    --- Song 2:
    ------ vocals.wav  
    ------ bass.wav  
    ------ drums.wav  
    ------ other.wav  
    ------ mixture.wav
    --- Song 1:
    ------ vocals.wav  
    ------ bass.wav  
    ------ drums.wav  
    ------ other.wav  
    ------ mixture.wav
    --- Song 2:
    ------ vocals.wav  
    ------ bass.wav  
    ------ drums.wav  
    ------ other.wav  
    ------ mixture.wav
    --- Song 3:
    ...........