1
0
mirror of synced 2024-11-27 17:00:54 +01:00

Format code (#877)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
github-actions[bot] 2023-07-26 19:51:48 +08:00 committed by GitHub
parent b1cb31854a
commit f7fc51c81a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 126 additions and 96 deletions

View File

@ -79,9 +79,7 @@ class FeatureInput(object):
from lib.rmvpe import RMVPE
print("loading rmvpe model")
self.model_rmvpe = RMVPE(
"rmvpe.pt", is_half=False, device="cpu"
)
self.model_rmvpe = RMVPE("rmvpe.pt", is_half=False, device="cpu")
f0 = self.model_rmvpe.infer_from_audio(x, thred=0.03)
return f0

View File

@ -23,7 +23,6 @@ def printt(strr):
f.flush()
class FeatureInput(object):
def __init__(self, samplerate=16000, hop_size=160):
self.fs = samplerate
@ -38,14 +37,12 @@ class FeatureInput(object):
def compute_f0(self, path, f0_method):
x = load_audio(path, self.fs)
p_len = x.shape[0] // self.hop
if(f0_method=="rmvpe"):
if f0_method == "rmvpe":
if hasattr(self, "model_rmvpe") == False:
from lib.rmvpe import RMVPE
print("loading rmvpe model")
self.model_rmvpe = RMVPE(
"rmvpe.pt", is_half=True, device="cuda"
)
self.model_rmvpe = RMVPE("rmvpe.pt", is_half=True, device="cuda")
f0 = self.model_rmvpe.infer_from_audio(x, thred=0.03)
return f0
@ -117,7 +114,7 @@ if __name__ == "__main__":
opt_path2 = "%s/%s" % (opt_root2, name)
paths.append([inp_path, opt_path1, opt_path2])
try:
featureInput.go(paths[i_part::n_part],"rmvpe")
featureInput.go(paths[i_part::n_part], "rmvpe")
except:
printt("f0_all_fail-%s" % (traceback.format_exc()))
# ps = []

View File

@ -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)
@ -570,13 +568,13 @@ def preprocess_dataset(trainset_dir, exp_dir, sr, n_p):
# but2.click(extract_f0,[gpus6,np7,f0method8,if_f0_3,trainset_dir4],[info2])
def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir, version19,gpus_rmvpe):
def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir, version19, gpus_rmvpe):
gpus = gpus.split("-")
os.makedirs("%s/logs/%s" % (now_dir, exp_dir), exist_ok=True)
f = open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "w")
f.close()
if if_f0:
if(f0method!="rmvpe_gpu"):
if f0method != "rmvpe_gpu":
cmd = config.python_cmd + ' extract_f0_print.py "%s/logs/%s" %s %s' % (
now_dir,
exp_dir,
@ -584,7 +582,9 @@ def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir, version19,gpus_rmvpe
f0method,
)
print(cmd)
p = Popen(cmd, shell=True, cwd=now_dir) # , stdin=PIPE, stdout=PIPE,stderr=PIPE
p = Popen(
cmd, shell=True, cwd=now_dir
) # , stdin=PIPE, stdout=PIPE,stderr=PIPE
###煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
done = [False]
threading.Thread(
@ -602,7 +602,9 @@ def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir, version19,gpus_rmvpe
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
@ -612,16 +614,9 @@ def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir, version19,gpus_rmvpe
ps = []
for idx, n_g in enumerate(gpus_rmvpe):
cmd = (
config.python_cmd
+ ' extract_f0_rmvpe.py %s %s %s "%s/logs/%s" %s '
% (
leng,
idx,
n_g,
now_dir,
exp_dir,
config.is_half
)
config.python_cmd
+ ' extract_f0_rmvpe.py %s %s %s "%s/logs/%s" %s '
% (leng, idx, n_g, now_dir, exp_dir, config.is_half)
)
print(cmd)
p = Popen(
@ -638,12 +633,16 @@ def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir, version19,gpus_rmvpe
),
).start()
while 1:
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:
yield (f.read())
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
@ -1037,7 +1036,8 @@ def train1key(
gpus16,
if_cache_gpu17,
if_save_every_weights18,
version19,gpus_rmvpe
version19,
gpus_rmvpe,
):
infos = []
@ -1074,7 +1074,7 @@ def train1key(
open(extract_f0_feature_log_path, "w")
if if_f0_3:
yield get_info_str("step2a:正在提取音高")
if(f0method8!="rmvpe_gpu"):
if f0method8 != "rmvpe_gpu":
cmd = config.python_cmd + ' extract_f0_print.py "%s" %s %s' % (
model_log_dir,
np7,
@ -1088,16 +1088,12 @@ def train1key(
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(
@ -1318,11 +1314,15 @@ def change_info_(ckpt_path):
traceback.print_exc()
return {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}
def change_f0_method(f0method8):
if(f0method8=="rmvpe_gpu"):visible=True
else:visible=False
if f0method8 == "rmvpe_gpu":
visible = True
else:
visible = False
return {"visible": visible, "__type__": "update"}
def export_onnx(ModelPath, ExportedPath):
global cpt
cpt = torch.load(ModelPath, map_location="cpu")
@ -1755,10 +1755,12 @@ with gr.Blocks(title="RVC WebUI") as app:
interactive=True,
)
gpus_rmvpe = gr.Textbox(
label=i18n("rmvpe卡号配置以-分隔输入使用的不同进程卡号,例如0-0-1使用在卡0上跑2个进程并在卡1上跑1个进程"),
value="%s-%s"%(gpus,gpus),
label=i18n(
"rmvpe卡号配置以-分隔输入使用的不同进程卡号,例如0-0-1使用在卡0上跑2个进程并在卡1上跑1个进程"
),
value="%s-%s" % (gpus, gpus),
interactive=True,
visible=True
visible=True,
)
but2 = gr.Button(i18n("特征提取"), variant="primary")
info2 = gr.Textbox(label=i18n("输出信息"), value="", max_lines=8)
@ -1769,7 +1771,15 @@ with gr.Blocks(title="RVC WebUI") as app:
)
but2.click(
extract_f0_feature,
[gpus6, np7, f0method8, if_f0_3, exp_dir1, version19,gpus_rmvpe],
[
gpus6,
np7,
f0method8,
if_f0_3,
exp_dir1,
version19,
gpus_rmvpe,
],
[info2],
)
with gr.Group():
@ -1894,7 +1904,8 @@ with gr.Blocks(title="RVC WebUI") as app:
gpus16,
if_cache_gpu17,
if_save_every_weights18,
version19,gpus_rmvpe
version19,
gpus_rmvpe,
],
info3,
)

View File

@ -1,4 +1,5 @@
import os,sys,pdb,torch
import os, sys, pdb, torch
now_dir = os.getcwd()
sys.path.append(now_dir)
import argparse
@ -9,35 +10,36 @@ import numpy as np
from multiprocessing import cpu_count
####
#USAGE
# USAGE
#
#In your Terminal or CMD or whatever
#python infer_cli.py [TRANSPOSE_VALUE] "[INPUT_PATH]" "[OUTPUT_PATH]" "[MODEL_PATH]" "[INDEX_FILE_PATH]" "[INFERENCE_DEVICE]" "[METHOD]"
# In your Terminal or CMD or whatever
# python infer_cli.py [TRANSPOSE_VALUE] "[INPUT_PATH]" "[OUTPUT_PATH]" "[MODEL_PATH]" "[INDEX_FILE_PATH]" "[INFERENCE_DEVICE]" "[METHOD]"
using_cli = False
device = "cuda:0"
is_half = False
if(len(sys.argv) > 0):
f0_up_key=int(sys.argv[1]) #transpose value
input_path=sys.argv[2]
output_path=sys.argv[3]
model_path=sys.argv[4]
file_index=sys.argv[5] #.index file
device=sys.argv[6]
f0_method=sys.argv[7] #pm or harvest or crepe
if len(sys.argv) > 0:
f0_up_key = int(sys.argv[1]) # transpose value
input_path = sys.argv[2]
output_path = sys.argv[3]
model_path = sys.argv[4]
file_index = sys.argv[5] # .index file
device = sys.argv[6]
f0_method = sys.argv[7] # pm or harvest or crepe
using_cli = True
#file_index2=sys.argv[8]
#index_rate=float(sys.argv[10]) #search feature ratio
#filter_radius=float(sys.argv[11]) #median filter
#resample_sr=float(sys.argv[12]) #resample audio in post processing
#rms_mix_rate=float(sys.argv[13]) #search feature
# file_index2=sys.argv[8]
# index_rate=float(sys.argv[10]) #search feature ratio
# filter_radius=float(sys.argv[11]) #median filter
# resample_sr=float(sys.argv[12]) #resample audio in post processing
# rms_mix_rate=float(sys.argv[13]) #search feature
print(sys.argv)
class Config:
def __init__(self,device,is_half):
def __init__(self, device, is_half):
self.device = device
self.is_half = is_half
self.n_cpu = 0
@ -113,8 +115,9 @@ class Config:
return x_pad, x_query, x_center, x_max
config=Config(device,is_half)
now_dir=os.getcwd()
config = Config(device, is_half)
now_dir = os.getcwd()
sys.path.append(now_dir)
from vc_infer_pipeline import VC
from infer_pack.models import SynthesizerTrnMs256NSFsid, SynthesizerTrnMs256NSFsid_nono
@ -122,7 +125,9 @@ from my_utils import load_audio
from fairseq import checkpoint_utils
from scipy.io import wavfile
hubert_model=None
hubert_model = None
def load_hubert():
global hubert_model
models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
@ -137,41 +142,42 @@ def load_hubert():
hubert_model = hubert_model.float()
hubert_model.eval()
def vc_single(
sid=0,
input_audio_path=None,
f0_up_key=0,
f0_up_key=0,
f0_file=None,
f0_method="pm",
file_index="", #.index file
f0_method="pm",
file_index="", # .index file
file_index2="",
# file_big_npy,
index_rate=1.0,
filter_radius=3,
resample_sr=0,
rms_mix_rate=1.0,
index_rate=1.0,
filter_radius=3,
resample_sr=0,
rms_mix_rate=1.0,
model_path="",
output_path="",
protect=0.33
protect=0.33,
):
global tgt_sr, net_g, vc, hubert_model, version
get_vc(model_path)
if input_audio_path is None:
return "You need to upload an audio file", None
f0_up_key = int(f0_up_key)
audio = load_audio(input_audio_path, 16000)
audio_max = np.abs(audio).max() / 0.95
if audio_max > 1:
audio /= audio_max
times = [0, 0, 0]
if hubert_model == None:
load_hubert()
if_f0 = cpt.get("f0", 1)
file_index = (
(
file_index.strip(" ")
@ -184,7 +190,7 @@ def vc_single(
if file_index != ""
else file_index2
)
audio_opt = vc.pipeline(
hubert_model,
net_g,
@ -204,32 +210,49 @@ def vc_single(
rms_mix_rate,
version,
f0_file=f0_file,
protect=protect
protect=protect,
)
wavfile.write(output_path, tgt_sr, audio_opt)
return('processed')
return "processed"
def get_vc(model_path):
global n_spk,tgt_sr,net_g,vc,cpt,device,is_half, version
print("loading pth %s"%model_path)
global n_spk, tgt_sr, net_g, vc, cpt, device, is_half, version
print("loading pth %s" % model_path)
cpt = torch.load(model_path, map_location="cpu")
tgt_sr = cpt["config"][-1]
cpt["config"][-3]=cpt["weight"]["emb_g.weight"].shape[0]#n_spk
if_f0=cpt.get("f0",1)
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk
if_f0 = cpt.get("f0", 1)
version = cpt.get("version", "v1")
if(if_f0==1):
if if_f0 == 1:
net_g = SynthesizerTrnMs256NSFsid(*cpt["config"], is_half=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 = net_g.half()
else:net_g = net_g.float()
if is_half:
net_g = net_g.half()
else:
net_g = net_g.float()
vc = VC(tgt_sr, config)
n_spk=cpt["config"][-3]
n_spk = cpt["config"][-3]
# return {"visible": True,"maximum": n_spk, "__type__": "update"}
if(using_cli):
vc_single(sid=0,input_audio_path=input_path,f0_up_key=f0_up_key,f0_file=None,f0_method=f0_method,file_index=file_index,file_index2="",index_rate=1,filter_radius=3,resample_sr=0,rms_mix_rate=0,model_path=model_path,output_path=output_path)
if using_cli:
vc_single(
sid=0,
input_audio_path=input_path,
f0_up_key=f0_up_key,
f0_file=None,
f0_method=f0_method,
file_index=file_index,
file_index2="",
index_rate=1,
filter_radius=3,
resample_sr=0,
rms_mix_rate=0,
model_path=model_path,
output_path=output_path,
)

View File

@ -1,4 +1,5 @@
import os,sys
import os, sys
now_dir = os.getcwd()
sys.path.append(os.path.join(now_dir))
sys.path.append(os.path.join(now_dir, "train"))