mirror of
https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI.git
synced 2025-04-15 00:58:58 +08:00
Format code (#526)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
parent
f92a923487
commit
a7647e4094
@ -64,8 +64,11 @@ def readwave(wav_path, normalize=False):
|
|||||||
# HuBERT model
|
# HuBERT model
|
||||||
printt("load model(s) from {}".format(model_path))
|
printt("load model(s) from {}".format(model_path))
|
||||||
# if hubert model is exist
|
# if hubert model is exist
|
||||||
if (os.access(model_path, os.F_OK) == False):
|
if os.access(model_path, os.F_OK) == False:
|
||||||
printt("Error: Extracting is shut down because %s does not exist, you may download it from https://huggingface.co/lj1995/VoiceConversionWebUI/tree/main" % model_path)
|
printt(
|
||||||
|
"Error: Extracting is shut down because %s does not exist, you may download it from https://huggingface.co/lj1995/VoiceConversionWebUI/tree/main"
|
||||||
|
% model_path
|
||||||
|
)
|
||||||
exit(0)
|
exit(0)
|
||||||
models, saved_cfg, task = checkpoint_utils.load_model_ensemble_and_task(
|
models, saved_cfg, task = checkpoint_utils.load_model_ensemble_and_task(
|
||||||
[model_path],
|
[model_path],
|
||||||
|
20
gui.py
20
gui.py
@ -469,21 +469,21 @@ class GUI:
|
|||||||
self.flag_vc = False
|
self.flag_vc = False
|
||||||
|
|
||||||
def set_values(self, values):
|
def set_values(self, values):
|
||||||
if(len(values["pth_path"].strip()) == 0):
|
if len(values["pth_path"].strip()) == 0:
|
||||||
sg.popup(i18n('请选择pth文件'))
|
sg.popup(i18n("请选择pth文件"))
|
||||||
return False
|
return False
|
||||||
if(len(values["index_path"].strip()) == 0):
|
if len(values["index_path"].strip()) == 0:
|
||||||
sg.popup(i18n('请选择index文件'))
|
sg.popup(i18n("请选择index文件"))
|
||||||
return False
|
return False
|
||||||
pattern = re.compile("[^\x00-\x7F]+")
|
pattern = re.compile("[^\x00-\x7F]+")
|
||||||
if(pattern.findall(values["hubert_path"])):
|
if pattern.findall(values["hubert_path"]):
|
||||||
sg.popup(i18n('hubert模型路径不可包含中文'))
|
sg.popup(i18n("hubert模型路径不可包含中文"))
|
||||||
return False
|
return False
|
||||||
if(pattern.findall(values["pth_path"])):
|
if pattern.findall(values["pth_path"]):
|
||||||
sg.popup(i18n('pth文件路径不可包含中文'))
|
sg.popup(i18n("pth文件路径不可包含中文"))
|
||||||
return False
|
return False
|
||||||
if(pattern.findall(values["index_path"])):
|
if pattern.findall(values["index_path"]):
|
||||||
sg.popup(i18n('index文件路径不可包含中文'))
|
sg.popup(i18n("index文件路径不可包含中文"))
|
||||||
return False
|
return False
|
||||||
self.set_devices(values["sg_input_device"], values["sg_output_device"])
|
self.set_devices(values["sg_input_device"], values["sg_output_device"])
|
||||||
self.config.hubert_path = os.path.join(current_dir, "hubert_base.pt")
|
self.config.hubert_path = os.path.join(current_dir, "hubert_base.pt")
|
||||||
|
67
infer-web.py
67
infer-web.py
@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
now_dir = os.getcwd()
|
now_dir = os.getcwd()
|
||||||
sys.path.append(now_dir)
|
sys.path.append(now_dir)
|
||||||
import traceback, pdb
|
import traceback, pdb
|
||||||
@ -434,11 +435,23 @@ def get_vc(sid,to_return_protect0,to_return_protect1):
|
|||||||
tgt_sr = cpt["config"][-1]
|
tgt_sr = cpt["config"][-1]
|
||||||
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk
|
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk
|
||||||
if_f0 = cpt.get("f0", 1)
|
if_f0 = cpt.get("f0", 1)
|
||||||
if(if_f0==0):
|
if if_f0 == 0:
|
||||||
to_return_protect0=to_return_protect1={"visible": False, "value": 0.5, "__type__": "update"}
|
to_return_protect0 = to_return_protect1 = {
|
||||||
|
"visible": False,
|
||||||
|
"value": 0.5,
|
||||||
|
"__type__": "update",
|
||||||
|
}
|
||||||
else:
|
else:
|
||||||
to_return_protect0 ={"visible": True, "value": to_return_protect0, "__type__": "update"}
|
to_return_protect0 = {
|
||||||
to_return_protect1 ={"visible": True, "value": to_return_protect1, "__type__": "update"}
|
"visible": True,
|
||||||
|
"value": to_return_protect0,
|
||||||
|
"__type__": "update",
|
||||||
|
}
|
||||||
|
to_return_protect1 = {
|
||||||
|
"visible": True,
|
||||||
|
"value": to_return_protect1,
|
||||||
|
"__type__": "update",
|
||||||
|
}
|
||||||
version = cpt.get("version", "v1")
|
version = cpt.get("version", "v1")
|
||||||
if version == "v1":
|
if version == "v1":
|
||||||
if if_f0 == 1:
|
if if_f0 == 1:
|
||||||
@ -459,7 +472,11 @@ def get_vc(sid,to_return_protect0,to_return_protect1):
|
|||||||
net_g = net_g.float()
|
net_g = net_g.float()
|
||||||
vc = VC(tgt_sr, config)
|
vc = VC(tgt_sr, config)
|
||||||
n_spk = cpt["config"][-3]
|
n_spk = cpt["config"][-3]
|
||||||
return {"visible": True, "maximum": n_spk, "__type__": "update"},to_return_protect0,to_return_protect1
|
return (
|
||||||
|
{"visible": True, "maximum": n_spk, "__type__": "update"},
|
||||||
|
to_return_protect0,
|
||||||
|
to_return_protect1,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def change_choices():
|
def change_choices():
|
||||||
@ -665,8 +682,13 @@ def change_sr2(sr2, if_f0_3, version19):
|
|||||||
|
|
||||||
def change_version19(sr2, if_f0_3, version19):
|
def change_version19(sr2, if_f0_3, version19):
|
||||||
path_str = "" if version19 == "v1" else "_v2"
|
path_str = "" if version19 == "v1" else "_v2"
|
||||||
if(sr2=="32k"and version19=="v1"):sr2="40k"
|
if sr2 == "32k" and version19 == "v1":
|
||||||
to_return_sr2= {"choices": ["40k","48k"], "__type__": "update"} if version19=="v1"else {"choices": ["32k","40k","48k"], "__type__": "update"}
|
sr2 = "40k"
|
||||||
|
to_return_sr2 = (
|
||||||
|
{"choices": ["40k", "48k"], "__type__": "update"}
|
||||||
|
if version19 == "v1"
|
||||||
|
else {"choices": ["32k", "40k", "48k"], "__type__": "update"}
|
||||||
|
)
|
||||||
f0_str = "f0" if if_f0_3 else ""
|
f0_str = "f0" if if_f0_3 else ""
|
||||||
if_pretrained_generator_exist = os.access(
|
if_pretrained_generator_exist = os.access(
|
||||||
"pretrained%s/%sG%s.pth" % (path_str, f0_str, sr2), os.F_OK
|
"pretrained%s/%sG%s.pth" % (path_str, f0_str, sr2), os.F_OK
|
||||||
@ -691,7 +713,7 @@ def change_version19(sr2, if_f0_3, version19):
|
|||||||
"pretrained%s/%sD%s.pth" % (path_str, f0_str, sr2)
|
"pretrained%s/%sD%s.pth" % (path_str, f0_str, sr2)
|
||||||
if if_pretrained_discriminator_exist
|
if if_pretrained_discriminator_exist
|
||||||
else "",
|
else "",
|
||||||
to_return_sr2
|
to_return_sr2,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -893,12 +915,22 @@ def train_index(exp_dir1, version19):
|
|||||||
big_npy_idx = np.arange(big_npy.shape[0])
|
big_npy_idx = np.arange(big_npy.shape[0])
|
||||||
np.random.shuffle(big_npy_idx)
|
np.random.shuffle(big_npy_idx)
|
||||||
big_npy = big_npy[big_npy_idx]
|
big_npy = big_npy[big_npy_idx]
|
||||||
if(big_npy.shape[0]>2e5):
|
if big_npy.shape[0] > 2e5:
|
||||||
# if(1):
|
# if(1):
|
||||||
infos.append("Trying doing kmeans %s shape to 10k centers." % big_npy.shape[0])
|
infos.append("Trying doing kmeans %s shape to 10k centers." % big_npy.shape[0])
|
||||||
yield "\n".join(infos)
|
yield "\n".join(infos)
|
||||||
try:
|
try:
|
||||||
big_npy = MiniBatchKMeans(n_clusters=10000, verbose=True, batch_size=256 * config.n_cpu, compute_labels=False, init="random").fit(big_npy).cluster_centers_
|
big_npy = (
|
||||||
|
MiniBatchKMeans(
|
||||||
|
n_clusters=10000,
|
||||||
|
verbose=True,
|
||||||
|
batch_size=256 * config.n_cpu,
|
||||||
|
compute_labels=False,
|
||||||
|
init="random",
|
||||||
|
)
|
||||||
|
.fit(big_npy)
|
||||||
|
.cluster_centers_
|
||||||
|
)
|
||||||
except:
|
except:
|
||||||
info = traceback.format_exc()
|
info = traceback.format_exc()
|
||||||
print(info)
|
print(info)
|
||||||
@ -1147,13 +1179,23 @@ def train1key(
|
|||||||
np.random.shuffle(big_npy_idx)
|
np.random.shuffle(big_npy_idx)
|
||||||
big_npy = big_npy[big_npy_idx]
|
big_npy = big_npy[big_npy_idx]
|
||||||
|
|
||||||
if(big_npy.shape[0]>2e5):
|
if big_npy.shape[0] > 2e5:
|
||||||
# if(1):
|
# if(1):
|
||||||
info = "Trying doing kmeans %s shape to 10k centers." % big_npy.shape[0]
|
info = "Trying doing kmeans %s shape to 10k centers." % big_npy.shape[0]
|
||||||
print(info)
|
print(info)
|
||||||
yield get_info_str(info)
|
yield get_info_str(info)
|
||||||
try:
|
try:
|
||||||
big_npy = MiniBatchKMeans(n_clusters=10000, verbose=True, batch_size=256 * config.n_cpu, compute_labels=False, init="random").fit(big_npy).cluster_centers_
|
big_npy = (
|
||||||
|
MiniBatchKMeans(
|
||||||
|
n_clusters=10000,
|
||||||
|
verbose=True,
|
||||||
|
batch_size=256 * config.n_cpu,
|
||||||
|
compute_labels=False,
|
||||||
|
init="random",
|
||||||
|
)
|
||||||
|
.fit(big_npy)
|
||||||
|
.cluster_centers_
|
||||||
|
)
|
||||||
except:
|
except:
|
||||||
info = traceback.format_exc()
|
info = traceback.format_exc()
|
||||||
print(info)
|
print(info)
|
||||||
@ -1207,7 +1249,6 @@ def change_info_(ckpt_path):
|
|||||||
return {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}
|
return {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def export_onnx(ModelPath, ExportedPath):
|
def export_onnx(ModelPath, ExportedPath):
|
||||||
cpt = torch.load(ModelPath, map_location="cpu")
|
cpt = torch.load(ModelPath, map_location="cpu")
|
||||||
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0]
|
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0]
|
||||||
|
@ -3,6 +3,7 @@ import librosa
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import soundfile
|
import soundfile
|
||||||
|
|
||||||
|
|
||||||
class ContentVec:
|
class ContentVec:
|
||||||
def __init__(self, vec_path="pretrained/vec-768-layer-12.onnx", device=None):
|
def __init__(self, vec_path="pretrained/vec-768-layer-12.onnx", device=None):
|
||||||
print("load model(s) from {}".format(vec_path))
|
print("load model(s) from {}".format(vec_path))
|
||||||
|
@ -192,7 +192,6 @@ def run(rank, n_gpus, hps):
|
|||||||
epoch_str = 1
|
epoch_str = 1
|
||||||
global_step = 0
|
global_step = 0
|
||||||
if hps.pretrainG != "":
|
if hps.pretrainG != "":
|
||||||
|
|
||||||
if rank == 0:
|
if rank == 0:
|
||||||
logger.info("loaded pretrained %s" % (hps.pretrainG))
|
logger.info("loaded pretrained %s" % (hps.pretrainG))
|
||||||
print(
|
print(
|
||||||
@ -201,7 +200,6 @@ def run(rank, n_gpus, hps):
|
|||||||
)
|
)
|
||||||
) ##测试不加载优化器
|
) ##测试不加载优化器
|
||||||
if hps.pretrainD != "":
|
if hps.pretrainD != "":
|
||||||
|
|
||||||
if rank == 0:
|
if rank == 0:
|
||||||
logger.info("loaded pretrained %s" % (hps.pretrainD))
|
logger.info("loaded pretrained %s" % (hps.pretrainD))
|
||||||
print(
|
print(
|
||||||
|
@ -54,7 +54,7 @@ class PreProcess:
|
|||||||
|
|
||||||
def norm_write(self, tmp_audio, idx0, idx1):
|
def norm_write(self, tmp_audio, idx0, idx1):
|
||||||
tmp_max = np.abs(tmp_audio).max()
|
tmp_max = np.abs(tmp_audio).max()
|
||||||
if(tmp_max>2.5):
|
if tmp_max > 2.5:
|
||||||
print("%s-%s-%s-filtered" % (idx0, idx1, tmp_max))
|
print("%s-%s-%s-filtered" % (idx0, idx1, tmp_max))
|
||||||
return
|
return
|
||||||
tmp_audio = (tmp_audio / tmp_max * (self.max * self.alpha)) + (
|
tmp_audio = (tmp_audio / tmp_max * (self.max * self.alpha)) + (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user