mirror of
https://github.com/jasonppy/VoiceCraft.git
synced 2026-04-03 09:46:45 +02:00
hf model download
This commit is contained in:
@@ -200,25 +200,33 @@
|
||||
"mask_interval = torch.LongTensor(mask_interval) # [M,2], M==1 for now\n",
|
||||
"\n",
|
||||
"# load model, tokenizer, and other necessary files\n",
|
||||
"voicecraft_name=\"giga330M.pth\"\n",
|
||||
"ckpt_fn =f\"./pretrained_models/{voicecraft_name}\"\n",
|
||||
"voicecraft_name=\"giga330M.pth\" # or gigaHalfLibri330M_TTSEnhanced_max16s.pth, giga830M.pth\n",
|
||||
"\n",
|
||||
"# the new way of loading the model, with huggingface, recommended\n",
|
||||
"from models.voicecraft import VoiceCraftHF\n",
|
||||
"model = VoiceCraftHF.from_pretrained(f\"pyp1/VoiceCraft_{voicecraft_name.replace('.pth', '')}\")\n",
|
||||
"phn2num = model.args.phn2num\n",
|
||||
"config = vars(model.args)\n",
|
||||
"model.to(device)\n",
|
||||
"\n",
|
||||
"# # the old way of loading the model\n",
|
||||
"# from models import voicecraft\n",
|
||||
"# filepath = hf_hub_download(repo_id=\"pyp1/VoiceCraft\", filename=voicecraft_name, repo_type=\"model\")\n",
|
||||
"# ckpt = torch.load(filepath, map_location=\"cpu\")\n",
|
||||
"# model = voicecraft.VoiceCraft(ckpt[\"config\"])\n",
|
||||
"# model.load_state_dict(ckpt[\"model\"])\n",
|
||||
"# config = vars(model.args)\n",
|
||||
"# phn2num = ckpt[\"phn2num\"]\n",
|
||||
"# model.to(device)\n",
|
||||
"# model.eval()\n",
|
||||
"\n",
|
||||
"encodec_fn = \"./pretrained_models/encodec_4cb2048_giga.th\"\n",
|
||||
"if not os.path.exists(ckpt_fn):\n",
|
||||
" os.system(f\"wget https://huggingface.co/pyp1/VoiceCraft/resolve/main/{voicecraft_name}\\?download\\=true\")\n",
|
||||
" os.system(f\"mv {voicecraft_name}\\?download\\=true ./pretrained_models/{voicecraft_name}\")\n",
|
||||
"if not os.path.exists(encodec_fn):\n",
|
||||
" os.system(f\"wget https://huggingface.co/pyp1/VoiceCraft/resolve/main/encodec_4cb2048_giga.th\")\n",
|
||||
" os.system(f\"mv encodec_4cb2048_giga.th ./pretrained_models/encodec_4cb2048_giga.th\")\n",
|
||||
"ckpt = torch.load(ckpt_fn, map_location=\"cpu\")\n",
|
||||
"model = voicecraft.VoiceCraft(ckpt[\"config\"])\n",
|
||||
"model.load_state_dict(ckpt[\"model\"])\n",
|
||||
"model.to(device)\n",
|
||||
"model.eval()\n",
|
||||
"\n",
|
||||
"phn2num = ckpt['phn2num']\n",
|
||||
"audio_tokenizer = AudioTokenizer(signature=encodec_fn) # will also put the neural codec model on gpu\n",
|
||||
"\n",
|
||||
"text_tokenizer = TextTokenizer(backend=\"espeak\")\n",
|
||||
"audio_tokenizer = AudioTokenizer(signature=encodec_fn) # will also put the neural codec model on gpu\n",
|
||||
"\n",
|
||||
"# run the model to get the output\n",
|
||||
"from inference_speech_editing_scale import inference_one_sample\n",
|
||||
|
||||
Reference in New Issue
Block a user