Config class (#192)

* update config.py

* class

* class

* fix
This commit is contained in:
Ftps
2023-04-28 21:43:02 +09:00
committed by GitHub
parent b1134d9f64
commit f391ac1763
3 changed files with 151 additions and 165 deletions

View File

@@ -74,19 +74,12 @@ from fairseq import checkpoint_utils
import gradio as gr
import logging
from vc_infer_pipeline import VC
from config import (
is_half,
device,
python_cmd,
listen_port,
iscolab,
noparallel,
noautoopen,
)
from config import Config
from infer_uvr5 import _audio_pre_
from my_utils import load_audio
from train.process_ckpt import show_info, change_info, merge, extract_small_model
config = Config()
# from trainset_preprocess_pipeline import PreProcess
logging.getLogger("numba").setLevel(logging.WARNING)
@@ -111,8 +104,8 @@ def load_hubert():
suffix="",
)
hubert_model = models[0]
hubert_model = hubert_model.to(device)
if is_half:
hubert_model = hubert_model.to(config.device)
if config.is_half:
hubert_model = hubert_model.half()
else:
hubert_model = hubert_model.float()
@@ -259,8 +252,8 @@ def uvr(model_name, inp_root, save_root_vocal, paths, save_root_ins, agg):
pre_fun = _audio_pre_(
agg=int(agg),
model_path=os.path.join(weight_uvr5_root, model_name + ".pth"),
device=device,
is_half=is_half,
device=config.device,
is_half=config.is_half,
)
if inp_root != "":
paths = [os.path.join(inp_root, name) for name in os.listdir(inp_root)]
@@ -328,7 +321,9 @@ def get_vc(sid):
###楼下不这么折腾清理不干净
if_f0 = cpt.get("f0", 1)
if if_f0 == 1:
net_g = SynthesizerTrnMs256NSFsid(*cpt["config"], is_half=is_half)
net_g = SynthesizerTrnMs256NSFsid(
*cpt["config"], is_half=config.is_half
)
else:
net_g = SynthesizerTrnMs256NSFsid_nono(*cpt["config"])
del net_g, cpt
@@ -343,17 +338,17 @@ def get_vc(sid):
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk
if_f0 = cpt.get("f0", 1)
if if_f0 == 1:
net_g = SynthesizerTrnMs256NSFsid(*cpt["config"], is_half=is_half)
net_g = SynthesizerTrnMs256NSFsid(*cpt["config"], is_half=config.is_half)
else:
net_g = SynthesizerTrnMs256NSFsid_nono(*cpt["config"])
del net_g.enc_q
print(net_g.load_state_dict(cpt["weight"], strict=False)) # 不加这一行清不干净, 真奇葩
net_g.eval().to(device)
if is_half:
net_g.eval().to(config.device)
if config.is_half:
net_g = net_g.half()
else:
net_g = net_g.float()
vc = VC(tgt_sr, device, is_half)
vc = VC(tgt_sr, config)
n_spk = cpt["config"][-3]
return {"visible": True, "maximum": n_spk, "__type__": "update"}
@@ -423,10 +418,10 @@ def preprocess_dataset(trainset_dir, exp_dir, sr, n_p=ncpu):
f = open("%s/logs/%s/preprocess.log" % (now_dir, exp_dir), "w")
f.close()
cmd = (
python_cmd
config.python_cmd
+ " trainset_preprocess_pipeline_print.py %s %s %s %s/logs/%s "
% (trainset_dir, sr, n_p, now_dir, exp_dir)
+ str(noparallel)
+ str(config.noparallel)
)
print(cmd)
p = Popen(cmd, shell=True) # , stdin=PIPE, stdout=PIPE,stderr=PIPE,cwd=now_dir
@@ -458,7 +453,7 @@ def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir):
f = open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "w")
f.close()
if if_f0 == "":
cmd = python_cmd + " extract_f0_print.py %s/logs/%s %s %s" % (
cmd = config.python_cmd + " extract_f0_print.py %s/logs/%s %s %s" % (
now_dir,
exp_dir,
n_p,
@@ -498,8 +493,8 @@ def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir):
leng = len(gpus)
ps = []
for idx, n_g in enumerate(gpus):
cmd = python_cmd + " extract_feature_print.py %s %s %s %s %s/logs/%s" % (
device,
cmd = config.python_cmd + " extract_feature_print.py %s %s %s %s %s/logs/%s" % (
config.device,
leng,
idx,
n_g,
@@ -621,7 +616,7 @@ def click_train(
print("use gpus:", gpus16)
if gpus16:
cmd = (
python_cmd
config.python_cmd
+ " train_nsf_sim_cache_sid_load_pretrain.py -e %s -sr %s -f0 %s -bs %s -g %s -te %s -se %s -pg %s -pd %s -l %s -c %s"
% (
exp_dir1,
@@ -639,7 +634,7 @@ def click_train(
)
else:
cmd = (
python_cmd
config.python_cmd
+ " train_nsf_sim_cache_sid_load_pretrain.py -e %s -sr %s -f0 %s -bs %s -te %s -se %s -pg %s -pd %s -l %s -c %s"
% (
exp_dir1,
@@ -736,10 +731,10 @@ def train1key(
#########step1:处理数据
open("%s/logs/%s/preprocess.log" % (now_dir, exp_dir1), "w").close()
cmd = (
python_cmd
config.python_cmd
+ " trainset_preprocess_pipeline_print.py %s %s %s %s/logs/%s "
% (trainset_dir4, sr_dict[sr2], ncpu, now_dir, exp_dir1)
+ str(noparallel)
+ str(config.noparallel)
)
yield get_info_str("step1:正在处理数据")
yield get_info_str(cmd)
@@ -751,7 +746,7 @@ def train1key(
open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir1), "w")
if if_f0_3 == "":
yield get_info_str("step2a:正在提取音高")
cmd = python_cmd + " extract_f0_print.py %s/logs/%s %s %s" % (
cmd = config.python_cmd + " extract_f0_print.py %s/logs/%s %s %s" % (
now_dir,
exp_dir1,
np7,
@@ -770,8 +765,8 @@ def train1key(
leng = len(gpus)
ps = []
for idx, n_g in enumerate(gpus):
cmd = python_cmd + " extract_feature_print.py %s %s %s %s %s/logs/%s" % (
device,
cmd = config.python_cmd + " extract_feature_print.py %s %s %s %s %s/logs/%s" % (
config.device,
leng,
idx,
n_g,
@@ -852,7 +847,7 @@ def train1key(
yield get_info_str("write filelist done")
if gpus16:
cmd = (
python_cmd
config.python_cmd
+ " train_nsf_sim_cache_sid_load_pretrain.py -e %s -sr %s -f0 %s -bs %s -g %s -te %s -se %s -pg %s -pd %s -l %s -c %s"
% (
exp_dir1,
@@ -870,7 +865,7 @@ def train1key(
)
else:
cmd = (
python_cmd
config.python_cmd
+ " train_nsf_sim_cache_sid_load_pretrain.py -e %s -sr %s -f0 %s -bs %s -te %s -se %s -pg %s -pd %s -l %s -c %s"
% (
exp_dir1,
@@ -1531,12 +1526,12 @@ with gr.Blocks() as app:
# with gr.TabItem(i18n("点击查看交流、问题反馈群号")):
# gr.Markdown(value=i18n("xxxxx"))
if iscolab:
if config.iscolab:
app.queue(concurrency_count=511, max_size=1022).launch(share=True)
else:
app.queue(concurrency_count=511, max_size=1022).launch(
server_name="0.0.0.0",
inbrowser=not noautoopen,
server_port=listen_port,
inbrowser=not config.noautoopen,
server_port=config.listen_port,
quiet=True,
)