From f88e6259fa665b91a36ddac9ad7ddc08ccd4631b Mon Sep 17 00:00:00 2001 From: Eloi Moliner Juanpere <64018465+eloimoliner@users.noreply.github.com> Date: Thu, 20 Jan 2022 16:59:34 +0200 Subject: [PATCH] Created using Colaboratory --- colab/demo.ipynb | 257 ++++++++++++++++++++++++++++------------------- 1 file changed, 151 insertions(+), 106 deletions(-) diff --git a/colab/demo.ipynb b/colab/demo.ipynb index cc55d35..919e5f5 100644 --- a/colab/demo.ipynb +++ b/colab/demo.ipynb @@ -22,14 +22,14 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "dd70762d", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "dd70762d", - "outputId": "499681b1-46d6-4f21-b3b8-3a3348f6765b" + "outputId": "24457550-e127-4d73-db47-297147b68f09" }, "outputs": [ { @@ -37,12 +37,32 @@ "name": "stdout", "text": [ "Cloning into 'denoising-historical-recordings'...\n", - "remote: Enumerating objects: 177, done.\u001b[K\n", - "remote: Counting objects: 100% (177/177), done.\u001b[K\n", - "remote: Compressing objects: 100% (153/153), done.\u001b[K\n", - "remote: Total 177 (delta 63), reused 99 (delta 16), pack-reused 0\u001b[K\n", - "Receiving objects: 100% (177/177), 97.29 KiB | 4.86 MiB/s, done.\n", - "Resolving deltas: 100% (63/63), done.\n" + "remote: Enumerating objects: 181, done.\u001b[K\n", + "remote: Counting objects: 100% (181/181), done.\u001b[K\n", + "remote: Compressing objects: 100% (157/157), done.\u001b[K\n", + "remote: Total 181 (delta 64), reused 98 (delta 16), pack-reused 0\u001b[K\n", + "Receiving objects: 100% (181/181), 104.80 KiB | 17.47 MiB/s, done.\n", + "Resolving deltas: 100% (64/64), done.\n", + "--2022-01-20 14:40:36-- https://github.com/eloimoliner/denoising-historical-recordings/releases/download/v0.0/checkpoint.zip\n", + "Resolving github.com (github.com)... 140.82.112.3\n", + "Connecting to github.com (github.com)|140.82.112.3|:443... connected.\n", + "HTTP request sent, awaiting response... 302 Found\n", + "Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/401385223/354cec4e-d8be-4126-8b32-9e6509bca537?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220120%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220120T144036Z&X-Amz-Expires=300&X-Amz-Signature=1cf02e4ae397a518db9da71aad3dfc7dcb844c520bbfc49398ca6a54171ad637&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=401385223&response-content-disposition=attachment%3B%20filename%3Dcheckpoint.zip&response-content-type=application%2Foctet-stream [following]\n", + "--2022-01-20 14:40:36-- https://objects.githubusercontent.com/github-production-release-asset-2e65be/401385223/354cec4e-d8be-4126-8b32-9e6509bca537?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220120%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220120T144036Z&X-Amz-Expires=300&X-Amz-Signature=1cf02e4ae397a518db9da71aad3dfc7dcb844c520bbfc49398ca6a54171ad637&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=401385223&response-content-disposition=attachment%3B%20filename%3Dcheckpoint.zip&response-content-type=application%2Foctet-stream\n", + "Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.110.133, 185.199.108.133, 185.199.111.133, ...\n", + "Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.110.133|:443... connected.\n", + "HTTP request sent, awaiting response... 200 OK\n", + "Length: 264031940 (252M) [application/octet-stream]\n", + "Saving to: ‘checkpoint.zip’\n", + "\n", + "checkpoint.zip 100%[===================>] 251.80M 215MB/s in 1.2s \n", + "\n", + "2022-01-20 14:40:38 (215 MB/s) - ‘checkpoint.zip’ saved [264031940/264031940]\n", + "\n", + "Archive: checkpoint.zip\n", + " inflating: denoising-historical-recordings/experiments/trained_model/checkpoint \n", + " inflating: denoising-historical-recordings/experiments/trained_model/checkpoint.data-00000-of-00001 \n", + " inflating: denoising-historical-recordings/experiments/trained_model/checkpoint.index \n" ] } ], @@ -64,10 +84,10 @@ "base_uri": "https://localhost:8080/" }, "id": "HmHRpa5eloy2", - "outputId": "34af882d-8fb7-4b2a-dccd-50e328e0ab90" + "outputId": "8666da99-94e0-4ed2-afca-f9e31b37c84c" }, "id": "HmHRpa5eloy2", - "execution_count": 18, + "execution_count": 2, "outputs": [ { "output_type": "stream", @@ -93,18 +113,17 @@ { "cell_type": "code", "source": [ - "#install dependencies\n", - "! pip install hydra-core==0.11.3" + "" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "nmic9hVzmSj6", - "outputId": "c549f0d1-9e5c-4445-ecd4-702697535011" + "outputId": "4d1a91d8-e994-48d3-d27b-f3c0b933b60e" }, "id": "nmic9hVzmSj6", - "execution_count": 15, + "execution_count": 3, "outputs": [ { "output_type": "stream", @@ -112,15 +131,13 @@ "text": [ "Collecting hydra-core==0.11.3\n", " Downloading hydra_core-0.11.3-py3-none-any.whl (72 kB)\n", - "\u001b[?25l\r\u001b[K |████▌ | 10 kB 19.6 MB/s eta 0:00:01\r\u001b[K |█████████ | 20 kB 12.0 MB/s eta 0:00:01\r\u001b[K |█████████████▋ | 30 kB 8.9 MB/s eta 0:00:01\r\u001b[K |██████████████████▏ | 40 kB 7.9 MB/s eta 0:00:01\r\u001b[K |██████████████████████▊ | 51 kB 5.3 MB/s eta 0:00:01\r\u001b[K |███████████████████████████▎ | 61 kB 5.4 MB/s eta 0:00:01\r\u001b[K |███████████████████████████████▉| 71 kB 5.7 MB/s eta 0:00:01\r\u001b[K |████████████████████████████████| 72 kB 372 kB/s \n", + "\u001b[?25l\r\u001b[K |████▌ | 10 kB 34.0 MB/s eta 0:00:01\r\u001b[K |█████████ | 20 kB 38.2 MB/s eta 0:00:01\r\u001b[K |█████████████▋ | 30 kB 43.5 MB/s eta 0:00:01\r\u001b[K |██████████████████▏ | 40 kB 47.4 MB/s eta 0:00:01\r\u001b[K |██████████████████████▊ | 51 kB 33.6 MB/s eta 0:00:01\r\u001b[K |███████████████████████████▎ | 61 kB 36.8 MB/s eta 0:00:01\r\u001b[K |███████████████████████████████▉| 71 kB 27.7 MB/s eta 0:00:01\r\u001b[K |████████████████████████████████| 72 kB 649 kB/s \n", "\u001b[?25hCollecting omegaconf<1.5,>=1.4\n", " Downloading omegaconf-1.4.1-py3-none-any.whl (14 kB)\n", - "Requirement already satisfied: six in /usr/local/lib/python3.7/site-packages (from omegaconf<1.5,>=1.4->hydra-core==0.11.3) (1.15.0)\n", - "Collecting PyYAML\n", - " Downloading PyYAML-6.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (596 kB)\n", - "\u001b[K |████████████████████████████████| 596 kB 39.4 MB/s \n", - "\u001b[?25hInstalling collected packages: PyYAML, omegaconf, hydra-core\n", - "Successfully installed PyYAML-6.0 hydra-core-0.11.3 omegaconf-1.4.1\n" + "Requirement already satisfied: PyYAML in /usr/local/lib/python3.7/dist-packages (from omegaconf<1.5,>=1.4->hydra-core==0.11.3) (3.13)\n", + "Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from omegaconf<1.5,>=1.4->hydra-core==0.11.3) (1.15.0)\n", + "Installing collected packages: omegaconf, hydra-core\n", + "Successfully installed hydra-core-0.11.3 omegaconf-1.4.1\n" ] } ] @@ -128,6 +145,10 @@ { "cell_type": "code", "source": [ + "#install dependencies\n", + "! pip install hydra-core==0.11.3\n", + "\n", + "#All the code goes here\n", "import unet\n", "import tensorflow as tf\n", "import soundfile as sf\n", @@ -135,18 +156,7 @@ "from tqdm import tqdm\n", "import scipy.signal\n", "import hydra\n", - "import os" - ], - "metadata": { - "id": "TQBDTmO4mUBx" - }, - "id": "TQBDTmO4mUBx", - "execution_count": 17, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ + "import os\n", "#workaround to load hydra conf file\n", "import yaml\n", "from pathlib import Path\n", @@ -157,50 +167,15 @@ " __setattr__ = dict.__setitem__\n", " __delattr__ = dict.__delitem__\n", "args=dotdict(args)\n", - "unet_args=dotdict(args.unet)" - ], - "metadata": { - "id": "yMI9sIUYo9Lp" - }, - "id": "yMI9sIUYo9Lp", - "execution_count": 62, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ + "unet_args=dotdict(args.unet)\n", + "\n", "path_experiment=str(args.path_experiment)\n", "\n", "unet_model = unet.build_model_denoise(unet_args=unet_args)\n", "\n", "ckpt=os.path.join(\"/content/denoising-historical-recordings\",path_experiment, 'checkpoint')\n", - "unet_model.load_weights(ckpt)" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "cbdPyEpAp7s0", - "outputId": "63df20d2-1c00-41a5-c8fc-a6cdcfb57d08" - }, - "id": "cbdPyEpAp7s0", - "execution_count": 67, - "outputs": [ - { - "output_type": "execute_result", - "data": { - "text/plain": [ - "" - ] - }, - "metadata": {}, - "execution_count": 67 - } - ] - }, - { - "cell_type": "code", - "source": [ + "unet_model.load_weights(ckpt)\n", + "\n", "def do_stft(noisy):\n", " \n", " window_fn = tf.signal.hamming_window\n", @@ -225,18 +200,8 @@ "\n", " pred_cpx=data[...,0] + 1j * data[...,1]\n", " pred_time=tf.signal.inverse_stft(pred_cpx, win_size, hop_size, window_fn=inv_window_fn)\n", - " return pred_time\n" - ], - "metadata": { - "id": "iDJGN-1_taXR" - }, - "id": "iDJGN-1_taXR", - "execution_count": 79, - "outputs": [] - }, - { - "cell_type": "code", - "source": [ + " return pred_time\n", + "\n", "def denoise_audio(audio):\n", "\n", " data, samplerate = sf.read(audio)\n", @@ -322,10 +287,10 @@ " return denoised_data" ], "metadata": { - "id": "LcSmbzm_z8w9" + "id": "TQBDTmO4mUBx" }, - "id": "LcSmbzm_z8w9", - "execution_count": 72, + "id": "TQBDTmO4mUBx", + "execution_count": 4, "outputs": [] }, { @@ -351,22 +316,22 @@ } }, "base_uri": "https://localhost:8080/", - "height": 75 + "height": 72 }, "id": "50Kmdy6AtbhW", - "outputId": "31d357e7-5adb-45f4-a3fe-3bb11d05a5af" + "outputId": "2d05860c-536d-45f8-92b4-d2ba6f5a54c5" }, "id": "50Kmdy6AtbhW", - "execution_count": 75, + "execution_count": 5, "outputs": [ { "output_type": "display_data", "data": { "text/html": [ "\n", - " \n", - " \n", + " \n", " Upload widget is only available when the cell has been executed in the\n", " current browser session. Please rerun this cell to enable.\n", " \n", @@ -393,25 +358,21 @@ "for fn in uploaded.keys():\n", " print('Denoising uploaded file \"{name}\"'.format(\n", " name=fn))\n", - " denoise_data=denoise_audio(fn)" + " denoise_data=denoise_audio(fn)\n", + " basename=os.path.splitext(fn)[0]\n", + " wav_output_name=basename+\"_denoised\"+\".wav\"\n", + " sf.write(wav_output_name, denoise_data, 44100)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "0po6zpvrylc2", - "outputId": "0d2b228e-dad8-40f8-f10a-118ea115180d" + "outputId": "173f5355-2939-41fe-c702-591aa752fc7e" }, "id": "0po6zpvrylc2", - "execution_count": null, + "execution_count": 6, "outputs": [ - { - "output_type": "stream", - "name": "stderr", - "text": [ - "\r 0%| | 0/41 [00:00" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "application/javascript": [ + "download(\"download_3e3ca242-937f-408e-a16c-4aa5bb2b9e50\", \"Carmen-Habanera_(Love_is_Like_a_Woo_-_Marguerite_D'Alvarez_noisy_input_denoised.wav\", 17961334)" + ], + "text/plain": [ + "" + ] + }, + "metadata": {} + } + ] + }, { "cell_type": "code", "source": [ "" ], "metadata": { - "id": "3tEshWBezYvf" + "id": "v_FuSJ4J-WO-" }, - "id": "3tEshWBezYvf", + "id": "v_FuSJ4J-WO-", "execution_count": null, "outputs": [] } @@ -464,7 +508,8 @@ "name": "demo.ipynb", "provenance": [], "include_colab_link": true - } + }, + "accelerator": "GPU" }, "nbformat": 4, "nbformat_minor": 5