Spaces:
Configuration error
Configuration error
File size: 4,288 Bytes
519d358 |
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 |
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "Be9yoh-ILfRr"
},
"source": [
"# Hybrid Demucs\n",
"\n",
"Feel free to use the Colab version:\n",
"https://colab.research.google.com/drive/1dC9nVxk3V_VPjUADsnFu8EiT-xnU1tGH?usp=sharing"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 139
},
"colab_type": "code",
"executionInfo": {
"elapsed": 12277,
"status": "ok",
"timestamp": 1583778134659,
"user": {
"displayName": "Marllus Lustosa",
"photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GgLl2RbW64ZyWz3Y8IBku0zhHCMnt7fz7fEl0LTdA=s64",
"userId": "14811735256675200480"
},
"user_tz": 180
},
"id": "kOjIPLlzhPfn",
"outputId": "c75f17ec-b576-4105-bc5b-c2ac9c1018a3"
},
"outputs": [],
"source": [
"!pip install -U demucs\n",
"# or for local development, if you have a clone of Demucs\n",
"# pip install -e ."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"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",
"# 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": {},
"outputs": [],
"source": [
"# 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": [
"# For training or more fun, refer to the Demucs README on our repo\n",
"# https://github.com/facebookresearch/demucs/tree/main/demucs"
]
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"authorship_tag": "ABX9TyM9xpVr1M86NRcjtQ7g9tCx",
"collapsed_sections": [],
"name": "Demucs.ipynb",
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
|