Skip to content

Commit

Permalink
Merge pull request facebookresearch#217 from facebookresearch/hybrid
Browse files Browse the repository at this point in the history
Hybrid Demucs
  • Loading branch information
adefossez authored Nov 10, 2021
2 parents 7445cbd + 44f5e0d commit 7b832a3
Show file tree
Hide file tree
Showing 1,512 changed files with 4,829 additions and 3,315 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@ jobs:
with:
python-version: 3.7

- uses: actions/cache@v2
with:
path: env
key: env-${{ hashFiles('**/requirements.txt') }}

- name: Install dependencies
run: |
python3 -m venv env
. env/bin/activate
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install '.[dev]'
- name: Run linter
run: |
. env/bin/activate
make linter
14 changes: 11 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ jobs:
with:
python-version: 3.7

- uses: actions/cache@v2
with:
path: env
key: env-${{ hashFiles('**/requirements.txt') }}

- name: Install dependencies
run: |
python3 -m venv env
. env/bin/activate
python -m pip install --upgrade pip
pip install .
pip install -r requirements.txt
- name: Run tests
- name: Run separation test
run: |
make tests
. env/bin/activate
make test_eval
20 changes: 11 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
__pycache__
*.egg-info
__pycache__
Session.vim
/build
/dist
Session.vim
*.log
/trash
/checkpoints
/logs
/models
/evals
/lab
/metadata
/notebooks
/outputs
/release
/release_models
/separated
/metadata
/tests
/trash
/misc
/mdx
92 changes: 65 additions & 27 deletions Demucs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
"id": "Be9yoh-ILfRr"
},
"source": [
"# [*Colab code for Demucs*](https://github.com/facebookresearch/demucs/)\n",
"# Hybrid Demucs\n",
"\n",
"Original version by marlluslustosa **https://github.com/marlluslustosa/demucs/blob/master/Demucs.ipynb**\n",
"\n",
"However, now things are much simpler with Demucs v2, so this might not be so useful. There is now a Colab version:\n",
"https://colab.research.google.com/drive/1jCegIzLIuqqcM85uVs3WCeAJiSoYq3oh?usp=sharing"
"Feel free to use the Colab version:\n",
"https://colab.research.google.com/drive/1dC9nVxk3V_VPjUADsnFu8EiT-xnU1tGH?usp=sharing"
]
},
{
Expand Down Expand Up @@ -40,48 +38,88 @@
},
"outputs": [],
"source": [
"!pip install demucs"
"!pip install -U demucs\n",
"# or for local development, if you have a clone of Demucs\n",
"# pip install -e ."
]
},
{
"cell_type": "markdown",
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab_type": "text",
"id": "Y1BdlzOQi3y7"
"colab": {},
"colab_type": "code",
"id": "5lYOzKKCKAbJ"
},
"outputs": [],
"source": [
"# You can use the `demucs` command line to separate tracks\n",
"!demucs test.mp3"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# You can also load directly the pretrained models,\n",
"# for instance for the MDX 2021 winning model of Track A:\n",
"from demucs import pretrained\n",
"model = pretrained.get_model('mdx')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Because `model` is a bag of 4 models, you cannot directly call it on your data,\n",
"# but the `apply_model` will know what to do of it.\n",
"import torch\n",
"from demucs.apply import apply_model\n",
"x = torch.randn(1, 2, 44100 * 10) # ten seconds of white noise for the demo\n",
"out = apply_model(model, x)[0] # shape is [S, C, T] with S the number of sources\n",
"\n",
"\n",
"---\n",
"\n",
"\n",
"# **Here begins the code for separating the audio source (model pretrained)**\n",
"###**- Upload your song to demucs/ folder and edit YOUR-SONG-PATH.mp3**\n",
"\n",
"\n",
"---\n",
"\n"
"# So let see, where is all the white noise content is going ?\n",
"for name, source in zip(model.sources, out):\n",
" print(name, source.std() / x.std())\n",
"# The outputs are quite weird to be fair, not what I would have expected."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "5lYOzKKCKAbJ"
},
"metadata": {},
"outputs": [],
"source": [
"!python3 -m demucs.separate test.mp3"
"# now let's take a single model from the bag, and let's test it on a pure cosine\n",
"freq = 440 # in Hz\n",
"sr = model.samplerate\n",
"t = torch.arange(10 * sr).float() / sr\n",
"x = torch.cos(2 * 3.1416 * freq * t).expand(1, 2, -1)\n",
"sub_model = model.models[3]\n",
"out = sub_model(x)[0]\n",
"\n",
"# Same question where does it go?\n",
"for name, source in zip(model.sources, out):\n",
" print(name, source.std() / x.std())\n",
" \n",
"# Well now it makes much more sense, all the energy is going\n",
"# in the `other` source.\n",
"# Feel free to try lower pitch (try 80 Hz) to see what happens !"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"# For training or more fun, refer to the Demucs README on our repo\n",
"# https://github.com/facebookresearch/demucs/tree/main/demucs"
]
}
],
"metadata": {
Expand All @@ -107,7 +145,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.8.8"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
15 changes: 11 additions & 4 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
include *.md
recursive-exclude env *
recursive-include conf *.yaml
include Makefile
include LICENSE
include setup.cfg
incude demucs.png
include demucs.png
include outputs.tar.gz
include test.mp3
include requirements.txt
recursive-include docs *.md
include requirements_minimal.txt
include mypy.ini
include demucs/py.typed
include demucs/remote/*.txt
include demucs/remote/*.yaml
27 changes: 19 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
default: tests

all: linter tests docs dist
all: linter tests

linter:
flake8 demucs
mypy demucs

tests: test_train test_eval

test_train: tests/musdb
_DORA_TEST_PATH=/tmp/demucs python3 -m dora run --clear \
dset.musdb=./tests/musdb dset.segment=4 dset.shift=2 epochs=2 model=demucs \
demucs.depth=2 demucs.channels=4 test.sdr=false misc.num_workers=0 test.workers=0 \
test.shifts=0

tests:
python3 -m demucs.separate -n demucs_unittest test.mp3
python3 -m demucs.separate -n demucs_unittest --mp3 test.mp3
test_eval:
python3 -m demucs -n demucs_unittest test.mp3
python3 -m demucs -n demucs_unittest --mp3 test.mp3

tests/musdb:
test -e tests || mkdir tests
python3 -c 'import musdb; musdb.DB("tests/tmp", download=True)'
musdbconvert tests/tmp tests/musdb

dist:
python3 setup.py sdist

clean:
rm -r dist build *.egg-info


.PHONY: linter tests dist
.PHONY: linter dist test_train test_eval
Loading

0 comments on commit 7b832a3

Please sign in to comment.