|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": { |
| 6 | + "id": "Th91ofnQWr8Y" |
| 7 | + }, |
| 8 | + "source": [ |
| 9 | + "## Dataset building + XTTS finetuning and inference\n", |
| 10 | + "\n", |
| 11 | + "#### Running the demo\n", |
| 12 | + "To start the demo run the first two cells (ignore pip install errors in the first one)\n", |
| 13 | + "\n", |
| 14 | + "Then click on the link `Running on public URL: ` when the demo is ready.\n", |
| 15 | + "\n", |
| 16 | + "#### Downloading the results\n", |
| 17 | + "\n", |
| 18 | + "You can run cell [3] to zip and download default dataset path\n", |
| 19 | + "\n", |
| 20 | + "You can run cell [4] to zip and download the latest model you trained" |
| 21 | + ] |
| 22 | + }, |
| 23 | + { |
| 24 | + "cell_type": "markdown", |
| 25 | + "metadata": { |
| 26 | + "id": "cdWKA_xFqkKq" |
| 27 | + }, |
| 28 | + "source": [ |
| 29 | + "### Installing the requirements" |
| 30 | + ] |
| 31 | + }, |
| 32 | + { |
| 33 | + "cell_type": "code", |
| 34 | + "execution_count": null, |
| 35 | + "metadata": { |
| 36 | + "id": "lmUUQqdN6BXk" |
| 37 | + }, |
| 38 | + "outputs": [], |
| 39 | + "source": [ |
| 40 | + "!pip install coqui-tts\n", |
| 41 | + "!pip install gradio==4.7.1 faster_whisper" |
| 42 | + ] |
| 43 | + }, |
| 44 | + { |
| 45 | + "cell_type": "markdown", |
| 46 | + "metadata": { |
| 47 | + "id": "g7rNt1e2qtDP" |
| 48 | + }, |
| 49 | + "source": [ |
| 50 | + "### Running the gradio UI" |
| 51 | + ] |
| 52 | + }, |
| 53 | + { |
| 54 | + "cell_type": "code", |
| 55 | + "execution_count": null, |
| 56 | + "metadata": { |
| 57 | + "id": "zd2xo_7a8wyj" |
| 58 | + }, |
| 59 | + "outputs": [], |
| 60 | + "source": [ |
| 61 | + "!python -m TTS.demos.xtts_ft_demo.xtts_demo --batch_size 2 --num_epochs 6" |
| 62 | + ] |
| 63 | + }, |
| 64 | + { |
| 65 | + "cell_type": "markdown", |
| 66 | + "metadata": { |
| 67 | + "id": "oXEBRA_kq23i" |
| 68 | + }, |
| 69 | + "source": [ |
| 70 | + "### Downloading the dataset" |
| 71 | + ] |
| 72 | + }, |
| 73 | + { |
| 74 | + "cell_type": "code", |
| 75 | + "execution_count": null, |
| 76 | + "metadata": { |
| 77 | + "id": "dBxgdKcvi4kO" |
| 78 | + }, |
| 79 | + "outputs": [], |
| 80 | + "source": [ |
| 81 | + "from google.colab import files\n", |
| 82 | + "\n", |
| 83 | + "!zip -q -r dataset.zip /tmp/xtts_ft/dataset\n", |
| 84 | + "files.download('dataset.zip')" |
| 85 | + ] |
| 86 | + }, |
| 87 | + { |
| 88 | + "cell_type": "markdown", |
| 89 | + "metadata": { |
| 90 | + "id": "ZKzoP53Nq_rJ" |
| 91 | + }, |
| 92 | + "source": [ |
| 93 | + "### Downloading the model" |
| 94 | + ] |
| 95 | + }, |
| 96 | + { |
| 97 | + "cell_type": "code", |
| 98 | + "execution_count": null, |
| 99 | + "metadata": { |
| 100 | + "id": "NpfdzHvKaX8M" |
| 101 | + }, |
| 102 | + "outputs": [], |
| 103 | + "source": [ |
| 104 | + "from google.colab import files\n", |
| 105 | + "import os\n", |
| 106 | + "import glob\n", |
| 107 | + "import torch\n", |
| 108 | + "\n", |
| 109 | + "def find_latest_best_model(folder_path):\n", |
| 110 | + " search_path = os.path.join(folder_path, '**', 'best_model.pth')\n", |
| 111 | + " files = glob.glob(search_path, recursive=True)\n", |
| 112 | + " latest_file = max(files, key=os.path.getctime, default=None)\n", |
| 113 | + " return latest_file\n", |
| 114 | + "\n", |
| 115 | + "model_path = find_latest_best_model(\"/tmp/xtts_ft/run/training/\")\n", |
| 116 | + "checkpoint = torch.load(model_path, map_location=torch.device(\"cpu\"))\n", |
| 117 | + "del checkpoint[\"optimizer\"]\n", |
| 118 | + "for key in list(checkpoint[\"model\"].keys()):\n", |
| 119 | + " if \"dvae\" in key:\n", |
| 120 | + " del checkpoint[\"model\"][key]\n", |
| 121 | + "torch.save(checkpoint, \"model.pth\")\n", |
| 122 | + "model_dir = os.path.dirname(model_path)\n", |
| 123 | + "files.download(os.path.join(model_dir, 'config.json'))\n", |
| 124 | + "files.download(os.path.join(model_dir, 'vocab.json'))\n", |
| 125 | + "files.download('model.pth')" |
| 126 | + ] |
| 127 | + }, |
| 128 | + { |
| 129 | + "cell_type": "markdown", |
| 130 | + "metadata": { |
| 131 | + "id": "Eh9_SusYdRE4" |
| 132 | + }, |
| 133 | + "source": [ |
| 134 | + "### Copy files to your google drive\n", |
| 135 | + "\n", |
| 136 | + "The two previous cells are a requirement for this step but it can be much faster" |
| 137 | + ] |
| 138 | + }, |
| 139 | + { |
| 140 | + "cell_type": "code", |
| 141 | + "execution_count": null, |
| 142 | + "metadata": { |
| 143 | + "id": "piLAaVHSdQs5" |
| 144 | + }, |
| 145 | + "outputs": [], |
| 146 | + "source": [ |
| 147 | + "from google.colab import drive\n", |
| 148 | + "import shutil\n", |
| 149 | + "drive.mount('/content/drive')\n", |
| 150 | + "!mkdir /content/drive/MyDrive/XTTS_ft_colab\n", |
| 151 | + "shutil.copy(os.path.join(model_dir, 'config.json'), \"/content/drive/MyDrive/XTTS_ft_colab/config.json\")\n", |
| 152 | + "shutil.copy(os.path.join(model_dir, 'vocab.json'), \"/content/drive/MyDrive/XTTS_ft_colab/vocab.json'\")\n", |
| 153 | + "shutil.copy('model.pth', \"/content/drive/MyDrive/XTTS_ft_colab/model.pth\")\n", |
| 154 | + "shutil.copy('dataset.zip', \"/content/drive/MyDrive/XTTS_ft_colab/dataset.zip\")" |
| 155 | + ] |
| 156 | + } |
| 157 | + ], |
| 158 | + "metadata": { |
| 159 | + "accelerator": "GPU", |
| 160 | + "colab": { |
| 161 | + "gpuType": "T4", |
| 162 | + "provenance": [] |
| 163 | + }, |
| 164 | + "kernelspec": { |
| 165 | + "display_name": "Python 3", |
| 166 | + "name": "python3" |
| 167 | + }, |
| 168 | + "language_info": { |
| 169 | + "name": "python" |
| 170 | + } |
| 171 | + }, |
| 172 | + "nbformat": 4, |
| 173 | + "nbformat_minor": 0 |
| 174 | +} |
0 commit comments