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
|
||||
printt("load model(s) from {}".format(model_path))
|
||||
# if hubert model is exist
|
||||
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)
|
||||
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
|
||||
)
|
||||
exit(0)
|
||||
models, saved_cfg, task = checkpoint_utils.load_model_ensemble_and_task(
|
||||
[model_path],
|
||||
|
20
gui.py
20
gui.py
@ -469,21 +469,21 @@ class GUI:
|
||||
self.flag_vc = False
|
||||
|
||||
def set_values(self, values):
|
||||
if(len(values["pth_path"].strip()) == 0):
|
||||
sg.popup(i18n('请选择pth文件'))
|
||||
if len(values["pth_path"].strip()) == 0:
|
||||
sg.popup(i18n("请选择pth文件"))
|
||||
return False
|
||||
if(len(values["index_path"].strip()) == 0):
|
||||
sg.popup(i18n('请选择index文件'))
|
||||
if len(values["index_path"].strip()) == 0:
|
||||
sg.popup(i18n("请选择index文件"))
|
||||
return False
|
||||
pattern = re.compile("[^\x00-\x7F]+")
|
||||
if(pattern.findall(values["hubert_path"])):
|
||||
sg.popup(i18n('hubert模型路径不可包含中文'))
|
||||
if pattern.findall(values["hubert_path"]):
|
||||
sg.popup(i18n("hubert模型路径不可包含中文"))
|
||||
return False
|
||||
if(pattern.findall(values["pth_path"])):
|
||||
sg.popup(i18n('pth文件路径不可包含中文'))
|
||||
if pattern.findall(values["pth_path"]):
|
||||
sg.popup(i18n("pth文件路径不可包含中文"))
|
||||
return False
|
||||
if(pattern.findall(values["index_path"])):
|
||||
sg.popup(i18n('index文件路径不可包含中文'))
|
||||
if pattern.findall(values["index_path"]):
|
||||
sg.popup(i18n("index文件路径不可包含中文"))
|
||||
return False
|
||||
self.set_devices(values["sg_input_device"], values["sg_output_device"])
|
||||
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 shutil
|
||||
import sys
|
||||
|
||||
now_dir = os.getcwd()
|
||||
sys.path.append(now_dir)
|
||||
import traceback, pdb
|
||||
@ -434,11 +435,23 @@ def get_vc(sid,to_return_protect0,to_return_protect1):
|
||||
tgt_sr = cpt["config"][-1]
|
||||
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk
|
||||
if_f0 = cpt.get("f0", 1)
|
||||
if(if_f0==0):
|
||||
to_return_protect0=to_return_protect1={"visible": False, "value": 0.5, "__type__": "update"}
|
||||
if if_f0 == 0:
|
||||
to_return_protect0 = to_return_protect1 = {
|
||||
"visible": False,
|
||||
"value": 0.5,
|
||||
"__type__": "update",
|
||||
}
|
||||
else:
|
||||
to_return_protect0 ={"visible": True, "value": to_return_protect0, "__type__": "update"}
|
||||
to_return_protect1 ={"visible": True, "value": to_return_protect1, "__type__": "update"}
|
||||
to_return_protect0 = {
|
||||
"visible": True,
|
||||
"value": to_return_protect0,
|
||||
"__type__": "update",
|
||||
}
|
||||
to_return_protect1 = {
|
||||
"visible": True,
|
||||
"value": to_return_protect1,
|
||||
"__type__": "update",
|
||||
}
|
||||
version = cpt.get("version", "v1")
|
||||
if version == "v1":
|
||||
if if_f0 == 1:
|
||||
@ -459,7 +472,11 @@ def get_vc(sid,to_return_protect0,to_return_protect1):
|
||||
net_g = net_g.float()
|
||||
vc = VC(tgt_sr, config)
|
||||
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():
|
||||
@ -665,8 +682,13 @@ def change_sr2(sr2, if_f0_3, version19):
|
||||
|
||||
def change_version19(sr2, if_f0_3, version19):
|
||||
path_str = "" if version19 == "v1" else "_v2"
|
||||
if(sr2=="32k"and version19=="v1"):sr2="40k"
|
||||
to_return_sr2= {"choices": ["40k","48k"], "__type__": "update"} if version19=="v1"else {"choices": ["32k","40k","48k"], "__type__": "update"}
|
||||
if sr2 == "32k" and version19 == "v1":
|
||||
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 ""
|
||||
if_pretrained_generator_exist = os.access(
|
||||
"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)
|
||||
if if_pretrained_discriminator_exist
|
||||
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])
|
||||
np.random.shuffle(big_npy_idx)
|
||||
big_npy = big_npy[big_npy_idx]
|
||||
if(big_npy.shape[0]>2e5):
|
||||
if big_npy.shape[0] > 2e5:
|
||||
# if(1):
|
||||
infos.append("Trying doing kmeans %s shape to 10k centers." % big_npy.shape[0])
|
||||
yield "\n".join(infos)
|
||||
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:
|
||||
info = traceback.format_exc()
|
||||
print(info)
|
||||
@ -1147,13 +1179,23 @@ def train1key(
|
||||
np.random.shuffle(big_npy_idx)
|
||||
big_npy = big_npy[big_npy_idx]
|
||||
|
||||
if(big_npy.shape[0]>2e5):
|
||||
if big_npy.shape[0] > 2e5:
|
||||
# if(1):
|
||||
info = "Trying doing kmeans %s shape to 10k centers." % big_npy.shape[0]
|
||||
print(info)
|
||||
yield get_info_str(info)
|
||||
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:
|
||||
info = traceback.format_exc()
|
||||
print(info)
|
||||
@ -1207,7 +1249,6 @@ def change_info_(ckpt_path):
|
||||
return {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}
|
||||
|
||||
|
||||
|
||||
def export_onnx(ModelPath, ExportedPath):
|
||||
cpt = torch.load(ModelPath, map_location="cpu")
|
||||
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0]
|
||||
|
@ -3,6 +3,7 @@ import librosa
|
||||
import numpy as np
|
||||
import soundfile
|
||||
|
||||
|
||||
class ContentVec:
|
||||
def __init__(self, vec_path="pretrained/vec-768-layer-12.onnx", device=None):
|
||||
print("load model(s) from {}".format(vec_path))
|
||||
|
@ -192,7 +192,6 @@ def run(rank, n_gpus, hps):
|
||||
epoch_str = 1
|
||||
global_step = 0
|
||||
if hps.pretrainG != "":
|
||||
|
||||
if rank == 0:
|
||||
logger.info("loaded pretrained %s" % (hps.pretrainG))
|
||||
print(
|
||||
@ -201,7 +200,6 @@ def run(rank, n_gpus, hps):
|
||||
)
|
||||
) ##测试不加载优化器
|
||||
if hps.pretrainD != "":
|
||||
|
||||
if rank == 0:
|
||||
logger.info("loaded pretrained %s" % (hps.pretrainD))
|
||||
print(
|
||||
|
@ -54,7 +54,7 @@ class PreProcess:
|
||||
|
||||
def norm_write(self, tmp_audio, idx0, idx1):
|
||||
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))
|
||||
return
|
||||
tmp_audio = (tmp_audio / tmp_max * (self.max * self.alpha)) + (
|
||||
|
Loading…
x
Reference in New Issue
Block a user