mirror of
https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI.git
synced 2026-01-19 18:41:52 +00:00
Format code (#989)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
7293002f53
commit
76b67842ba
112
infer-web.py
112
infer-web.py
@@ -43,9 +43,7 @@ logging.getLogger("numba").setLevel(logging.WARNING)
|
||||
now_dir = os.getcwd()
|
||||
tmp = os.path.join(now_dir, "TEMP")
|
||||
shutil.rmtree(tmp, ignore_errors=True)
|
||||
shutil.rmtree(
|
||||
"%s/runtime/Lib/site-packages/infer_pack" % (now_dir), ignore_errors=True
|
||||
)
|
||||
shutil.rmtree("%s/runtime/Lib/site-packages/infer_pack" % (now_dir), ignore_errors=True)
|
||||
shutil.rmtree("%s/runtime/Lib/site-packages/uvr5_pack" % (now_dir), ignore_errors=True)
|
||||
os.makedirs(tmp, exist_ok=True)
|
||||
os.makedirs(os.path.join(now_dir, "logs"), exist_ok=True)
|
||||
@@ -56,12 +54,14 @@ torch.manual_seed(114514)
|
||||
|
||||
|
||||
config = Config()
|
||||
if(config.dml==True):
|
||||
if config.dml == True:
|
||||
|
||||
def forward_dml(ctx, x, scale):
|
||||
ctx.scale = scale
|
||||
res = x.clone().detach()
|
||||
return res
|
||||
fairseq.modules.grad_multiply.GradMultiply.forward=forward_dml
|
||||
|
||||
fairseq.modules.grad_multiply.GradMultiply.forward = forward_dml
|
||||
i18n = I18nAuto()
|
||||
i18n.print()
|
||||
# 判断是否有能用来训练和加速推理的N卡
|
||||
@@ -451,15 +451,21 @@ def get_vc(sid, to_return_protect0, to_return_protect1):
|
||||
del net_g, cpt
|
||||
if torch.cuda.is_available():
|
||||
torch.cuda.empty_cache()
|
||||
return {"visible": False, "__type__": "update"},{
|
||||
"visible": True,
|
||||
"value": to_return_protect0,
|
||||
"__type__": "update",
|
||||
},{
|
||||
"visible": True,
|
||||
"value": to_return_protect1,
|
||||
"__type__": "update",
|
||||
},"",""
|
||||
return (
|
||||
{"visible": False, "__type__": "update"},
|
||||
{
|
||||
"visible": True,
|
||||
"value": to_return_protect0,
|
||||
"__type__": "update",
|
||||
},
|
||||
{
|
||||
"visible": True,
|
||||
"value": to_return_protect1,
|
||||
"__type__": "update",
|
||||
},
|
||||
"",
|
||||
"",
|
||||
)
|
||||
person = "%s/%s" % (weight_root, sid)
|
||||
print("loading %s" % person)
|
||||
|
||||
@@ -504,15 +510,13 @@ 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]
|
||||
index={
|
||||
"value":get_index_path_from_model(sid),
|
||||
"__type__": "update"
|
||||
}
|
||||
index = {"value": get_index_path_from_model(sid), "__type__": "update"}
|
||||
return (
|
||||
{"visible": True, "maximum": n_spk, "__type__": "update"},
|
||||
to_return_protect0,
|
||||
to_return_protect1,
|
||||
index,index
|
||||
index,
|
||||
index,
|
||||
)
|
||||
|
||||
|
||||
@@ -629,7 +633,7 @@ def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir, version19, gpus_rmvp
|
||||
),
|
||||
).start()
|
||||
else:
|
||||
if(gpus_rmvpe!="-"):
|
||||
if gpus_rmvpe != "-":
|
||||
gpus_rmvpe = gpus_rmvpe.split("-")
|
||||
leng = len(gpus_rmvpe)
|
||||
ps = []
|
||||
@@ -647,7 +651,7 @@ def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir, version19, gpus_rmvp
|
||||
###煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
|
||||
done = [False]
|
||||
threading.Thread(
|
||||
target=if_done_multi,#
|
||||
target=if_done_multi, #
|
||||
args=(
|
||||
done,
|
||||
ps,
|
||||
@@ -655,7 +659,8 @@ def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir, version19, gpus_rmvp
|
||||
).start()
|
||||
else:
|
||||
cmd = config.python_cmd + ' extract_f0_rmvpe_dml.py "%s/logs/%s" ' % (
|
||||
now_dir, exp_dir
|
||||
now_dir,
|
||||
exp_dir,
|
||||
)
|
||||
print(cmd)
|
||||
p = Popen(
|
||||
@@ -671,9 +676,7 @@ def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir, version19, gpus_rmvp
|
||||
sleep(1)
|
||||
if done[0]:
|
||||
break
|
||||
with open(
|
||||
"%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r"
|
||||
) as f:
|
||||
with open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r") as f:
|
||||
log = f.read()
|
||||
print(log)
|
||||
yield log
|
||||
@@ -971,7 +974,7 @@ def click_train(
|
||||
# but4.click(train_index, [exp_dir1], info3)
|
||||
def train_index(exp_dir1, version19):
|
||||
# exp_dir = "%s/logs/%s" % (now_dir, exp_dir1)
|
||||
exp_dir = "logs/%s" % ( exp_dir1)
|
||||
exp_dir = "logs/%s" % (exp_dir1)
|
||||
os.makedirs(exp_dir, exist_ok=True)
|
||||
feature_dir = (
|
||||
"%s/3_feature256" % (exp_dir)
|
||||
@@ -1115,17 +1118,21 @@ def train1key(
|
||||
p = Popen(cmd, shell=True, cwd=now_dir)
|
||||
p.wait()
|
||||
else:
|
||||
if(gpus_rmvpe!="-"):
|
||||
if gpus_rmvpe != "-":
|
||||
gpus_rmvpe = gpus_rmvpe.split("-")
|
||||
leng = len(gpus_rmvpe)
|
||||
ps = []
|
||||
for idx, n_g in enumerate(gpus_rmvpe):
|
||||
cmd = config.python_cmd + ' extract_f0_rmvpe.py %s %s %s "%s" %s ' % (
|
||||
leng,
|
||||
idx,
|
||||
n_g,
|
||||
model_log_dir,
|
||||
config.is_half,
|
||||
cmd = (
|
||||
config.python_cmd
|
||||
+ ' extract_f0_rmvpe.py %s %s %s "%s" %s '
|
||||
% (
|
||||
leng,
|
||||
idx,
|
||||
n_g,
|
||||
model_log_dir,
|
||||
config.is_half,
|
||||
)
|
||||
)
|
||||
yield get_info_str(cmd)
|
||||
p = Popen(
|
||||
@@ -1134,7 +1141,7 @@ def train1key(
|
||||
ps.append(p)
|
||||
for p in ps:
|
||||
p.wait()
|
||||
else:#dml
|
||||
else: # dml
|
||||
cmd = config.python_cmd + ' extract_f0_rmvpe_dml.py "%s" ' % (
|
||||
model_log_dir
|
||||
)
|
||||
@@ -1316,7 +1323,17 @@ def train1key(
|
||||
index_ivf = faiss.extract_index_ivf(index) #
|
||||
index_ivf.nprobe = 1
|
||||
index.train(big_npy)
|
||||
faiss.write_index(index,"%s/trained_IVF%s_Flat_nprobe_%s_%s_%s.index"% (model_log_dir.replace(now_dir+"/",""), n_ivf, index_ivf.nprobe, exp_dir1, version19))
|
||||
faiss.write_index(
|
||||
index,
|
||||
"%s/trained_IVF%s_Flat_nprobe_%s_%s_%s.index"
|
||||
% (
|
||||
model_log_dir.replace(now_dir + "/", ""),
|
||||
n_ivf,
|
||||
index_ivf.nprobe,
|
||||
exp_dir1,
|
||||
version19,
|
||||
),
|
||||
)
|
||||
yield get_info_str("adding index")
|
||||
batch_size_add = 8192
|
||||
for i in range(0, big_npy.shape[0], batch_size_add):
|
||||
@@ -1324,7 +1341,13 @@ def train1key(
|
||||
faiss.write_index(
|
||||
index,
|
||||
"%s/added_IVF%s_Flat_nprobe_%s_%s_%s.index"
|
||||
% (model_log_dir.replace(now_dir+"/",""), n_ivf, index_ivf.nprobe, exp_dir1, version19),
|
||||
% (
|
||||
model_log_dir.replace(now_dir + "/", ""),
|
||||
n_ivf,
|
||||
index_ivf.nprobe,
|
||||
exp_dir1,
|
||||
version19,
|
||||
),
|
||||
)
|
||||
yield get_info_str(
|
||||
"成功构建索引, added_IVF%s_Flat_nprobe_%s_%s_%s.index"
|
||||
@@ -1351,6 +1374,8 @@ def change_info_(ckpt_path):
|
||||
|
||||
|
||||
F0GPUVisible = config.dml == False
|
||||
|
||||
|
||||
def change_f0_method(f0method8):
|
||||
if f0method8 == "rmvpe_gpu":
|
||||
visible = F0GPUVisible
|
||||
@@ -1450,7 +1475,9 @@ with gr.Blocks(title="RVC WebUI") as app:
|
||||
label=i18n(
|
||||
"选择音高提取算法,输入歌声可用pm提速,harvest低音好但巨慢无比,crepe效果好但吃GPU,rmvpe效果最好且微吃GPU"
|
||||
),
|
||||
choices=["pm", "harvest", "crepe", "rmvpe"]if config.dml==False else ["pm", "harvest", "rmvpe"],
|
||||
choices=["pm", "harvest", "crepe", "rmvpe"]
|
||||
if config.dml == False
|
||||
else ["pm", "harvest", "rmvpe"],
|
||||
value="pm",
|
||||
interactive=True,
|
||||
)
|
||||
@@ -1556,7 +1583,9 @@ with gr.Blocks(title="RVC WebUI") as app:
|
||||
label=i18n(
|
||||
"选择音高提取算法,输入歌声可用pm提速,harvest低音好但巨慢无比,crepe效果好但吃GPU,rmvpe效果最好且微吃GPU"
|
||||
),
|
||||
choices=["pm", "harvest", "crepe", "rmvpe"]if config.dml==False else ["pm", "harvest", "rmvpe"],
|
||||
choices=["pm", "harvest", "crepe", "rmvpe"]
|
||||
if config.dml == False
|
||||
else ["pm", "harvest", "rmvpe"],
|
||||
value="pm",
|
||||
interactive=True,
|
||||
)
|
||||
@@ -1790,9 +1819,12 @@ with gr.Blocks(title="RVC WebUI") as app:
|
||||
gpus6 = gr.Textbox(
|
||||
label=i18n("以-分隔输入使用的卡号, 例如 0-1-2 使用卡0和卡1和卡2"),
|
||||
value=gpus,
|
||||
interactive=True,visible=F0GPUVisible
|
||||
interactive=True,
|
||||
visible=F0GPUVisible,
|
||||
)
|
||||
gpu_info9 = gr.Textbox(
|
||||
label=i18n("显卡信息"), value=gpu_info, visible=F0GPUVisible
|
||||
)
|
||||
gpu_info9 = gr.Textbox(label=i18n("显卡信息"), value=gpu_info,visible=F0GPUVisible)
|
||||
with gr.Column():
|
||||
f0method8 = gr.Radio(
|
||||
label=i18n(
|
||||
|
||||
Reference in New Issue
Block a user