Skip to content

Commit a7647e4

Browse files
Format code (#526)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent f92a923 commit a7647e4

7 files changed

+91
-48
lines changed

extract_feature_print.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ def readwave(wav_path, normalize=False):
6464
# HuBERT model
6565
printt("load model(s) from {}".format(model_path))
6666
# if hubert model is exist
67-
if (os.access(model_path, os.F_OK) == False):
68-
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)
67+
if os.access(model_path, os.F_OK) == False:
68+
printt(
69+
"Error: Extracting is shut down because %s does not exist, you may download it from https://huggingface.co/lj1995/VoiceConversionWebUI/tree/main"
70+
% model_path
71+
)
6972
exit(0)
7073
models, saved_cfg, task = checkpoint_utils.load_model_ensemble_and_task(
7174
[model_path],

gui.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -469,21 +469,21 @@ def event_handler(self):
469469
self.flag_vc = False
470470

471471
def set_values(self, values):
472-
if(len(values["pth_path"].strip()) == 0):
473-
sg.popup(i18n('请选择pth文件'))
472+
if len(values["pth_path"].strip()) == 0:
473+
sg.popup(i18n("请选择pth文件"))
474474
return False
475-
if(len(values["index_path"].strip()) == 0):
476-
sg.popup(i18n('请选择index文件'))
475+
if len(values["index_path"].strip()) == 0:
476+
sg.popup(i18n("请选择index文件"))
477477
return False
478478
pattern = re.compile("[^\x00-\x7F]+")
479-
if(pattern.findall(values["hubert_path"])):
480-
sg.popup(i18n('hubert模型路径不可包含中文'))
479+
if pattern.findall(values["hubert_path"]):
480+
sg.popup(i18n("hubert模型路径不可包含中文"))
481481
return False
482-
if(pattern.findall(values["pth_path"])):
483-
sg.popup(i18n('pth文件路径不可包含中文'))
482+
if pattern.findall(values["pth_path"]):
483+
sg.popup(i18n("pth文件路径不可包含中文"))
484484
return False
485-
if(pattern.findall(values["index_path"])):
486-
sg.popup(i18n('index文件路径不可包含中文'))
485+
if pattern.findall(values["index_path"]):
486+
sg.popup(i18n("index文件路径不可包含中文"))
487487
return False
488488
self.set_devices(values["sg_input_device"], values["sg_output_device"])
489489
self.config.hubert_path = os.path.join(current_dir, "hubert_base.pt")

infer-web.py

Lines changed: 69 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import os
22
import shutil
33
import sys
4+
45
now_dir = os.getcwd()
56
sys.path.append(now_dir)
6-
import traceback,pdb
7+
import traceback, pdb
78
import warnings
89

910
import numpy as np
@@ -396,7 +397,7 @@ def uvr(model_name, inp_root, save_root_vocal, paths, save_root_ins, agg, format
396397

397398

398399
# 一个选项卡全局只能有一个音色
399-
def get_vc(sid,to_return_protect0,to_return_protect1):
400+
def get_vc(sid, to_return_protect0, to_return_protect1):
400401
global n_spk, tgt_sr, net_g, vc, cpt, version
401402
if sid == "" or sid == []:
402403
global hubert_model
@@ -434,11 +435,23 @@ def get_vc(sid,to_return_protect0,to_return_protect1):
434435
tgt_sr = cpt["config"][-1]
435436
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk
436437
if_f0 = cpt.get("f0", 1)
437-
if(if_f0==0):
438-
to_return_protect0=to_return_protect1={"visible": False, "value": 0.5, "__type__": "update"}
438+
if if_f0 == 0:
439+
to_return_protect0 = to_return_protect1 = {
440+
"visible": False,
441+
"value": 0.5,
442+
"__type__": "update",
443+
}
439444
else:
440-
to_return_protect0 ={"visible": True, "value": to_return_protect0, "__type__": "update"}
441-
to_return_protect1 ={"visible": True, "value": to_return_protect1, "__type__": "update"}
445+
to_return_protect0 = {
446+
"visible": True,
447+
"value": to_return_protect0,
448+
"__type__": "update",
449+
}
450+
to_return_protect1 = {
451+
"visible": True,
452+
"value": to_return_protect1,
453+
"__type__": "update",
454+
}
442455
version = cpt.get("version", "v1")
443456
if version == "v1":
444457
if if_f0 == 1:
@@ -459,7 +472,11 @@ def get_vc(sid,to_return_protect0,to_return_protect1):
459472
net_g = net_g.float()
460473
vc = VC(tgt_sr, config)
461474
n_spk = cpt["config"][-3]
462-
return {"visible": True, "maximum": n_spk, "__type__": "update"},to_return_protect0,to_return_protect1
475+
return (
476+
{"visible": True, "maximum": n_spk, "__type__": "update"},
477+
to_return_protect0,
478+
to_return_protect1,
479+
)
463480

464481

465482
def change_choices():
@@ -665,8 +682,13 @@ def change_sr2(sr2, if_f0_3, version19):
665682

666683
def change_version19(sr2, if_f0_3, version19):
667684
path_str = "" if version19 == "v1" else "_v2"
668-
if(sr2=="32k"and version19=="v1"):sr2="40k"
669-
to_return_sr2= {"choices": ["40k","48k"], "__type__": "update"} if version19=="v1"else {"choices": ["32k","40k","48k"], "__type__": "update"}
685+
if sr2 == "32k" and version19 == "v1":
686+
sr2 = "40k"
687+
to_return_sr2 = (
688+
{"choices": ["40k", "48k"], "__type__": "update"}
689+
if version19 == "v1"
690+
else {"choices": ["32k", "40k", "48k"], "__type__": "update"}
691+
)
670692
f0_str = "f0" if if_f0_3 else ""
671693
if_pretrained_generator_exist = os.access(
672694
"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):
691713
"pretrained%s/%sD%s.pth" % (path_str, f0_str, sr2)
692714
if if_pretrained_discriminator_exist
693715
else "",
694-
to_return_sr2
716+
to_return_sr2,
695717
)
696718

697719

@@ -893,14 +915,24 @@ def train_index(exp_dir1, version19):
893915
big_npy_idx = np.arange(big_npy.shape[0])
894916
np.random.shuffle(big_npy_idx)
895917
big_npy = big_npy[big_npy_idx]
896-
if(big_npy.shape[0]>2e5):
897-
# if(1):
898-
infos.append("Trying doing kmeans %s shape to 10k centers."%big_npy.shape[0])
918+
if big_npy.shape[0] > 2e5:
919+
# if(1):
920+
infos.append("Trying doing kmeans %s shape to 10k centers." % big_npy.shape[0])
899921
yield "\n".join(infos)
900922
try:
901-
big_npy = MiniBatchKMeans(n_clusters=10000, verbose=True, batch_size=256 * config.n_cpu, compute_labels=False, init="random").fit(big_npy).cluster_centers_
923+
big_npy = (
924+
MiniBatchKMeans(
925+
n_clusters=10000,
926+
verbose=True,
927+
batch_size=256 * config.n_cpu,
928+
compute_labels=False,
929+
init="random",
930+
)
931+
.fit(big_npy)
932+
.cluster_centers_
933+
)
902934
except:
903-
info=traceback.format_exc()
935+
info = traceback.format_exc()
904936
print(info)
905937
infos.append(info)
906938
yield "\n".join(infos)
@@ -1147,15 +1179,25 @@ def get_info_str(strr):
11471179
np.random.shuffle(big_npy_idx)
11481180
big_npy = big_npy[big_npy_idx]
11491181

1150-
if(big_npy.shape[0]>2e5):
1151-
# if(1):
1152-
info="Trying doing kmeans %s shape to 10k centers."%big_npy.shape[0]
1182+
if big_npy.shape[0] > 2e5:
1183+
# if(1):
1184+
info = "Trying doing kmeans %s shape to 10k centers." % big_npy.shape[0]
11531185
print(info)
11541186
yield get_info_str(info)
11551187
try:
1156-
big_npy = MiniBatchKMeans(n_clusters=10000, verbose=True, batch_size=256 * config.n_cpu, compute_labels=False, init="random").fit(big_npy).cluster_centers_
1188+
big_npy = (
1189+
MiniBatchKMeans(
1190+
n_clusters=10000,
1191+
verbose=True,
1192+
batch_size=256 * config.n_cpu,
1193+
compute_labels=False,
1194+
init="random",
1195+
)
1196+
.fit(big_npy)
1197+
.cluster_centers_
1198+
)
11571199
except:
1158-
info=traceback.format_exc()
1200+
info = traceback.format_exc()
11591201
print(info)
11601202
yield get_info_str(info)
11611203

@@ -1207,11 +1249,10 @@ def change_info_(ckpt_path):
12071249
return {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}
12081250

12091251

1210-
12111252
def export_onnx(ModelPath, ExportedPath):
12121253
cpt = torch.load(ModelPath, map_location="cpu")
12131254
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0]
1214-
vec_channels = 256 if cpt.get("version","v1")=="v1"else 768
1255+
vec_channels = 256 if cpt.get("version", "v1") == "v1" else 768
12151256

12161257
test_phone = torch.rand(1, 200, vec_channels) # hidden unit
12171258
test_phone_lengths = torch.tensor([200]).long() # hidden unit 长度(貌似没啥用)
@@ -1223,7 +1264,7 @@ def export_onnx(ModelPath, ExportedPath):
12231264
device = "cpu" # 导出时设备(不影响使用模型)
12241265

12251266
net_g = SynthesizerTrnMsNSFsidM(
1226-
*cpt["config"], is_half=False,version=cpt.get("version","v1")
1267+
*cpt["config"], is_half=False, version=cpt.get("version", "v1")
12271268
) # fp32导出(C++要支持fp16必须手动将内存重新排列所以暂时不用fp16)
12281269
net_g.load_state_dict(cpt["weight"], strict=False)
12291270
input_names = ["phone", "phone_lengths", "pitch", "pitchf", "ds", "rnd"]
@@ -1504,8 +1545,8 @@ def export_onnx(ModelPath, ExportedPath):
15041545
)
15051546
sid0.change(
15061547
fn=get_vc,
1507-
inputs=[sid0,protect0,protect1],
1508-
outputs=[spk_item,protect0,protect1],
1548+
inputs=[sid0, protect0, protect1],
1549+
outputs=[spk_item, protect0, protect1],
15091550
)
15101551
with gr.TabItem(i18n("伴奏人声分离&去混响&去回声")):
15111552
with gr.Group():
@@ -1604,7 +1645,7 @@ def export_onnx(ModelPath, ExportedPath):
16041645
maximum=config.n_cpu,
16051646
step=1,
16061647
label=i18n("提取音高和处理数据使用的CPU进程数"),
1607-
value=int(np.ceil(config.n_cpu/1.5)),
1648+
value=int(np.ceil(config.n_cpu / 1.5)),
16081649
interactive=True,
16091650
)
16101651
with gr.Group(): # 暂时单人的, 后面支持最多4人的#数据处理
@@ -1722,7 +1763,7 @@ def export_onnx(ModelPath, ExportedPath):
17221763
version19.change(
17231764
change_version19,
17241765
[sr2, if_f0_3, version19],
1725-
[pretrained_G14, pretrained_D15,sr2],
1766+
[pretrained_G14, pretrained_D15, sr2],
17261767
)
17271768
if_f0_3.change(
17281769
change_f0,
@@ -1915,7 +1956,7 @@ def export_onnx(ModelPath, ExportedPath):
19151956
[ckpt_path2, save_name, sr__, if_f0__, info___, version_1],
19161957
info7,
19171958
)
1918-
1959+
19191960
with gr.TabItem(i18n("Onnx导出")):
19201961
with gr.Row():
19211962
ckpt_dir = gr.Textbox(label=i18n("RVC模型路径"), value="", interactive=True)

infer_pack/onnx_inference.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import numpy as np
44
import soundfile
55

6+
67
class ContentVec:
78
def __init__(self, vec_path="pretrained/vec-768-layer-12.onnx", device=None):
89
print("load model(s) from {}".format(vec_path))

train_nsf_sim_cache_sid_load_pretrain.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ def run(rank, n_gpus, hps):
192192
epoch_str = 1
193193
global_step = 0
194194
if hps.pretrainG != "":
195-
196195
if rank == 0:
197196
logger.info("loaded pretrained %s" % (hps.pretrainG))
198197
print(
@@ -201,7 +200,6 @@ def run(rank, n_gpus, hps):
201200
)
202201
) ##测试不加载优化器
203202
if hps.pretrainD != "":
204-
205203
if rank == 0:
206204
logger.info("loaded pretrained %s" % (hps.pretrainD))
207205
print(

trainset_preprocess_pipeline_print.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ def __init__(self, sr, exp_dir):
5353
os.makedirs(self.wavs16k_dir, exist_ok=True)
5454

5555
def norm_write(self, tmp_audio, idx0, idx1):
56-
tmp_max=np.abs(tmp_audio).max()
57-
if(tmp_max>2.5):
58-
print("%s-%s-%s-filtered"%(idx0,idx1,tmp_max))
56+
tmp_max = np.abs(tmp_audio).max()
57+
if tmp_max > 2.5:
58+
print("%s-%s-%s-filtered" % (idx0, idx1, tmp_max))
5959
return
6060
tmp_audio = (tmp_audio / tmp_max * (self.max * self.alpha)) + (
6161
1 - self.alpha

vc_infer_pipeline.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def vc(
184184
with torch.no_grad():
185185
logits = model.extract_features(**inputs)
186186
feats = model.final_proj(logits[0]) if version == "v1" else logits[0]
187-
if protect < 0.5 and pitch!=None and pitchf!=None:
187+
if protect < 0.5 and pitch != None and pitchf != None:
188188
feats0 = feats.clone()
189189
if (
190190
isinstance(index, type(None)) == False
@@ -211,7 +211,7 @@ def vc(
211211
)
212212

213213
feats = F.interpolate(feats.permute(0, 2, 1), scale_factor=2).permute(0, 2, 1)
214-
if protect < 0.5 and pitch!=None and pitchf!=None:
214+
if protect < 0.5 and pitch != None and pitchf != None:
215215
feats0 = F.interpolate(feats0.permute(0, 2, 1), scale_factor=2).permute(
216216
0, 2, 1
217217
)
@@ -223,7 +223,7 @@ def vc(
223223
pitch = pitch[:, :p_len]
224224
pitchf = pitchf[:, :p_len]
225225

226-
if protect < 0.5 and pitch!=None and pitchf!=None:
226+
if protect < 0.5 and pitch != None and pitchf != None:
227227
pitchff = pitchf.clone()
228228
pitchff[pitchf > 0] = 1
229229
pitchff[pitchf < 1] = protect

0 commit comments

Comments
 (0)