Last active
April 18, 2024 14:49
-
-
Save schollz/1741ac03a19750fadef7e5cd0add0f29 to your computer and use it in GitHub Desktop.
aimovie.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "nbformat": 4, | |
| "nbformat_minor": 0, | |
| "metadata": { | |
| "colab": { | |
| "name": "aimovie.ipynb", | |
| "provenance": [], | |
| "collapsed_sections": [], | |
| "authorship_tag": "ABX9TyMuRxejHQKRMZaBDHNJeLVM", | |
| "include_colab_link": true | |
| }, | |
| "kernelspec": { | |
| "name": "python3", | |
| "display_name": "Python 3" | |
| }, | |
| "language_info": { | |
| "name": "python" | |
| }, | |
| "accelerator": "GPU" | |
| }, | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "view-in-github", | |
| "colab_type": "text" | |
| }, | |
| "source": [ | |
| "<a href=\"https://colab.research.google.com/gist/schollz/1741ac03a19750fadef7e5cd0add0f29/aimovie.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "S4IkNuc_Z5wx", | |
| "outputId": "53dd9078-dfae-4c13-91f3-04b586efabd6" | |
| }, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (4.63.0)\n", | |
| "Requirement already satisfied: librosa in /usr/local/lib/python3.7/dist-packages (0.8.1)\n", | |
| "Requirement already satisfied: moviepy in /usr/local/lib/python3.7/dist-packages (0.2.3.5)\n", | |
| "Requirement already satisfied: torch in /usr/local/lib/python3.7/dist-packages (1.10.0+cu111)\n", | |
| "Collecting scipy==1.1.0\n", | |
| " Downloading scipy-1.1.0-cp37-cp37m-manylinux1_x86_64.whl (31.2 MB)\n", | |
| "\u001b[K |████████████████████████████████| 31.2 MB 22.8 MB/s \n", | |
| "\u001b[?25hCollecting pytorch_pretrained_biggan\n", | |
| " Downloading pytorch_pretrained_biggan-0.1.1-py3-none-any.whl (27 kB)\n", | |
| "Requirement already satisfied: numpy>=1.8.2 in /usr/local/lib/python3.7/dist-packages (from scipy==1.1.0) (1.21.5)\n", | |
| "Requirement already satisfied: audioread>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from librosa) (2.1.9)\n", | |
| "Requirement already satisfied: numba>=0.43.0 in /usr/local/lib/python3.7/dist-packages (from librosa) (0.51.2)\n", | |
| "Requirement already satisfied: pooch>=1.0 in /usr/local/lib/python3.7/dist-packages (from librosa) (1.6.0)\n", | |
| "Requirement already satisfied: soundfile>=0.10.2 in /usr/local/lib/python3.7/dist-packages (from librosa) (0.10.3.post1)\n", | |
| "Requirement already satisfied: joblib>=0.14 in /usr/local/lib/python3.7/dist-packages (from librosa) (1.1.0)\n", | |
| "Requirement already satisfied: scikit-learn!=0.19.0,>=0.14.0 in /usr/local/lib/python3.7/dist-packages (from librosa) (1.0.2)\n", | |
| "Requirement already satisfied: decorator>=3.0.0 in /usr/local/lib/python3.7/dist-packages (from librosa) (4.4.2)\n", | |
| "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.7/dist-packages (from librosa) (21.3)\n", | |
| "Requirement already satisfied: resampy>=0.2.2 in /usr/local/lib/python3.7/dist-packages (from librosa) (0.2.2)\n", | |
| "Requirement already satisfied: llvmlite<0.35,>=0.34.0.dev0 in /usr/local/lib/python3.7/dist-packages (from numba>=0.43.0->librosa) (0.34.0)\n", | |
| "Requirement already satisfied: setuptools in /usr/local/lib/python3.7/dist-packages (from numba>=0.43.0->librosa) (57.4.0)\n", | |
| "Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /usr/local/lib/python3.7/dist-packages (from packaging>=20.0->librosa) (3.0.7)\n", | |
| "Requirement already satisfied: appdirs>=1.3.0 in /usr/local/lib/python3.7/dist-packages (from pooch>=1.0->librosa) (1.4.4)\n", | |
| "Requirement already satisfied: requests>=2.19.0 in /usr/local/lib/python3.7/dist-packages (from pooch>=1.0->librosa) (2.23.0)\n", | |
| "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2.19.0->pooch>=1.0->librosa) (2.10)\n", | |
| "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests>=2.19.0->pooch>=1.0->librosa) (1.24.3)\n", | |
| "Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests>=2.19.0->pooch>=1.0->librosa) (3.0.4)\n", | |
| "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests>=2.19.0->pooch>=1.0->librosa) (2021.10.8)\n", | |
| "Requirement already satisfied: six>=1.3 in /usr/local/lib/python3.7/dist-packages (from resampy>=0.2.2->librosa) (1.15.0)\n", | |
| "Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-learn!=0.19.0,>=0.14.0->librosa) (3.1.0)\n", | |
| "Requirement already satisfied: cffi>=1.0 in /usr/local/lib/python3.7/dist-packages (from soundfile>=0.10.2->librosa) (1.15.0)\n", | |
| "Requirement already satisfied: pycparser in /usr/local/lib/python3.7/dist-packages (from cffi>=1.0->soundfile>=0.10.2->librosa) (2.21)\n", | |
| "Requirement already satisfied: imageio<3.0,>=2.1.2 in /usr/local/lib/python3.7/dist-packages (from moviepy) (2.4.1)\n", | |
| "Requirement already satisfied: pillow in /usr/local/lib/python3.7/dist-packages (from imageio<3.0,>=2.1.2->moviepy) (7.1.2)\n", | |
| "Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from torch) (3.10.0.2)\n", | |
| "Collecting boto3\n", | |
| " Downloading boto3-1.21.22-py3-none-any.whl (132 kB)\n", | |
| "\u001b[K |████████████████████████████████| 132 kB 27.8 MB/s \n", | |
| "\u001b[?25hCollecting jmespath<2.0.0,>=0.7.1\n", | |
| " Downloading jmespath-1.0.0-py3-none-any.whl (23 kB)\n", | |
| "Collecting botocore<1.25.0,>=1.24.22\n", | |
| " Downloading botocore-1.24.22-py3-none-any.whl (8.6 MB)\n", | |
| "\u001b[K |████████████████████████████████| 8.6 MB 19.1 MB/s \n", | |
| "\u001b[?25hCollecting s3transfer<0.6.0,>=0.5.0\n", | |
| " Downloading s3transfer-0.5.2-py3-none-any.whl (79 kB)\n", | |
| "\u001b[K |████████████████████████████████| 79 kB 3.6 MB/s \n", | |
| "\u001b[?25hCollecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1\n", | |
| " Downloading urllib3-1.25.11-py2.py3-none-any.whl (127 kB)\n", | |
| "\u001b[K |████████████████████████████████| 127 kB 33.5 MB/s \n", | |
| "\u001b[?25hRequirement already satisfied: python-dateutil<3.0.0,>=2.1 in /usr/local/lib/python3.7/dist-packages (from botocore<1.25.0,>=1.24.22->boto3->pytorch_pretrained_biggan) (2.8.2)\n", | |
| "Installing collected packages: urllib3, jmespath, botocore, scipy, s3transfer, boto3, pytorch-pretrained-biggan\n", | |
| " Attempting uninstall: urllib3\n", | |
| " Found existing installation: urllib3 1.24.3\n", | |
| " Uninstalling urllib3-1.24.3:\n", | |
| " Successfully uninstalled urllib3-1.24.3\n", | |
| " Attempting uninstall: scipy\n", | |
| " Found existing installation: scipy 1.4.1\n", | |
| " Uninstalling scipy-1.4.1:\n", | |
| " Successfully uninstalled scipy-1.4.1\n", | |
| "\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", | |
| "pymc3 3.11.4 requires scipy>=1.2.0, but you have scipy 1.1.0 which is incompatible.\n", | |
| "plotnine 0.6.0 requires scipy>=1.2.0, but you have scipy 1.1.0 which is incompatible.\n", | |
| "jax 0.3.1 requires scipy>=1.2.1, but you have scipy 1.1.0 which is incompatible.\n", | |
| "datascience 0.10.6 requires folium==0.2.1, but you have folium 0.8.3 which is incompatible.\n", | |
| "albumentations 0.1.12 requires imgaug<0.2.7,>=0.2.5, but you have imgaug 0.2.9 which is incompatible.\u001b[0m\n", | |
| "Successfully installed boto3-1.21.22 botocore-1.24.22 jmespath-1.0.0 pytorch-pretrained-biggan-0.1.1 s3transfer-0.5.2 scipy-1.1.0 urllib3-1.25.11\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "pip install tqdm librosa moviepy torch scipy==1.1.0 pytorch_pretrained_biggan" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "import librosa\n", | |
| "import argparse\n", | |
| "import numpy as np\n", | |
| "import moviepy.editor as mpy\n", | |
| "import random\n", | |
| "import torch\n", | |
| "from scipy.misc import toimage\n", | |
| "from tqdm import tqdm\n", | |
| "from pytorch_pretrained_biggan import (BigGAN, one_hot_from_names, truncated_noise_sample,\n", | |
| " save_as_images, display_in_terminal)\n", | |
| "\n" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "Wbx5M7-7aJuz", | |
| "outputId": "2c8a5453-df40-45ab-f64c-05661e30e21d" | |
| }, | |
| "execution_count": 2, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "Imageio: 'ffmpeg-linux64-v3.3.1' was not found on your computer; downloading it now.\n", | |
| "Try 1. Download from https://github.com/imageio/imageio-binaries/raw/master/ffmpeg/ffmpeg-linux64-v3.3.1 (43.8 MB)\n", | |
| "Downloading: 8192/45929032 bytes (0.0%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b1073152/45929032 bytes (2.3%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b3194880/45929032 bytes (7.0%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b4571136/45929032 bytes (10.0%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b5906432/45929032 bytes (12.9%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b7798784/45929032 bytes (17.0%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b9682944/45929032 bytes (21.1%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b11550720/45929032 bytes (25.1%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b12730368/45929032 bytes (27.7%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b14409728/45929032 bytes (31.4%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b16572416/45929032 bytes (36.1%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b18341888/45929032 bytes (39.9%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b19963904/45929032 bytes (43.5%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b22257664/45929032 bytes (48.5%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b24051712/45929032 bytes (52.4%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b25296896/45929032 bytes (55.1%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b27385856/45929032 bytes (59.6%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b29253632/45929032 bytes (63.7%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b30949376/45929032 bytes (67.4%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b32219136/45929032 bytes (70.1%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b34045952/45929032 bytes (74.1%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b35979264/45929032 bytes (78.3%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b37421056/45929032 bytes (81.5%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b39256064/45929032 bytes (85.5%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b41009152/45929032 bytes (89.3%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b43319296/45929032 bytes (94.3%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b45023232/45929032 bytes (98.0%)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b45929032/45929032 bytes (100.0%)\n", | |
| " Done\n", | |
| "File saved as /root/.imageio/ffmpeg/ffmpeg-linux64-v3.3.1.\n" | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "from google.colab import files\n", | |
| "\n", | |
| "uploaded = files.upload()\n", | |
| "\n", | |
| "for fn in uploaded.keys():\n", | |
| " print('User uploaded file \"{name}\" with length {length} bytes'.format(\n", | |
| " name=fn, length=len(uploaded[fn])))\n", | |
| " " | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "resources": { | |
| "http://localhost:8080/nbextensions/google.colab/files.js": { | |
| "data": "Ly8gQ29weXJpZ2h0IDIwMTcgR29vZ2xlIExMQwovLwovLyBMaWNlbnNlZCB1bmRlciB0aGUgQXBhY2hlIExpY2Vuc2UsIFZlcnNpb24gMi4wICh0aGUgIkxpY2Vuc2UiKTsKLy8geW91IG1heSBub3QgdXNlIHRoaXMgZmlsZSBleGNlcHQgaW4gY29tcGxpYW5jZSB3aXRoIHRoZSBMaWNlbnNlLgovLyBZb3UgbWF5IG9idGFpbiBhIGNvcHkgb2YgdGhlIExpY2Vuc2UgYXQKLy8KLy8gICAgICBodHRwOi8vd3d3LmFwYWNoZS5vcmcvbGljZW5zZXMvTElDRU5TRS0yLjAKLy8KLy8gVW5sZXNzIHJlcXVpcmVkIGJ5IGFwcGxpY2FibGUgbGF3IG9yIGFncmVlZCB0byBpbiB3cml0aW5nLCBzb2Z0d2FyZQovLyBkaXN0cmlidXRlZCB1bmRlciB0aGUgTGljZW5zZSBpcyBkaXN0cmlidXRlZCBvbiBhbiAiQVMgSVMiIEJBU0lTLAovLyBXSVRIT1VUIFdBUlJBTlRJRVMgT1IgQ09ORElUSU9OUyBPRiBBTlkgS0lORCwgZWl0aGVyIGV4cHJlc3Mgb3IgaW1wbGllZC4KLy8gU2VlIHRoZSBMaWNlbnNlIGZvciB0aGUgc3BlY2lmaWMgbGFuZ3VhZ2UgZ292ZXJuaW5nIHBlcm1pc3Npb25zIGFuZAovLyBsaW1pdGF0aW9ucyB1bmRlciB0aGUgTGljZW5zZS4KCi8qKgogKiBAZmlsZW92ZXJ2aWV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ZW5kJywKICAgICAgICAgIGZpbGU6IGZpbGUubmFtZSwKICAgICAgICAgIGRhdGE6IGJhc2U2NCwKICAgICAgICB9LAogICAgICB9OwoKICAgICAgbGV0IHBlcmNlbnREb25lID0gZmlsZURhdGEuYnl0ZUxlbmd0aCA9PT0gMCA/CiAgICAgICAgICAxMDAgOgogICAgICAgICAgTWF0aC5yb3VuZCgocG9zaXRpb24gLyBmaWxlRGF0YS5ieXRlTGVuZ3RoKSAqIDEwMCk7CiAgICAgIHBlcmNlbnQudGV4dENvbnRlbnQgPSBgJHtwZXJjZW50RG9uZX0lIGRvbmVgOwoKICAgIH0gd2hpbGUgKHBvc2l0aW9uIDwgZmlsZURhdGEuYnl0ZUxlbmd0aCk7CiAgfQoKICAvLyBBbGwgZG9uZS4KICB5aWVsZCB7CiAgICByZXNwb25zZTogewogICAgICBhY3Rpb246ICdjb21wbGV0ZScsCiAgICB9CiAgfTsKfQoKc2NvcGUuZ29vZ2xlID0gc2NvcGUuZ29vZ2xlIHx8IHt9OwpzY29wZS5nb29nbGUuY29sYWIgPSBzY29wZS5nb29nbGUuY29sYWIgfHwge307CnNjb3BlLmdvb2dsZS5jb2xhYi5fZmlsZXMgPSB7CiAgX3VwbG9hZEZpbGVzLAogIF91cGxvYWRGaWxlc0NvbnRpbnVlLAp9Owp9KShzZWxmKTsK", | |
| "ok": true, | |
| "headers": [ | |
| [ | |
| "content-type", | |
| "application/javascript" | |
| ] | |
| ], | |
| "status": 200, | |
| "status_text": "OK" | |
| } | |
| }, | |
| "base_uri": "https://localhost:8080/", | |
| "height": 92 | |
| }, | |
| "id": "T9jpnFY9ate5", | |
| "outputId": "2e6d390c-be0b-416f-e432-f46f5f691c93" | |
| }, | |
| "execution_count": 3, | |
| "outputs": [ | |
| { | |
| "output_type": "display_data", | |
| "data": { | |
| "text/plain": [ | |
| "<IPython.core.display.HTML object>" | |
| ], | |
| "text/html": [ | |
| "\n", | |
| " <input type=\"file\" id=\"files-54ce7932-a622-43a0-8af2-e0c0db9686f0\" name=\"files[]\" multiple disabled\n", | |
| " style=\"border:none\" />\n", | |
| " <output id=\"result-54ce7932-a622-43a0-8af2-e0c0db9686f0\">\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", | |
| " </output>\n", | |
| " <script src=\"/nbextensions/google.colab/files.js\"></script> " | |
| ] | |
| }, | |
| "metadata": {} | |
| }, | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "Saving 1.mp3 to 1.mp3\n", | |
| "User uploaded file \"1.mp3\" with length 640749 bytes\n" | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "with open('/tmp/1.mp3', 'wb') as writefile:\n", | |
| " writefile.write(uploaded[\"1.mp3\"])\n", | |
| "\n", | |
| "y, sr = librosa.load('/tmp/1.mp3')\n", | |
| "\n", | |
| "# set model name based on resolution\n", | |
| "model_name = \"biggan-deep-256\" # -128, -256, or -512\n", | |
| "\n", | |
| "frame_length = 512\n", | |
| "\n", | |
| "# set pitch sensitivity\n", | |
| "set_pitch_sensitivity = 150\n", | |
| "pitch_sensitivity = (300 - set_pitch_sensitivity) * 512 / frame_length\n", | |
| "\n", | |
| "# set tempo sensitivity\n", | |
| "set_sensitivity = 0.25\n", | |
| "tempo_sensitivity = set_sensitivity * frame_length / 512\n", | |
| "\n", | |
| "# set depth\n", | |
| "depth = 1\n", | |
| "\n", | |
| "# set number of classes\n", | |
| "num_classes = 12\n", | |
| "\n", | |
| "# set sort_classes_by_power\n", | |
| "sort_classes_by_power = 0\n", | |
| "\n", | |
| "# set jitter\n", | |
| "jitter = 0.5\n", | |
| "\n", | |
| "# set truncation\n", | |
| "truncation = 1\n", | |
| "\n", | |
| "# set batch size\n", | |
| "batch_size = 30\n", | |
| "\n", | |
| "# set use_previous_classes\n", | |
| "use_previous_vectors = 0\n", | |
| "\n", | |
| "# set use_previous_vectors\n", | |
| "use_previous_classes = 0\n", | |
| "\n", | |
| "# set output name\n", | |
| "outname = '/tmp/1.mp4'\n", | |
| "\n", | |
| "smooth_factor = int(20 * 512 / frame_length)\n", | |
| "frame_lim = int(np.floor(len(y) / sr * 22050 / frame_length / batch_size))\n", | |
| "\n", | |
| "# Load pre-trained model\n", | |
| "model = BigGAN.from_pretrained(model_name)\n", | |
| "\n", | |
| "# set device\n", | |
| "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n", | |
| "\n", | |
| "\n", | |
| "########################################\n", | |
| "########################################\n", | |
| "########################################\n", | |
| "########################################\n", | |
| "########################################\n", | |
| "\n", | |
| "\n", | |
| "# create spectrogram\n", | |
| "spec = librosa.feature.melspectrogram(\n", | |
| " y=y, sr=sr, n_mels=128, fmax=8000, hop_length=frame_length\n", | |
| ")\n", | |
| "\n", | |
| "# get mean power at each time point\n", | |
| "specm = np.mean(spec, axis=0)\n", | |
| "\n", | |
| "# compute power gradient across time points\n", | |
| "gradm = np.gradient(specm)\n", | |
| "\n", | |
| "# set max to 1\n", | |
| "gradm = gradm / np.max(gradm)\n", | |
| "\n", | |
| "# set negative gradient time points to zero\n", | |
| "gradm = gradm.clip(min=0)\n", | |
| "\n", | |
| "# normalize mean power between 0-1\n", | |
| "specm = (specm - np.min(specm)) / np.ptp(specm)\n", | |
| "\n", | |
| "# create chromagram of pitches X time points\n", | |
| "chroma = librosa.feature.chroma_cqt(y=y, sr=sr, hop_length=frame_length)\n", | |
| "\n", | |
| "# sort pitches by overall power\n", | |
| "chromasort = np.argsort(np.mean(chroma, axis=1))[::-1]\n", | |
| "\n", | |
| "cls1000 = list(range(1000))\n", | |
| "random.shuffle(cls1000)\n", | |
| "classes = cls1000[:12]\n", | |
| "\n", | |
| "\n", | |
| "if sort_classes_by_power == 1:\n", | |
| " classes = [classes[s] for s in np.argsort(chromasort[:num_classes])]\n", | |
| "\n", | |
| "\n", | |
| "# initialize first class vector\n", | |
| "cv1 = np.zeros(1000)\n", | |
| "for pi, p in enumerate(chromasort[:num_classes]):\n", | |
| "\n", | |
| " if num_classes < 12:\n", | |
| " cv1[classes[pi]] = chroma[p][\n", | |
| " np.min([np.where(chrow > 0)[0][0] for chrow in chroma])\n", | |
| " ]\n", | |
| " else:\n", | |
| " cv1[classes[p]] = chroma[p][\n", | |
| " np.min([np.where(chrow > 0)[0][0] for chrow in chroma])\n", | |
| " ]\n", | |
| "\n", | |
| "# initialize first noise vector\n", | |
| "nv1 = truncated_noise_sample(truncation=truncation)[0]\n", | |
| "\n", | |
| "# initialize list of class and noise vectors\n", | |
| "class_vectors = [cv1]\n", | |
| "noise_vectors = [nv1]\n", | |
| "\n", | |
| "# initialize previous vectors (will be used to track the previous frame)\n", | |
| "cvlast = cv1\n", | |
| "nvlast = nv1\n", | |
| "\n", | |
| "\n", | |
| "# initialize the direction of noise vector unit updates\n", | |
| "update_dir = np.zeros(128)\n", | |
| "for ni, n in enumerate(nv1):\n", | |
| " if n < 0:\n", | |
| " update_dir[ni] = 1\n", | |
| " else:\n", | |
| " update_dir[ni] = -1\n", | |
| "\n", | |
| "\n", | |
| "# initialize noise unit update\n", | |
| "update_last = np.zeros(128)\n", | |
| "\n", | |
| "# get new jitters\n", | |
| "def new_jitters(jitter):\n", | |
| " jitters = np.zeros(128)\n", | |
| " for j in range(128):\n", | |
| " if random.uniform(0, 1) < 0.5:\n", | |
| " jitters[j] = 1\n", | |
| " else:\n", | |
| " jitters[j] = 1 - jitter\n", | |
| " return jitters\n", | |
| "\n", | |
| "\n", | |
| "# get new update directions\n", | |
| "def new_update_dir(nv2, update_dir):\n", | |
| " for ni, n in enumerate(nv2):\n", | |
| " if n >= 2 * truncation - tempo_sensitivity:\n", | |
| " update_dir[ni] = -1\n", | |
| "\n", | |
| " elif n < -2 * truncation + tempo_sensitivity:\n", | |
| " update_dir[ni] = 1\n", | |
| " return update_dir\n", | |
| "\n", | |
| "\n", | |
| "# smooth class vectors\n", | |
| "def smooth(class_vectors, smooth_factor):\n", | |
| "\n", | |
| " if smooth_factor == 1:\n", | |
| " return class_vectors\n", | |
| "\n", | |
| " class_vectors_terp = []\n", | |
| " for c in range(int(np.floor(len(class_vectors) / smooth_factor) - 1)):\n", | |
| " ci = c * smooth_factor\n", | |
| " cva = np.mean(class_vectors[int(ci) : int(ci) + smooth_factor], axis=0)\n", | |
| " cvb = np.mean(\n", | |
| " class_vectors[int(ci) + smooth_factor : int(ci) + smooth_factor * 2], axis=0\n", | |
| " )\n", | |
| "\n", | |
| " for j in range(smooth_factor):\n", | |
| " cvc = cva * (1 - j / (smooth_factor - 1)) + cvb * (j / (smooth_factor - 1))\n", | |
| " class_vectors_terp.append(cvc)\n", | |
| "\n", | |
| " return np.array(class_vectors_terp)\n", | |
| "\n", | |
| "\n", | |
| "# normalize class vector between 0-1\n", | |
| "def normalize_cv(cv2):\n", | |
| " min_class_val = min(i for i in cv2 if i != 0)\n", | |
| " for ci, c in enumerate(cv2):\n", | |
| " if c == 0:\n", | |
| " cv2[ci] = min_class_val\n", | |
| " cv2 = (cv2 - min_class_val) / np.ptp(cv2)\n", | |
| "\n", | |
| " return cv2\n", | |
| "\n", | |
| "\n", | |
| "print(\"\\nGenerating input vectors \\n\")\n", | |
| "\n", | |
| "for i in tqdm(range(len(gradm))):\n", | |
| "\n", | |
| " # print progress\n", | |
| " pass\n", | |
| "\n", | |
| " # update jitter vector every 100 frames by setting ~half of noise vector units to lower sensitivity\n", | |
| " if i % 200 == 0:\n", | |
| " jitters = new_jitters(jitter)\n", | |
| "\n", | |
| " # get last noise vector\n", | |
| " nv1 = nvlast\n", | |
| "\n", | |
| " # set noise vector update based on direction, sensitivity, jitter, and combination of overall power and gradient of power\n", | |
| " update = (\n", | |
| " np.array([tempo_sensitivity for k in range(128)])\n", | |
| " * (gradm[i] + specm[i])\n", | |
| " * update_dir\n", | |
| " * jitters\n", | |
| " )\n", | |
| "\n", | |
| " # smooth the update with the previous update (to avoid overly sharp frame transitions)\n", | |
| " update = (update + update_last * 3) / 4\n", | |
| "\n", | |
| " # set last update\n", | |
| " update_last = update\n", | |
| "\n", | |
| " # update noise vector\n", | |
| " nv2 = nv1 + update\n", | |
| "\n", | |
| " # append to noise vectors\n", | |
| " noise_vectors.append(nv2)\n", | |
| "\n", | |
| " # set last noise vector\n", | |
| " nvlast = nv2\n", | |
| "\n", | |
| " # update the direction of noise units\n", | |
| " update_dir = new_update_dir(nv2, update_dir)\n", | |
| "\n", | |
| " # get last class vector\n", | |
| " cv1 = cvlast\n", | |
| "\n", | |
| " # generate new class vector\n", | |
| " cv2 = np.zeros(1000)\n", | |
| " for j in range(num_classes):\n", | |
| "\n", | |
| " cv2[classes[j]] = (\n", | |
| " cvlast[classes[j]] + ((chroma[chromasort[j]][i]) / (pitch_sensitivity))\n", | |
| " ) / (1 + (1 / ((pitch_sensitivity))))\n", | |
| "\n", | |
| " # if more than 6 classes, normalize new class vector between 0 and 1, else simply set max class val to 1\n", | |
| " if num_classes > 6:\n", | |
| " cv2 = normalize_cv(cv2)\n", | |
| " else:\n", | |
| " cv2 = cv2 / np.max(cv2)\n", | |
| "\n", | |
| " # adjust depth\n", | |
| " cv2 = cv2 * depth\n", | |
| "\n", | |
| " # this prevents rare bugs where all classes are the same value\n", | |
| " if np.std(cv2[np.where(cv2 != 0)]) < 0.0000001:\n", | |
| " cv2[classes[0]] = cv2[classes[0]] + 0.01\n", | |
| "\n", | |
| " # append new class vector\n", | |
| " class_vectors.append(cv2)\n", | |
| "\n", | |
| " # set last class vector\n", | |
| " cvlast = cv2\n", | |
| "\n", | |
| "\n", | |
| "# interpolate between class vectors of bin size [smooth_factor] to smooth frames\n", | |
| "class_vectors = smooth(class_vectors, smooth_factor)\n", | |
| "\n", | |
| "\n", | |
| "# check whether to use vectors from last run\n", | |
| "if use_previous_vectors == 1:\n", | |
| " # load vectors from previous run\n", | |
| " class_vectors = np.load(\"/tmp/class_vectors.npy\")\n", | |
| " noise_vectors = np.load(\"/tmp/noise_vectors.npy\")\n", | |
| "else:\n", | |
| " # save record of vectors for current video\n", | |
| " np.save(\"/tmp/class_vectors.npy\", class_vectors)\n", | |
| " np.save(\"/tmp/noise_vectors.npy\", noise_vectors)\n", | |
| "\n", | |
| "# convert to Tensor\n", | |
| "noise_vectors = torch.Tensor(np.array(noise_vectors))\n", | |
| "class_vectors = torch.Tensor(np.array(class_vectors))\n", | |
| "\n", | |
| "\n", | |
| "# Generate frames in batches of batch_size\n", | |
| "\n", | |
| "print(\"\\n\\nGenerating frames \\n\")\n", | |
| "\n", | |
| "# send to CUDA if running on GPU\n", | |
| "model = model.to(device)\n", | |
| "noise_vectors = noise_vectors.to(device)\n", | |
| "class_vectors = class_vectors.to(device)\n", | |
| "\n", | |
| "\n", | |
| "frames = []\n", | |
| "\n", | |
| "for i in tqdm(range(frame_lim)):\n", | |
| "\n", | |
| " # print progress\n", | |
| " pass\n", | |
| "\n", | |
| " if (i + 1) * batch_size > len(class_vectors):\n", | |
| " torch.cuda.empty_cache()\n", | |
| " break\n", | |
| "\n", | |
| " # get batch\n", | |
| " noise_vector = noise_vectors[i * batch_size : (i + 1) * batch_size]\n", | |
| " class_vector = class_vectors[i * batch_size : (i + 1) * batch_size]\n", | |
| "\n", | |
| " # Generate images\n", | |
| " with torch.no_grad():\n", | |
| " output = model(noise_vector, class_vector, truncation)\n", | |
| "\n", | |
| " output_cpu = output.cpu().data.numpy()\n", | |
| "\n", | |
| " # convert to image array and add to frames\n", | |
| " for out in output_cpu:\n", | |
| " im = np.array(toimage(out))\n", | |
| " frames.append(im)\n", | |
| "\n", | |
| " # empty cuda cache\n", | |
| " torch.cuda.empty_cache()\n", | |
| "\n", | |
| "aud = mpy.AudioFileClip(\"/tmp/1.mp3\", fps=44100)\n", | |
| "clip = mpy.ImageSequenceClip(frames, fps=22050 / frame_length)\n", | |
| "clip = clip.set_audio(aud)\n", | |
| "clip.write_videofile(outname, audio_codec=\"aac\")\n", | |
| "\n", | |
| "from google.colab import files\n", | |
| "\n", | |
| "files.download('/tmp/1.mp4')\n", | |
| "\n" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/", | |
| "height": 330 | |
| }, | |
| "id": "wbwY0W7lb4Gu", | |
| "outputId": "c73bd8e3-a236-4018-fc52-d00f24e33b07" | |
| }, | |
| "execution_count": 15, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "\n", | |
| "Generating input vectors \n", | |
| "\n" | |
| ] | |
| }, | |
| { | |
| "output_type": "stream", | |
| "name": "stderr", | |
| "text": [ | |
| "100%|██████████| 1723/1723 [00:03<00:00, 517.78it/s]\n" | |
| ] | |
| }, | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "\n", | |
| "\n", | |
| "Generating frames \n", | |
| "\n" | |
| ] | |
| }, | |
| { | |
| "output_type": "stream", | |
| "name": "stderr", | |
| "text": [ | |
| " 98%|█████████▊| 56/57 [02:21<00:02, 2.53s/it]" | |
| ] | |
| }, | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "[MoviePy] >>>> Building video /tmp/1.mp4\n", | |
| "[MoviePy] Writing audio in 1TEMP_MPY_wvf_snd.mp4\n" | |
| ] | |
| }, | |
| { | |
| "output_type": "stream", | |
| "name": "stderr", | |
| "text": [ | |
| "\n", | |
| "100%|██████████| 883/883 [00:01<00:00, 456.69it/s]" | |
| ] | |
| }, | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "[MoviePy] Done.\n", | |
| "[MoviePy] Writing video /tmp/1.mp4\n" | |
| ] | |
| }, | |
| { | |
| "output_type": "stream", | |
| "name": "stderr", | |
| "text": [ | |
| "\n", | |
| "100%|██████████| 1680/1680 [00:16<00:00, 98.96it/s]\n" | |
| ] | |
| }, | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "[MoviePy] Done.\n", | |
| "[MoviePy] >>>> Video ready: /tmp/1.mp4 \n", | |
| "\n" | |
| ] | |
| }, | |
| { | |
| "output_type": "display_data", | |
| "data": { | |
| "text/plain": [ | |
| "<IPython.core.display.Javascript object>" | |
| ], | |
| "application/javascript": [ | |
| "\n", | |
| " async function download(id, filename, size) {\n", | |
| " if (!google.colab.kernel.accessAllowed) {\n", | |
| " return;\n", | |
| " }\n", | |
| " const div = document.createElement('div');\n", | |
| " const label = document.createElement('label');\n", | |
| " label.textContent = `Downloading \"${filename}\": `;\n", | |
| " div.appendChild(label);\n", | |
| " const progress = document.createElement('progress');\n", | |
| " progress.max = size;\n", | |
| " div.appendChild(progress);\n", | |
| " document.body.appendChild(div);\n", | |
| "\n", | |
| " const buffers = [];\n", | |
| " let downloaded = 0;\n", | |
| "\n", | |
| " const channel = await google.colab.kernel.comms.open(id);\n", | |
| " // Send a message to notify the kernel that we're ready.\n", | |
| " channel.send({})\n", | |
| "\n", | |
| " for await (const message of channel.messages) {\n", | |
| " // Send a message to notify the kernel that we're ready.\n", | |
| " channel.send({})\n", | |
| " if (message.buffers) {\n", | |
| " for (const buffer of message.buffers) {\n", | |
| " buffers.push(buffer);\n", | |
| " downloaded += buffer.byteLength;\n", | |
| " progress.value = downloaded;\n", | |
| " }\n", | |
| " }\n", | |
| " }\n", | |
| " const blob = new Blob(buffers, {type: 'application/binary'});\n", | |
| " const a = document.createElement('a');\n", | |
| " a.href = window.URL.createObjectURL(blob);\n", | |
| " a.download = filename;\n", | |
| " div.appendChild(a);\n", | |
| " a.click();\n", | |
| " div.remove();\n", | |
| " }\n", | |
| " " | |
| ] | |
| }, | |
| "metadata": {} | |
| }, | |
| { | |
| "output_type": "display_data", | |
| "data": { | |
| "text/plain": [ | |
| "<IPython.core.display.Javascript object>" | |
| ], | |
| "application/javascript": [ | |
| "download(\"download_719ef4ee-4925-434d-b8ca-cecc5dcce6db\", \"1.mp4\", 5747919)" | |
| ] | |
| }, | |
| "metadata": {} | |
| } | |
| ] | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, i cant seem to run the second section. The run of the first section ends with a few warning messages:
Any suggestion?
-thanks so much for your work
Building wheels for collected packages: scipy, moviepy
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
Building wheel for scipy (setup.py) ... error
ERROR: Failed building wheel for scipy
Running setup.py clean for scipy
error: subprocess-exited-with-error
× python setup.py clean did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed cleaning build dir for scipy
Building wheel for moviepy (setup.py) ... done
Created wheel for moviepy: filename=moviepy-1.0.3-py3-none-any.whl size=110721 sha256=0b86af3d230dfc8ad2aead606230fa1c06de5eff890714bfdc18fb0916e2f04e
Stored in directory: /root/.cache/pip/wheels/96/32/2d/e10123bd88fbfc02fed53cc18c80a171d3c87479ed845fa7c1
Successfully built moviepy
Failed to build scipy
ERROR: Could not build wheels for scipy, which is required to install pyproject.toml-based projects
[3]
0 s
import librosa
import argparse
import numpy as np
import moviepy.editor as mpy
import random
import torch
from scipy.misc import toimage
from tqdm import tqdm
from pytorch_pretrained_biggan import (BigGAN, one_hot_from_names, truncated_noise_sample,
save_as_images, display_in_terminal)