{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "b447e2c4", "metadata": {}, "outputs": [], "source": [ "import os\n", "import sys\n", "sys.path.insert(0, os.path.dirname(os.path.abspath(\"\")))" ] }, { "cell_type": "code", "execution_count": 2, "id": "c2fc0e7a", "metadata": {}, "outputs": [], "source": [ "import random\n", "from src.mel import Mel\n", "from PIL import ImageOps, Image\n", "from IPython.display import Audio\n", "from diffusers import DDPMPipeline\n", "from datasets import load_from_disk" ] }, { "cell_type": "code", "execution_count": 3, "id": "a3d45c36", "metadata": {}, "outputs": [], "source": [ "mel = Mel(x_res=64, y_res=64, hop_length=1024)" ] }, { "cell_type": "markdown", "id": "011fb5a1", "metadata": {}, "source": [ "### Run model inference to generate mel spectrogram" ] }, { "cell_type": "code", "execution_count": 4, "id": "b809fed5", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5b2ca925758841d2accaac8229f84b53", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/1000 [00:00" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "image = Image.fromarray(images[0][0])\n", "image" ] }, { "cell_type": "markdown", "id": "7230c280", "metadata": {}, "source": [ "### Transform mel spectrogram to audio" ] }, { "cell_type": "code", "execution_count": 5, "id": "5f8a149d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "audio = mel.image_to_audio(image)\n", "Audio(data=audio, rate=mel.get_sample_rate())" ] }, { "cell_type": "markdown", "id": "ef54cef3", "metadata": {}, "source": [ "### Compare results with random sample from training set" ] }, { "cell_type": "code", "execution_count": 7, "id": "269ee816", "metadata": {}, "outputs": [], "source": [ "ds = load_from_disk('../data-64')" ] }, { "cell_type": "code", "execution_count": 8, "id": "b9023846", "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAAAAAC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8M2Kmfiip272OWyRMEIy1TmhDuSSKY2F9YEUwPQitv5FSmFIUKY0NDkxJAR8smVHNZLaI/19cdsAhT20Japs2mJGhPIOkaRfXEHQAySZCmn5IYy6oidRS77HGdnsT3bkiAUO7ngFTbEPU3RUo51SidkI4E5mRyjPyJzY8PalRQzGmNQvgTAOTKeS8oFZY5xKYktohCMsDIVcqTpsK5+1rYqt6m7DJFJxkOO93Gbc6CFLQeqhz4taRUKfoxgMTeBXDSAqYBWNIvkHD2rZLPbkItLIlrGqmng8lB3crUhCs2BNKlfTOFinVoKjajF6nZOJtPRP13Shxu82Ieh6GEYH6/tcoRzMz+tH82ejnv2JZihFDM0Iz/fx91O8fC5DyP9MDJ3oBgxP2GEGJ2mNjlVesAIgUbgDjnG2S/zWJPgnqZUAktUJRxONSZubpIzwVDmkgkJgsa+GBNTzDEiQEUx6jHEgJ2PC4SYU7Y+gciL0XUIPntdso8KP355B/ink7IP6v7+T9M4v9OjPtjD15/uK/suxvP5nS/7+3HZDeejXe6+pMenHA+OWDrsQtAU4wV6kzooaxtWXkZS4ZOMl93l3JK26qFvshgkldu7qhe4anBFi070oi0Xvp96elLgPgQ1ffrlj3+4MPrF4N4Qqz/ru9MJm/vu8N//UL9Db9zt/m3c719O06H5cNxUx5vfv/nLL0/jw4keDvDTDt4w9+mjfQD4MM84z9XOoCOQEzwwOMX/eaXgM3uCLx+NeTzSI7xR0094vpv29TD8P9LNf/+ctgNuAAAAAElFTkSuQmCC\n", "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "image = random.choice(ds['train'])['image']\n", "image" ] }, { "cell_type": "code", "execution_count": 9, "id": "492e2334", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "audio = mel.image_to_audio(image)\n", "Audio(data=audio, rate=mel.get_sample_rate())" ] }, { "cell_type": "code", "execution_count": null, "id": "acf96aba", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "huggingface", "language": "python", "name": "huggingface" }, "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.9.13" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 5 }