Format code (#188)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
github-actions[bot] 2023-04-28 11:25:20 +08:00 committed by GitHub
parent 9976df7045
commit 9068d5283e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 95 additions and 51 deletions

View File

@ -64,25 +64,43 @@ if not torch.cuda.is_available():
device = "cpu"
is_half = False
gpu_mem=None
gpu_mem = None
if device not in ["cpu", "mps"]:
i_device=int(device.split(":")[-1])
i_device = int(device.split(":")[-1])
gpu_name = torch.cuda.get_device_name(i_device)
if "16" in gpu_name or "P40"in gpu_name.upper() or "1070"in gpu_name or "1080"in gpu_name:
if (
"16" in gpu_name
or "P40" in gpu_name.upper()
or "1070" in gpu_name
or "1080" in gpu_name
):
print("16系显卡强制单精度")
is_half = False
with open("configs/32k.json","r")as f:strr=f.read().replace("true","false")
with open("configs/32k.json","w")as f:f.write(strr)
with open("configs/40k.json","r")as f:strr=f.read().replace("true","false")
with open("configs/40k.json","w")as f:f.write(strr)
with open("configs/48k.json","r")as f:strr=f.read().replace("true","false")
with open("configs/48k.json","w")as f:f.write(strr)
with open("trainset_preprocess_pipeline_print.py","r")as f:strr=f.read().replace("3.7","3.0")
with open("trainset_preprocess_pipeline_print.py","w")as f:f.write(strr)
gpu_mem=int(torch.cuda.get_device_properties(i_device).total_memory/1024/1024/1024+0.4)
if(gpu_mem<=4):
with open("trainset_preprocess_pipeline_print.py","r")as f:strr=f.read().replace("3.7","3.0")
with open("trainset_preprocess_pipeline_print.py","w")as f:f.write(strr)
with open("configs/32k.json", "r") as f:
strr = f.read().replace("true", "false")
with open("configs/32k.json", "w") as f:
f.write(strr)
with open("configs/40k.json", "r") as f:
strr = f.read().replace("true", "false")
with open("configs/40k.json", "w") as f:
f.write(strr)
with open("configs/48k.json", "r") as f:
strr = f.read().replace("true", "false")
with open("configs/48k.json", "w") as f:
f.write(strr)
with open("trainset_preprocess_pipeline_print.py", "r") as f:
strr = f.read().replace("3.7", "3.0")
with open("trainset_preprocess_pipeline_print.py", "w") as f:
f.write(strr)
gpu_mem = int(
torch.cuda.get_device_properties(i_device).total_memory / 1024 / 1024 / 1024
+ 0.4
)
if gpu_mem <= 4:
with open("trainset_preprocess_pipeline_print.py", "r") as f:
strr = f.read().replace("3.7", "3.0")
with open("trainset_preprocess_pipeline_print.py", "w") as f:
f.write(strr)
from multiprocessing import cpu_count
if n_cpu == 0:
@ -99,8 +117,8 @@ else:
x_query = 6
x_center = 38
x_max = 41
if(gpu_mem!=None and gpu_mem<=4):
if gpu_mem != None and gpu_mem <= 4:
x_pad = 1
x_query = 5
x_center = 30
x_max = 32
x_max = 32

8
gui.py
View File

@ -375,9 +375,7 @@ class GUI:
self.crossfade_frame = int(self.config.crossfade_time * self.config.samplerate)
self.sola_search_frame = int(0.012 * self.config.samplerate)
self.delay_frame = int(0.01 * self.config.samplerate) # 往前预留0.02s
self.extra_frame = int(
self.config.extra_time * self.config.samplerate
)
self.extra_frame = int(self.config.extra_time * self.config.samplerate)
self.rvc = None
self.rvc = RVC(
self.config.pitch,
@ -408,7 +406,9 @@ class GUI:
orig_freq=self.config.samplerate, new_freq=16000, dtype=torch.float32
)
self.resampler2 = tat.Resample(
orig_freq=self.rvc.tgt_sr, new_freq=self.config.samplerate, dtype=torch.float32
orig_freq=self.rvc.tgt_sr,
new_freq=self.config.samplerate,
dtype=torch.float32,
)
thread_vc = threading.Thread(target=self.soundinput)
thread_vc.start()

View File

@ -1,11 +1,12 @@
from multiprocessing import cpu_count
import threading,pdb,librosa
import threading, pdb, librosa
from time import sleep
from subprocess import Popen
from time import sleep
import torch, os, traceback, sys, warnings, shutil, numpy as np
import faiss
from random import shuffle
now_dir = os.getcwd()
sys.path.append(now_dir)
tmp = os.path.join(now_dir, "TEMP")
@ -24,7 +25,7 @@ i18n = I18nAuto()
ncpu = cpu_count()
ngpu = torch.cuda.device_count()
gpu_infos = []
mem=[]
mem = []
if (not torch.cuda.is_available()) or ngpu == 0:
if_gpu_ok = False
else:
@ -50,13 +51,21 @@ else:
): # A10#A100#V100#A40#P40#M40#K80#A4500
if_gpu_ok = True # 至少有一张能用的N卡
gpu_infos.append("%s\t%s" % (i, gpu_name))
mem.append(int(torch.cuda.get_device_properties(i).total_memory/1024/1024/1024+0.4))
mem.append(
int(
torch.cuda.get_device_properties(i).total_memory
/ 1024
/ 1024
/ 1024
+ 0.4
)
)
if if_gpu_ok == True and len(gpu_infos) > 0:
gpu_info ="\n".join(gpu_infos)
default_batch_size=min(mem)//2
gpu_info = "\n".join(gpu_infos)
default_batch_size = min(mem) // 2
else:
gpu_info = "很遗憾您这没有能用的显卡来支持您训练"
default_batch_size=1
default_batch_size = 1
gpus = "-".join([i[0] for i in gpu_infos])
from infer_pack.models import SynthesizerTrnMs256NSFsid, SynthesizerTrnMs256NSFsid_nono
from scipy.io import wavfile
@ -236,7 +245,7 @@ def vc_multi(
yield traceback.format_exc()
def uvr(model_name, inp_root, save_root_vocal, paths, save_root_ins,agg):
def uvr(model_name, inp_root, save_root_vocal, paths, save_root_ins, agg):
infos = []
try:
inp_root = inp_root.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
@ -258,23 +267,30 @@ def uvr(model_name, inp_root, save_root_vocal, paths, save_root_ins,agg):
paths = [path.name for path in paths]
for path in paths:
inp_path = os.path.join(inp_root, path)
need_reformat=1
done=0
need_reformat = 1
done = 0
try:
info = ffmpeg.probe(inp_path, cmd="ffprobe")
if(info["streams"][0]["channels"]==2 and info["streams"][0]["sample_rate"]=="44100"):
need_reformat=0
if (
info["streams"][0]["channels"] == 2
and info["streams"][0]["sample_rate"] == "44100"
):
need_reformat = 0
pre_fun._path_audio_(inp_path, save_root_ins, save_root_vocal)
done=1
done = 1
except:
need_reformat = 1
traceback.print_exc()
if(need_reformat==1):
tmp_path="%s/%s.reformatted.wav"%(tmp,os.path.basename(inp_path))
os.system("ffmpeg -i %s -vn -acodec pcm_s16le -ac 2 -ar 44100 %s -y"%(inp_path,tmp_path))
inp_path=tmp_path
if need_reformat == 1:
tmp_path = "%s/%s.reformatted.wav" % (tmp, os.path.basename(inp_path))
os.system(
"ffmpeg -i %s -vn -acodec pcm_s16le -ac 2 -ar 44100 %s -y"
% (inp_path, tmp_path)
)
inp_path = tmp_path
try:
if(done==0):pre_fun._path_audio_(inp_path, save_root_ins, save_root_vocal)
if done == 0:
pre_fun._path_audio_(inp_path, save_root_ins, save_root_vocal)
infos.append("%s->Success" % (os.path.basename(inp_path)))
yield "\n".join(infos)
except:
@ -660,11 +676,11 @@ def train_index(exp_dir1):
big_npy = np.concatenate(npys, 0)
# np.save("%s/total_fea.npy" % exp_dir, big_npy)
# n_ivf = big_npy.shape[0] // 39
n_ivf = min(int(16 * np.sqrt(big_npy.shape[0])),big_npy.shape[0]// 39)
infos=[]
infos.append("%s,%s"%(big_npy.shape,n_ivf))
n_ivf = min(int(16 * np.sqrt(big_npy.shape[0])), big_npy.shape[0] // 39)
infos = []
infos.append("%s,%s" % (big_npy.shape, n_ivf))
yield "\n".join(infos)
index = faiss.index_factory(256, "IVF%s,Flat"%n_ivf)
index = faiss.index_factory(256, "IVF%s,Flat" % n_ivf)
# index = faiss.index_factory(256, "IVF%s,PQ128x4fs,RFlat"%n_ivf)
infos.append("training")
yield "\n".join(infos)
@ -672,13 +688,19 @@ def train_index(exp_dir1):
# index_ivf.nprobe = int(np.power(n_ivf,0.3))
index_ivf.nprobe = 1
index.train(big_npy)
faiss.write_index(index, '%s/trained_IVF%s_Flat_nprobe_%s.index'%(exp_dir,n_ivf,index_ivf.nprobe))
faiss.write_index(
index,
"%s/trained_IVF%s_Flat_nprobe_%s.index" % (exp_dir, n_ivf, index_ivf.nprobe),
)
# faiss.write_index(index, '%s/trained_IVF%s_Flat_FastScan.index'%(exp_dir,n_ivf))
infos.append("adding")
yield "\n".join(infos)
index.add(big_npy)
faiss.write_index(index, '%s/added_IVF%s_Flat_nprobe_%s.index'%(exp_dir,n_ivf,index_ivf.nprobe))
infos.append("成功构建索引added_IVF%s_Flat_nprobe_%s.index"%(n_ivf,index_ivf.nprobe))
faiss.write_index(
index,
"%s/added_IVF%s_Flat_nprobe_%s.index" % (exp_dir, n_ivf, index_ivf.nprobe),
)
infos.append("成功构建索引added_IVF%s_Flat_nprobe_%s.index" % (n_ivf, index_ivf.nprobe))
# faiss.write_index(index, '%s/added_IVF%s_Flat_FastScan.index'%(exp_dir,n_ivf))
# infos.append("成功构建索引added_IVF%s_Flat_FastScan.index"%(n_ivf))
yield "\n".join(infos)
@ -876,7 +898,7 @@ def train1key(
big_npy = np.concatenate(npys, 0)
# np.save("%s/total_fea.npy" % exp_dir, big_npy)
# n_ivf = big_npy.shape[0] // 39
n_ivf = min(int(16 * np.sqrt(big_npy.shape[0])),big_npy.shape[0]// 39)
n_ivf = min(int(16 * np.sqrt(big_npy.shape[0])), big_npy.shape[0] // 39)
yield get_info_str("%s,%s" % (big_npy.shape, n_ivf))
index = faiss.index_factory(256, "IVF%s,Flat" % n_ivf)
yield get_info_str("training index")
@ -1171,7 +1193,7 @@ with gr.Blocks() as app:
label="人声提取激进程度",
value=10,
interactive=True,
visible=False#先不开放调整
visible=False, # 先不开放调整
)
opt_vocal_root = gr.Textbox(
label=i18n("指定输出人声文件夹"), value="opt"
@ -1187,7 +1209,7 @@ with gr.Blocks() as app:
opt_vocal_root,
wav_inputs,
opt_ins_root,
agg
agg,
],
[vc_output4],
)

View File

@ -13,7 +13,7 @@ from scipy.io import wavfile
class _audio_pre_:
def __init__(self, agg,model_path, device, is_half):
def __init__(self, agg, model_path, device, is_half):
self.model_path = model_path
self.device = device
self.data = {
@ -139,7 +139,9 @@ class _audio_pre_:
wav_instrument = spec_utils.cmb_spectrogram_to_wave(y_spec_m, self.mp)
print("%s instruments done" % name)
wavfile.write(
os.path.join(ins_root, "instrument_{}_{}.wav".format(name,self.data["agg"])),
os.path.join(
ins_root, "instrument_{}_{}.wav".format(name, self.data["agg"])
),
self.mp.param["sr"],
(np.array(wav_instrument) * 32768).astype("int16"),
) #
@ -155,7 +157,9 @@ class _audio_pre_:
wav_vocals = spec_utils.cmb_spectrogram_to_wave(v_spec_m, self.mp)
print("%s vocals done" % name)
wavfile.write(
os.path.join(vocal_root, "vocal_{}_{}.wav".format(name,self.data["agg"])),
os.path.join(
vocal_root, "vocal_{}_{}.wav".format(name, self.data["agg"])
),
self.mp.param["sr"],
(np.array(wav_vocals) * 32768).astype("int16"),
)