{"id":17618163,"url":"https://github.com/kinwaicheuk/demucs_lightning","last_synced_at":"2025-04-19T13:49:28.364Z","repository":{"id":38877471,"uuid":"485183018","full_name":"KinWaiCheuk/demucs_lightning","owner":"KinWaiCheuk","description":"Demucs Lightning: A PyTorch lightning version of Demucs with Hydra and Tensorboard features","archived":false,"fork":false,"pushed_at":"2023-05-03T06:28:50.000Z","size":206,"stargazers_count":84,"open_issues_count":4,"forks_count":10,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-19T05:13:16.992Z","etag":null,"topics":["deep-learning","machine-learning","music-information-retrieval","source-separation"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KinWaiCheuk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-25T01:18:14.000Z","updated_at":"2025-01-30T19:17:03.000Z","dependencies_parsed_at":"2024-10-23T02:19:18.042Z","dependency_job_id":"1bed8ef9-0a6d-471e-8c2b-71a7ec52e93c","html_url":"https://github.com/KinWaiCheuk/demucs_lightning","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KinWaiCheuk%2Fdemucs_lightning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KinWaiCheuk%2Fdemucs_lightning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KinWaiCheuk%2Fdemucs_lightning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KinWaiCheuk%2Fdemucs_lightning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KinWaiCheuk","download_url":"https://codeload.github.com/KinWaiCheuk/demucs_lightning/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249707256,"owners_count":21313800,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","machine-learning","music-information-retrieval","source-separation"],"created_at":"2024-10-22T19:26:45.174Z","updated_at":"2025-04-19T13:49:28.345Z","avatar_url":"https://github.com/KinWaiCheuk.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Demucs lightning\n\n1. [Introduction](#Introduction)\n1. [Requirement](#Requirement)\n1. [Training](#Training)\n    1. [Demucs](#Demucs)\n    1. [HDemucs](#HDemucs)\n1. [Resume from Checkpoints](#Resume-from-Checkpoints)\n1. [Training with a less powerful GPU](#Training-with-a-less-powerful-GPU)\n1. [Testing pretrained model](#Testing-pretrained-model)\n1. [Half-Precision Training](#Half-Precision-Training)\n1. [Default settings](#Default-settings)\n1. [Inferencing](#Inferencing)\n1. [Development](#Development)\n\n\n## Introduction\n```\ndemucs_lightning\n├──conf\n│     ├─train_test_config.yaml\n│     ├─infer_config.yaml\n│     │\n│\n├──demucs\n│     ├─demucs.py\n│     ├─hdemucs.py\n│     ├─other custome modules\n│\n├──requirements.txt\n├──train.py\n├──test.py\n├──inference.py\n│   \n```\n\nThere are 2 major released version of Demucs. \n* Demucs (v2) used waveform as domain. \n* Hybrid Demucs (v3) is featuring hybrid source separation. \n\nYou can find their model structure in \n`demucs.py` and `hdemucs.py` from demucs folder.\\\nFor the official information of Demucs, you can visit [facebookresearch/demucs](https://github.com/facebookresearch/demucs)\n\nDemucs is trained by [MusdbHQ](https://sigsep.github.io/datasets/musdb.html). This repo uses `AudioLoader` to get MusdbHQ dataset .\\\nFor more information of Audioloader, you can visit [KinWaiCheuk/AudioLoader](https://github.com/KinWaiCheuk/AudioLoader).\n\nOr else you can download MusdbHQ dataset manually from [zenodo](https://zenodo.org/record/3338373#.YoEmSC8RpQI).\n\n## Requirement\n`Python==3.8.10` and `ffmpeg` is required to run this repo.\n\nIf `ffmpeg` is not installed on your machine, you can install it via `apt install ffmpeg`\n\nYou can install all required libraries at once via\n``` bash\npip install -r requirements.txt\n```\n\n## Logging\n\nTensorBoard logging is used by default. If you want to use the\nWandbLogger instead (recommended!), either edit `logger` in\n`conf/train_test_config.yaml` or postpend `logger=wandb` to all\nyour commands.\n\n## Training\nIf it is your first time running the repo, you can use the argument `download=True` to automatically download and setup the `musdb18hq` dataset. Otherwise, you can omit this  argument.\n\n### Demucs\nIt requires `16,885 MB` of GPU memory. If you do not have enough GPU memory, please read [this section](#Training-with-a-less-powerful-GPU).\n\n```bash\npython train.py devices=[0] model=Demucs download=True\n```\n\n### HDemucs\nIt requires `19,199 MB` of GPU memory.\n```bash\npython train.py devices=[0] model=HDemucs download=True\n```\n\n## Resume from Checkpoints\nIt is possible to continue training from an existing checkpoint by passing the `resume_checkpoint` argument. By default, hydra saves all the checkpoints at `'outputs/YYYY-MM-DD/HH-MM-SS/XXX_experiment_epoch=XXX_augmentation=XXX/version_1/checkpoints/XXX.ckpt'`. For example, if you have a checkpoint trained with 32-bit precision for 100 epochs already via the following command:\n\n```bash\npython train.py devices=[0] trainer.precision=32 epochs=100\n```\n\nAnd now you want to train for 50 epochs more, then you can use the following CLI command:\n\n```bash\npython train.py devices=[0] trainer.precision=16 epochs=150 resume_checkpoint='outputs/2022-05-24/21-20-17/Demucs_experiment_epoch=360_augmentation=True/version_1/checkpoints/e=123-TRAIN_loss=0.08.ckpt'\n```\n\nYou can always move you checkpoints to a better place to shorten the path name.\n\n## Training with a less powerful GPU\nIt is possible to reduce the GPU memory required to train the models by using the following tricks. But it might affect the model performance.\n### Reduce Batch Size\nYou can reduce the batch size to `2`. By doing so, it only requires `10,851 MB` of GPU memory.\n```bash\npython train.py batch_size=2 augment.remix.group_size=2 model=Demucs\n```\n\n### Disable Augmentation \nYou can futher reduce the batch size to `1` if data augmentation is disabled. By doing so, it only requires `7,703 MB` of GPU memory.\n```bash\npython train.py batch_size=1 data_augmentation=False model=Demucs\n```\n\n\n### Reduce Audio Segment Length\nYou can reduce the audio segment length to only `6`. By doing so, it only requires `6,175 MB` of GPU memory.\n```bash\npython train.py batch_size=1 data_augmentation=False segment=6 model=Demucs\n```\n\n## Testing pretrained model\nYou can use `test.py` to evaluate the pretrained model directly by using an existing checkpoint. You can give the checkpoint path via `resume_checkpoint` argument.\n\n```bash\npython test.py resume_checkpoint='outputs/2022-05-24/21-20-17/Demucs_experiment_epoch=360_augmentation=True/version_1/checkpoints/e=123-TRAIN_loss=0.08.ckpt'\n```\n\n## Half-Precision Training\nBy default, pytorch lightning uses 32-bit precision for training. To use 16-bit precision (half-precision), you can specify `trainer.precision`:\n\n```bash\npython train.py trainer.precision=16\n```\n\nDouble-precision is also supported by specifying `trainer.precision=64`.\n\n\n\n## Default settings \nThe full list of arguments and their default values can be found in `conf/config.yaml`.\n\n__devices__: Select which GPU to use. If you have multiple GPUs on your machine and you want to use GPU:2, you can set `devices=[2]`. If you want to use DDP (multi-GPU training), you can set `devices=2`, it will automatically use the first two GPUs avaliable in your machine. If you want to use GPU:0, GPU:2, and GPU:3 for training, you can set `devices=[0,2,3]`.\n\n__download__: When set to `True`, it will automatically download and setup the dataset. Default as `False`\n\n__data_root__: Select the location of your dataset. If `download=True`, it will become the directory that the dataset is going to be downloaded to. Default as `'./musdb18hq'`\n\n__model__: Select which version of demucs to use. Default model of this repo is Hybrid Demucs (v3). You can switch to Demucs (v2) by setting the `model=Demucs`.\n\n__samplerate__: The sampling rate for the audio. Default as `44100`.\n\n__epochs__: The number of epochs to train the model. Default as `360`.\n\n__optim.lr__: Learning rate of the optimizer. Default as `3e-4`.\n\n\n## Inferencing\nYou are able to apply your trained model weight on your own audio file by using `inference.py`. Some nesscesary argument are the following:\n\n* `checkpoint` refers to the path of trained model weight checkpoint file\n* `infer_audio_folder_path` refers to the path of your audio folder where has all the audios inside\n* `infer_audio_ext` refer to the type of your audio. Default value is `'wav'`\n\n```bash\npython inference.py infer_audio_folder_path='../../infer_audio' checkpoint='outputs/2022-05-24/21-20-17/Demucs_experiment_epoch=360_augmentation=True/version_1/checkpoints/e=123-TRAIN_loss=0.08.ckpt'\n```\n\nBy default, hydra saves all the seperated audio in the `outputs` folder.\n## Development\n\nIf you are a developer on this repo, please run:\n\n```\npre-commit install\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkinwaicheuk%2Fdemucs_lightning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkinwaicheuk%2Fdemucs_lightning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkinwaicheuk%2Fdemucs_lightning/lists"}