CoolFace
Apppublic

ChazzyG/Retrieval-based-Voice-Conversion-WebUI

sourceHugging Faceapache-2.0updated 9mo agoView on Hugging Face
0likes
Retrieval_based_Voice_Conversion_WebUI.ipynb381 linesDownload Raw Back to root
1{2  "nbformat": 4,3  "nbformat_minor": 0,4  "metadata": {5    "colab": {6      "private_outputs": true,7      "provenance": []8    },9    "kernelspec": {10      "name": "python3",11      "display_name": "Python 3"12    },13    "language_info": {14      "name": "python"15    },16    "accelerator": "GPU",17    "gpuClass": "standard"18  },19  "cells": [20    {21      "cell_type": "markdown",22      "source": [23        "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/liujing04/Retrieval-based-Voice-Conversion-WebUI/blob/main/Retrieval_based_Voice_Conversion_WebUI.ipynb)"24      ],25      "metadata": {26        "id": "ZFFCx5J80SGa"27      }28    },29    {30      "cell_type": "code",31      "execution_count": null,32      "metadata": {33        "id": "GmFP6bN9dvOq"34      },35      "outputs": [],36      "source": [37        "#@title 查看显卡\n",38        "!nvidia-smi"39      ]40    },41    {42      "cell_type": "code",43      "source": [44        "#@title 安装依赖\n",45        "!apt-get -y install build-essential python3-dev ffmpeg\n",46        "!pip3 install --upgrade setuptools wheel\n",47        "!pip3 install --upgrade pip\n",48        "!pip3 install faiss-gpu fairseq gradio ffmpeg ffmpeg-python praat-parselmouth pyworld numpy==1.23.5 numba==0.56.4 librosa==0.9.2"49      ],50      "metadata": {51        "id": "wjddIFr1oS3W"52      },53      "execution_count": null,54      "outputs": []55    },56    {57      "cell_type": "code",58      "source": [59        "#@title 克隆仓库\n",60        "\n",61        "!git clone --depth=1 -b stable https://github.com/fumiama/Retrieval-based-Voice-Conversion-WebUI\n",62        "%cd /content/Retrieval-based-Voice-Conversion-WebUI\n",63        "!mkdir -p pretrained uvr5_weights"64      ],65      "metadata": {66        "id": "ge_97mfpgqTm"67      },68      "execution_count": null,69      "outputs": []70    },71    {72      "cell_type": "code",73      "source": [74        "#@title 更新仓库(一般无需执行)\n",75        "!git pull"76      ],77      "metadata": {78        "id": "BLDEZADkvlw1"79      },80      "execution_count": null,81      "outputs": []82    },83    {84      "cell_type": "code",85      "source": [86        "#@title 安装aria2\n",87        "!apt -y install -qq aria2"88      ],89      "metadata": {90        "id": "pqE0PrnuRqI2"91      },92      "execution_count": null,93      "outputs": []94    },95    {96      "cell_type": "code",97      "source": [98        "#@title 下载底模\n",99        "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/D32k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o D32k.pth\n",100        "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/D40k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o D40k.pth\n",101        "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/D48k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o D48k.pth\n",102        "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/G32k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o G32k.pth\n",103        "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/G40k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o G40k.pth\n",104        "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/G48k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o G48k.pth\n",105        "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/f0D32k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o f0D32k.pth\n",106        "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/f0D40k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o f0D40k.pth\n",107        "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/f0D48k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o f0D48k.pth\n",108        "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/f0G32k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o f0G32k.pth\n",109        "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/f0G40k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o f0G40k.pth\n",110        "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/f0G48k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o f0G48k.pth"111      ],112      "metadata": {113        "id": "UG3XpUwEomUz"114      },115      "execution_count": null,116      "outputs": []117    },118    {119      "cell_type": "code",120      "source": [121        "#@title 下载人声分离模型\n",122        "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/uvr5_weights/HP2-人声vocals+非人声instrumentals.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/uvr5_weights -o HP2-人声vocals+非人声instrumentals.pth\n",123        "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/uvr5_weights/HP5-主旋律人声vocals+其他instrumentals.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/uvr5_weights -o HP5-主旋律人声vocals+其他instrumentals.pth"124      ],125      "metadata": {126        "id": "HugjmZqZRuiF"127      },128      "execution_count": null,129      "outputs": []130    },131    {132      "cell_type": "code",133      "source": [134        "#@title 下载hubert_base\n",135        "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/hubert_base.pt -d /content/Retrieval-based-Voice-Conversion-WebUI -o hubert_base.pt"136      ],137      "metadata": {138        "id": "2RCaT9FTR0ej"139      },140      "execution_count": null,141      "outputs": []142    },143    {144      "cell_type": "code",145      "source": [146        "#@title 挂载谷歌云盘\n",147        "\n",148        "from google.colab import drive\n",149        "drive.mount('/content/drive')"150      ],151      "metadata": {152        "id": "jwu07JgqoFON"153      },154      "execution_count": null,155      "outputs": []156    },157    {158      "cell_type": "code",159      "source": [160        "#@title 从谷歌云盘加载打包好的数据集到/content/dataset\n",161        "\n",162        "#@markdown 数据集位置\n",163        "DATASET = \"/content/drive/MyDrive/dataset/lulu20230327_32k.zip\"  #@param {type:\"string\"}\n",164        "\n",165        "!mkdir -p /content/dataset\n",166        "!unzip -d /content/dataset -B {DATASET}"167      ],168      "metadata": {169        "id": "Mwk7Q0Loqzjx"170      },171      "execution_count": null,172      "outputs": []173    },174    {175      "cell_type": "code",176      "source": [177        "#@title 重命名数据集中的重名文件\n",178        "!ls -a /content/dataset/\n",179        "!rename 's/(\\w+)\\.(\\w+)~(\\d*)/$1_$3.$2/' /content/dataset/*.*~*"180      ],181      "metadata": {182        "id": "PDlFxWHWEynD"183      },184      "execution_count": null,185      "outputs": []186    },187    {188      "cell_type": "code",189      "source": [190        "#@title 启动web\n",191        "%cd /content/Retrieval-based-Voice-Conversion-WebUI\n",192        "# %load_ext tensorboard\n",193        "# %tensorboard --logdir /content/Retrieval-based-Voice-Conversion-WebUI/logs\n",194        "!python3 infer-web.py --colab --pycmd python3"195      ],196      "metadata": {197        "id": "7vh6vphDwO0b"198      },199      "execution_count": null,200      "outputs": []201    },202    {203      "cell_type": "code",204      "source": [205        "#@title 手动将训练后的模型文件备份到谷歌云盘\n",206        "#@markdown 需要自己查看logs文件夹下模型的文件名,手动修改下方命令末尾的文件名\n",207        "\n",208        "#@markdown 模型名\n",209        "MODELNAME = \"lulu\"  #@param {type:\"string\"}\n",210        "#@markdown 模型epoch\n",211        "MODELEPOCH = 9600  #@param {type:\"integer\"}\n",212        "\n",213        "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/G_{MODELEPOCH}.pth /content/drive/MyDrive/{MODELNAME}_D_{MODELEPOCH}.pth\n",214        "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/D_{MODELEPOCH}.pth /content/drive/MyDrive/{MODELNAME}_G_{MODELEPOCH}.pth\n",215        "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/added_*.index /content/drive/MyDrive/\n",216        "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/total_*.npy /content/drive/MyDrive/\n",217        "\n",218        "!cp /content/Retrieval-based-Voice-Conversion-WebUI/weights/{MODELNAME}.pth /content/drive/MyDrive/{MODELNAME}{MODELEPOCH}.pth"219      ],220      "metadata": {221        "id": "FgJuNeAwx5Y_"222      },223      "execution_count": null,224      "outputs": []225    },226    {227      "cell_type": "code",228      "source": [229        "#@title 从谷歌云盘恢复pth\n",230        "#@markdown 需要自己查看logs文件夹下模型的文件名,手动修改下方命令末尾的文件名\n",231        "\n",232        "#@markdown 模型名\n",233        "MODELNAME = \"lulu\"  #@param {type:\"string\"}\n",234        "#@markdown 模型epoch\n",235        "MODELEPOCH = 7500  #@param {type:\"integer\"}\n",236        "\n",237        "!mkdir -p /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}\n",238        "\n",239        "!cp /content/drive/MyDrive/{MODELNAME}_D_{MODELEPOCH}.pth /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/G_{MODELEPOCH}.pth\n",240        "!cp /content/drive/MyDrive/{MODELNAME}_G_{MODELEPOCH}.pth /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/D_{MODELEPOCH}.pth\n",241        "!cp /content/drive/MyDrive/*.index /content/\n",242        "!cp /content/drive/MyDrive/*.npy /content/\n",243        "!cp /content/drive/MyDrive/{MODELNAME}{MODELEPOCH}.pth /content/Retrieval-based-Voice-Conversion-WebUI/weights/{MODELNAME}.pth"244      ],245      "metadata": {246        "id": "OVQoLQJXS7WX"247      },248      "execution_count": null,249      "outputs": []250    },251    {252      "cell_type": "code",253      "source": [254        "#@title 手动预处理(不推荐)\n",255        "#@markdown 模型名\n",256        "MODELNAME = \"lulu\"  #@param {type:\"string\"}\n",257        "#@markdown 采样率\n",258        "BITRATE = 48000  #@param {type:\"integer\"}\n",259        "#@markdown 使用的进程数\n",260        "THREADCOUNT = 8  #@param {type:\"integer\"}\n",261        "\n",262        "!python3 trainset_preprocess_pipeline_print.py /content/dataset {BITRATE} {THREADCOUNT} logs/{MODELNAME} True\n"263      ],264      "metadata": {265        "id": "ZKAyuKb9J6dz"266      },267      "execution_count": null,268      "outputs": []269    },270    {271      "cell_type": "code",272      "source": [273        "#@title 手动提取特征(不推荐)\n",274        "#@markdown 模型名\n",275        "MODELNAME = \"lulu\"  #@param {type:\"string\"}\n",276        "#@markdown 使用的进程数\n",277        "THREADCOUNT = 8  #@param {type:\"integer\"}\n",278        "#@markdown 音高提取算法\n",279        "ALGO = \"harvest\"  #@param {type:\"string\"}\n",280        "\n",281        "!python3 extract_f0_print.py logs/{MODELNAME} {THREADCOUNT} {ALGO}\n",282        "\n",283        "!python3 extract_feature_print.py cpu 1 0 0 logs/{MODELNAME}\n"284      ],285      "metadata": {286        "id": "CrxJqzAUKmPJ"287      },288      "execution_count": null,289      "outputs": []290    },291    {292      "cell_type": "code",293      "source": [294        "#@title 手动训练(不推荐)\n",295        "#@markdown 模型名\n",296        "MODELNAME = \"lulu\"  #@param {type:\"string\"}\n",297        "#@markdown 使用的GPU\n",298        "USEGPU = \"0\"  #@param {type:\"string\"}\n",299        "#@markdown 批大小\n",300        "BATCHSIZE = 32  #@param {type:\"integer\"}\n",301        "#@markdown 停止的epoch\n",302        "MODELEPOCH = 3200  #@param {type:\"integer\"}\n",303        "#@markdown 保存epoch间隔\n",304        "EPOCHSAVE = 100  #@param {type:\"integer\"}\n",305        "#@markdown 采样率\n",306        "MODELSAMPLE = \"48k\"  #@param {type:\"string\"}\n",307        "#@markdown 是否缓存训练集\n",308        "CACHEDATA = 1  #@param {type:\"integer\"}\n",309        "#@markdown 是否仅保存最新的ckpt文件\n",310        "ONLYLATEST = 0  #@param {type:\"integer\"}\n",311        "\n",312        "!python3 train_nsf_sim_cache_sid_load_pretrain.py -e lulu -sr {MODELSAMPLE} -f0 1 -bs {BATCHSIZE} -g {USEGPU} -te {MODELEPOCH} -se {EPOCHSAVE} -pg pretrained/f0G{MODELSAMPLE}.pth -pd pretrained/f0D{MODELSAMPLE}.pth -l {ONLYLATEST} -c {CACHEDATA}\n"313      ],314      "metadata": {315        "id": "IMLPLKOaKj58"316      },317      "execution_count": null,318      "outputs": []319    },320    {321      "cell_type": "code",322      "source": [323        "#@title 删除其它pth,只留选中的(慎点,仔细看代码)\n",324        "#@markdown 模型名\n",325        "MODELNAME = \"lulu\"  #@param {type:\"string\"}\n",326        "#@markdown 选中模型epoch\n",327        "MODELEPOCH = 9600  #@param {type:\"integer\"}\n",328        "\n",329        "!echo \"备份选中的模型。。。\"\n",330        "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/G_{MODELEPOCH}.pth /content/{MODELNAME}_D_{MODELEPOCH}.pth\n",331        "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/D_{MODELEPOCH}.pth /content/{MODELNAME}_G_{MODELEPOCH}.pth\n",332        "\n",333        "!echo \"正在删除。。。\"\n",334        "!ls /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}\n",335        "!rm /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/*.pth\n",336        "\n",337        "!echo \"恢复选中的模型。。。\"\n",338        "!mv /content/{MODELNAME}_D_{MODELEPOCH}.pth /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/G_{MODELEPOCH}.pth \n",339        "!mv /content/{MODELNAME}_G_{MODELEPOCH}.pth /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/D_{MODELEPOCH}.pth\n",340        "\n",341        "!echo \"删除完成\"\n",342        "!ls /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}"343      ],344      "metadata": {345        "id": "haYA81hySuDl"346      },347      "execution_count": null,348      "outputs": []349    },350    {351      "cell_type": "code",352      "source": [353        "#@title 清除项目下所有文件,只留选中的模型(慎点,仔细看代码)\n",354        "#@markdown 模型名\n",355        "MODELNAME = \"lulu\"  #@param {type:\"string\"}\n",356        "#@markdown 选中模型epoch\n",357        "MODELEPOCH = 9600  #@param {type:\"integer\"}\n",358        "\n",359        "!echo \"备份选中的模型。。。\"\n",360        "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/G_{MODELEPOCH}.pth /content/{MODELNAME}_D_{MODELEPOCH}.pth\n",361        "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/D_{MODELEPOCH}.pth /content/{MODELNAME}_G_{MODELEPOCH}.pth\n",362        "\n",363        "!echo \"正在删除。。。\"\n",364        "!ls /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}\n",365        "!rm -rf /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/*\n",366        "\n",367        "!echo \"恢复选中的模型。。。\"\n",368        "!mv /content/{MODELNAME}_D_{MODELEPOCH}.pth /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/G_{MODELEPOCH}.pth \n",369        "!mv /content/{MODELNAME}_G_{MODELEPOCH}.pth /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/D_{MODELEPOCH}.pth\n",370        "\n",371        "!echo \"删除完成\"\n",372        "!ls /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}"373      ],374      "metadata": {375        "id": "QhSiPTVPoIRh"376      },377      "execution_count": null,378      "outputs": []379    }380  ]381}