File size: 22,037 Bytes
641d0e6 |
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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 |
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "0pKllbPyK_BC"
},
"source": [
"## **Applio NoUI**\n",
"A simple, high-quality voice conversion tool focused on ease of use and performance.\n",
"\n",
"[Support](https://discord.gg/urxFjYmYYh) — [GitHub](https://github.com/IAHispano/Applio) — [Terms of Use](https://github.com/IAHispano/Applio/blob/main/TERMS_OF_USE.md)\n",
"\n",
"<br>\n",
"\n",
"---\n",
"\n",
"<br>\n",
"\n",
"#### **Acknowledgments**\n",
"\n",
"To all external collaborators for their special help in the following areas: Hina (Encryption method), Poopmaster (Extra section), Shirou (UV installer), Kit Lemonfoot (NoUI inspiration)\n",
"\n",
"#### **Disclaimer**\n",
"By using Applio, you agree to comply with ethical and legal standards, respect intellectual property and privacy rights, avoid harmful or prohibited uses, and accept full responsibility for any outcomes, while Applio disclaims liability and reserves the right to amend these terms."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ymMCTSD6m8qV"
},
"source": [
"### **Install Applio**\n",
"If the runtime restarts, re-run the installation steps."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "yFhAeKGOp9aa"
},
"outputs": [],
"source": [
"# @title Mount Google Drive\n",
"from google.colab import drive\n",
"\n",
"drive.mount(\"/content/drive\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "CAXW55BQm0PP"
},
"outputs": [],
"source": [
"# @title Setup runtime environment\n",
"from multiprocessing import cpu_count\n",
"cpu_cores = cpu_count()\n",
"post_process = False\n",
"hop_length = 128 # Common default value for hop_length, added for consistency across cells\n",
"\n",
"!git config --global advice.detachedHead false\n",
"!git clone https://github.com/IAHispano/Applio --branch 3.2.9 --single-branch\n",
"%cd /content/Applio\n",
"!sudo update-alternatives --set python3 /usr/bin/python3.10\n",
"!curl -LsSf https://astral.sh/uv/install.sh | sh\n",
"\n",
"print(\"Installing requirements...\")\n",
"!uv pip install -q -r requirements.txt\n",
"print(\"Finished installing requirements!\")\n",
"!python core.py \"prerequisites\" --models \"True\" --pretraineds_hifigan \"True\""
]
},
{
"cell_type": "code",
"source": [
"\n",
"# @title Unduh File Model\n",
"# @markdown Kode ini akan mengunduh file model yang diperlukan ke direktori `/content/`.\n",
"\n",
"import os\n",
"\n",
"# URL dan nama file\n",
"files_to_download = {\n",
" \"D_GKv1_48k.pth\": \"https://huggingface.co/glickko/GK_pretrain/resolve/main/D_GKv1_48k.pth?download=true\",\n",
" \"G_GKv1_48k.pth\": \"https://huggingface.co/glickko/GK_pretrain/resolve/main/G_GKv1_48k.pth?download=true\",\n",
"\n",
"}\n",
"\n",
"# Direktori tujuan\n",
"output_directory = \"/content\"\n",
"\n",
"# Proses pengunduhan\n",
"for filename, url in files_to_download.items():\n",
" output_path = os.path.join(output_directory, filename)\n",
" print(f\"Mengunduh {filename}...\")\n",
" # Menggunakan wget untuk mengunduh file\n",
" !wget -q --show-progress -O {output_path} \"{url}\"\n",
" print(f\"Selesai! File disimpan di: {output_path}\\n\")\n",
"\n",
"print(\"🎉 Semua file telah berhasil diunduh.\")\n",
"\n",
"# Menampilkan isi folder /content untuk verifikasi\n",
"print(\"\\nIsi folder /content saat ini:\")\n",
"!ls -lh /content"
],
"metadata": {
"id": "eYCTi9pE90fU"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "1QkabnLlF2KB"
},
"source": [
"### **Train**"
]
},
{
"cell_type": "code",
"source": [
"# @title Setup model variables\n",
"model_name = \"\" # @param {type:\"string\"}\n",
"sample_rate = \"48k\" # @param [\"32k\", \"40k\", \"48k\"] {allow-input: false}\n",
"sr = int(sample_rate.rstrip(\"k\")) * 1000"
],
"metadata": {
"cellView": "form",
"id": "64V5TWxp05cn"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "oBzqm4JkGGa0"
},
"outputs": [],
"source": [
"# @title Preprocess Dataset\n",
"from os import environ\n",
"environ['TF_CPP_MIN_LOG_LEVEL'] = '3'\n",
"dataset_path = \"\" # @param {type:\"string\"}\n",
"\n",
"cut_preprocess = \"Simple\" # @param [\"Skip\",\"Simple\",\"Automatic\"]\n",
"chunk_len = 5 # @param {type:\"slider\", min:0.5, max:5.0, step:0.5}\n",
"overlap_len = 0.3 # @param {type:\"slider\", min:0, max:0.5, step:0.1}\n",
"process_effects = False # @param{type:\"boolean\"}\n",
"noise_reduction = False # @param{type:\"boolean\"}\n",
"noise_reduction_strength = 0.7 # @param {type:\"slider\", min:0.0, max:1.0, step:0.1}\n",
"\n",
"%cd /content/Applio\n",
"!python core.py preprocess --model_name \"{model_name}\" --dataset_path \"{dataset_path}\" --sample_rate \"{sr}\" --cpu_cores \"{cpu_cores}\" --cut_preprocess \"{cut_preprocess}\" --process_effects \"{process_effects}\" --noise_reduction \"{noise_reduction}\" --noise_reduction_strength \"{noise_reduction_strength}\" --chunk_len \"{chunk_len}\" --overlap_len \"{overlap_len}\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "zWMiMYfRJTJv"
},
"outputs": [],
"source": [
"# @title Extract Features\n",
"f0_method = \"rmvpe\" # @param [\"crepe\", \"crepe-tiny\", \"rmvpe\"] {allow-input: false}\n",
"\n",
"sr = int(sample_rate.rstrip(\"k\")) * 1000\n",
"include_mutes = 2 # @param {type:\"slider\", min:0, max:10, step:1}\n",
"embedder_model = \"contentvec\" # @param [\"contentvec\", \"chinese-hubert-base\", \"japanese-hubert-base\", \"korean-hubert-base\", \"custom\"] {allow-input: false}\n",
"embedder_model_custom = \"\" # @param {type:\"string\"}\n",
"\n",
"%cd /content/Applio\n",
"!python core.py extract --model_name \"{model_name}\" --f0_method \"{f0_method}\" --hop_length \"{hop_length}\" --sample_rate \"{sr}\" --cpu_cores \"{cpu_cores}\" --gpu \"0\" --embedder_model \"{embedder_model}\" --embedder_model_custom \"{embedder_model_custom}\" --include_mutes \"{include_mutes}\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "bHLs5AT4Q1ck"
},
"outputs": [],
"source": [
"# @title Generate index file\n",
"index_algorithm = \"Auto\" # @param [\"Auto\", \"Faiss\", \"KMeans\"] {allow-input: false}\n",
"\n",
"%cd /content/Applio\n",
"!python core.py index --model_name \"{model_name}\" --index_algorithm \"{index_algorithm}\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "TI6LLdIzKAIa"
},
"outputs": [],
"source": [
"# @title Start Training\n",
"import threading\n",
"import time\n",
"import os\n",
"import shutil\n",
"import hashlib\n",
"import time\n",
"\n",
"LOGS_FOLDER = \"/content/Applio/logs/\"\n",
"GOOGLE_DRIVE_PATH = \"/content/drive/MyDrive/RVC_Backup\"\n",
"\n",
"\n",
"def import_google_drive_backup():\n",
" print(\"Importing Google Drive backup...\")\n",
" for root, dirs, files in os.walk(GOOGLE_DRIVE_PATH):\n",
" for filename in files:\n",
" filepath = os.path.join(root, filename)\n",
" if os.path.isfile(filepath):\n",
" backup_filepath = os.path.join(\n",
" LOGS_FOLDER, os.path.relpath(filepath, GOOGLE_DRIVE_PATH)\n",
" )\n",
" backup_folderpath = os.path.dirname(backup_filepath)\n",
" if not os.path.exists(backup_folderpath):\n",
" os.makedirs(backup_folderpath)\n",
" print(f\"Created backup folder: {backup_folderpath}\", flush=True)\n",
" shutil.copy2(filepath, backup_filepath)\n",
" print(f\"Imported file from Google Drive backup: {filename}\")\n",
" print(\"Google Drive backup import completed.\")\n",
"\n",
"\n",
"if \"autobackups\" not in globals():\n",
" autobackups = False\n",
"# @markdown ### 💾 AutoBackup\n",
"cooldown = 15 # @param {type:\"slider\", min:0, max:100, step:0}\n",
"auto_backups = True # @param{type:\"boolean\"}\n",
"def backup_files():\n",
" print(\"\\nStarting backup loop...\")\n",
" last_backup_timestamps_path = os.path.join(\n",
" LOGS_FOLDER, \"last_backup_timestamps.txt\"\n",
" )\n",
" fully_updated = False\n",
"\n",
" while True:\n",
" try:\n",
" updated_files = 0\n",
" deleted_files = 0\n",
" new_files = 0\n",
" last_backup_timestamps = {}\n",
"\n",
" try:\n",
" with open(last_backup_timestamps_path, \"r\") as f:\n",
" last_backup_timestamps = dict(line.strip().split(\":\") for line in f)\n",
" except FileNotFoundError:\n",
" pass\n",
"\n",
" for root, dirs, files in os.walk(LOGS_FOLDER):\n",
" # Excluding \"zips\" and \"mute\" directories\n",
" if \"zips\" in dirs:\n",
" dirs.remove(\"zips\")\n",
" if \"mute\" in dirs:\n",
" dirs.remove(\"mute\")\n",
"\n",
" for filename in files:\n",
" if filename != \"last_backup_timestamps.txt\":\n",
" filepath = os.path.join(root, filename)\n",
" if os.path.isfile(filepath):\n",
" backup_filepath = os.path.join(\n",
" GOOGLE_DRIVE_PATH,\n",
" os.path.relpath(filepath, LOGS_FOLDER),\n",
" )\n",
" backup_folderpath = os.path.dirname(backup_filepath)\n",
" if not os.path.exists(backup_folderpath):\n",
" os.makedirs(backup_folderpath)\n",
" last_backup_timestamp = last_backup_timestamps.get(filepath)\n",
" current_timestamp = os.path.getmtime(filepath)\n",
" if (\n",
" last_backup_timestamp is None\n",
" or float(last_backup_timestamp) < current_timestamp\n",
" ):\n",
" shutil.copy2(filepath, backup_filepath)\n",
" last_backup_timestamps[filepath] = str(current_timestamp)\n",
" if last_backup_timestamp is None:\n",
" new_files += 1\n",
" else:\n",
" updated_files += 1\n",
"\n",
"\n",
" for filepath in list(last_backup_timestamps.keys()):\n",
" if not os.path.exists(filepath):\n",
" backup_filepath = os.path.join(\n",
" GOOGLE_DRIVE_PATH, os.path.relpath(filepath, LOGS_FOLDER)\n",
" )\n",
" if os.path.exists(backup_filepath):\n",
" os.remove(backup_filepath)\n",
" deleted_files += 1\n",
" del last_backup_timestamps[filepath]\n",
"\n",
"\n",
" if updated_files > 0 or deleted_files > 0 or new_files > 0:\n",
" print(f\"Backup Complete: {new_files} new, {updated_files} updated, {deleted_files} deleted.\")\n",
" fully_updated = False\n",
" elif not fully_updated:\n",
" print(\"Files are up to date.\")\n",
" fully_updated = True\n",
"\n",
" with open(last_backup_timestamps_path, \"w\") as f:\n",
" for filepath, timestamp in last_backup_timestamps.items():\n",
" f.write(f\"{filepath}:{timestamp}\\n\")\n",
"\n",
" time.sleep(cooldown if fully_updated else 0.1)\n",
"\n",
"\n",
" except Exception as error:\n",
" print(f\"An error occurred during backup: {error}\")\n",
"\n",
"\n",
"if autobackups:\n",
" autobackups = False\n",
" print(\"Autobackup Disabled\")\n",
"else:\n",
" autobackups = True\n",
" print(\"Autobackup Enabled\")\n",
"# @markdown ### ⚙️ Train Settings\n",
"total_epoch = 150 # @param {type:\"integer\"}\n",
"batch_size = 19 # @param {type:\"slider\", min:1, max:25, step:0}\n",
"gpu = 0\n",
"sr = int(sample_rate.rstrip(\"k\")) * 1000\n",
"pretrained = True # @param{type:\"boolean\"}\n",
"cleanup = False # @param{type:\"boolean\"}\n",
"cache_data_in_gpu = False # @param{type:\"boolean\"}\n",
"vocoder = \"HiFi-GAN\" # @param [\"HiFi-GAN\"]\n",
"checkpointing = False\n",
"tensorboard = True # @param{type:\"boolean\"}\n",
"# @markdown ### ➡️ Choose how many epochs your model will be stored\n",
"save_every_epoch = 10 # @param {type:\"slider\", min:1, max:100, step:0}\n",
"save_only_latest = True # @param{type:\"boolean\"}\n",
"save_every_weights = True # @param{type:\"boolean\"}\n",
"overtraining_detector = False # @param{type:\"boolean\"}\n",
"overtraining_threshold = 50 # @param {type:\"slider\", min:1, max:100, step:0}\n",
"# @markdown ### ❓ Optional\n",
"# @markdown In case you select custom pretrained, you will have to download the pretraineds and enter the path of the pretraineds.\n",
"custom_pretrained = True # @param{type:\"boolean\"}\n",
"g_pretrained_path = \"/content/G_GKv1_48k.pth\" # @param {type:\"string\"}\n",
"d_pretrained_path = \"/content/D_GKv1_48k.pth\" # @param {type:\"string\"}\n",
"\n",
"if \"pretrained\" not in globals():\n",
" pretrained = True\n",
"\n",
"if \"custom_pretrained\" not in globals():\n",
" custom_pretrained = False\n",
"\n",
"if \"g_pretrained_path\" not in globals():\n",
" g_pretrained_path = \"Custom Path\"\n",
"\n",
"if \"d_pretrained_path\" not in globals():\n",
" d_pretrained_path = \"Custom Path\"\n",
"\n",
"\n",
"def start_train():\n",
" if tensorboard == True:\n",
" %load_ext tensorboard\n",
" %tensorboard --logdir /content/Applio/logs/\n",
" %cd /content/Applio\n",
" !python core.py train --model_name \"{model_name}\" --save_every_epoch \"{save_every_epoch}\" --save_only_latest \"{save_only_latest}\" --save_every_weights \"{save_every_weights}\" --total_epoch \"{total_epoch}\" --sample_rate \"{sr}\" --batch_size \"{batch_size}\" --gpu \"{gpu}\" --pretrained \"{pretrained}\" --custom_pretrained \"{custom_pretrained}\" --g_pretrained_path \"{g_pretrained_path}\" --d_pretrained_path \"{d_pretrained_path}\" --overtraining_detector \"{overtraining_detector}\" --overtraining_threshold \"{overtraining_threshold}\" --cleanup \"{cleanup}\" --cache_data_in_gpu \"{cache_data_in_gpu}\" --vocoder \"{vocoder}\" --checkpointing \"{checkpointing}\"\n",
"\n",
"\n",
"server_thread = threading.Thread(target=start_train)\n",
"server_thread.start()\n",
"\n",
"if auto_backups:\n",
" backup_files()\n",
"else:\n",
" while True:\n",
" time.sleep(10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "X_eU_SoiHIQg"
},
"source": [
"# @title Export model\n",
"from pathlib import Path\n",
"\n",
"export_for = \"training\" # @param [\"training\", \"inference\"] {allow-input: false}\n",
"\n",
"logs_folder = Path(f\"/content/Applio/logs/{model_name}/\")\n",
"if not (logs_folder.exists() and logs_folder.is_dir()):\n",
" raise FileNotFoundError(f\"{model_name} model folder not found\")\n",
"\n",
"%cd {logs_folder}/..\n",
"if export_for == \"training\":\n",
" !zip -r \"/content/{model_name}.zip\" \"{model_name}\"\n",
"else:\n",
" # find latest trained weight file\n",
" !ls -t \"{model_name}/{model_name}\"_*e_*s.pth | head -n 1 > /tmp/weight.txt\n",
" weight_path = open(\"/tmp/weight.txt\", \"r\").read().strip()\n",
" if weight_path == \"\":\n",
" raise FileNotFoundError(\"Model has no weight file, please finish training first\")\n",
" weight_name = Path(weight_path).name\n",
" # command does not fail if index is missing, and i allow it\n",
" !zip \"/content/{model_name}.zip\" \"{model_name}/{weight_name}\" \"{model_name}/{model_name}.index\"\n",
"\n",
"BACKUP_PATH = \"/content/drive/MyDrive/RVC_Backup/\"\n",
"if Path(\"/content/drive\").is_mount():\n",
" !mkdir -p \"{BACKUP_PATH}\"\n",
" !mv \"/content/{model_name}.zip\" \"{BACKUP_PATH}\" && echo \"Exported model as {BACKUP_PATH}{model_name}.zip\"\n",
"else:\n",
" !echo \"Drive not mounted, exporting model as /content/{model_name}.zip\""
],
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "OaKoymXsyEYN"
},
"source": [
"### **Resume training**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "d3KgLAYnyHkP"
},
"outputs": [],
"source": [
"# @title Load a Backup\n",
"from google.colab import drive\n",
"import os\n",
"import shutil\n",
"\n",
"# @markdown Put the exact name you put as your Model Name in Applio.\n",
"modelname = \"My-Project\" # @param {type:\"string\"}\n",
"source_path = \"/content/drive/MyDrive/RVC_Backup/\" + modelname\n",
"destination_path = \"/content/Applio/logs/\" + modelname\n",
"backup_timestamps_file = \"last_backup_timestamps.txt\"\n",
"if not os.path.exists(source_path):\n",
" print(\n",
" \"The model folder does not exist. Please verify the name is correct or check your Google Drive.\"\n",
" )\n",
"else:\n",
" time_ = os.path.join(\"/content/drive/MyDrive/RVC_Backup/\", backup_timestamps_file)\n",
" time__ = os.path.join(\"/content/Applio/logs/\", backup_timestamps_file)\n",
" if os.path.exists(time_):\n",
" shutil.copy(time_, time__)\n",
" shutil.copytree(source_path, destination_path)\n",
" print(\"Model backup loaded successfully.\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "sc9DzvRCyJ2d"
},
"outputs": [],
"source": [
"# @title Set training variables\n",
"# @markdown ### ➡️ Use the same as you did previously\n",
"model_name = \"Darwin\" # @param {type:\"string\"}\n",
"sample_rate = \"40k\" # @param [\"32k\", \"40k\", \"48k\"] {allow-input: false}\n",
"f0_method = \"rmvpe\" # @param [\"crepe\", \"crepe-tiny\", \"rmvpe\"] {allow-input: false}\n",
"sr = int(sample_rate.rstrip(\"k\")) * 1000"
]
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"collapsed_sections": [
"ymMCTSD6m8qV"
],
"provenance": [],
"private_outputs": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
} |