CoolFace
Apppublic

soiz1/Retrieval-based-Voice-Conversion-WebUI

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