Format code (#188)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
parent
9976df7045
commit
9068d5283e
46
config.py
46
config.py
@ -68,21 +68,39 @@ gpu_mem=None
|
||||
if device not in ["cpu", "mps"]:
|
||||
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,7 +117,7 @@ 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
|
||||
|
8
gui.py
8
gui.py
@ -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()
|
||||
|
40
infer-web.py
40
infer-web.py
@ -6,6 +6,7 @@ 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")
|
||||
@ -50,7 +51,15 @@ 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
|
||||
@ -262,19 +271,26 @@ def uvr(model_name, inp_root, save_root_vocal, paths, save_root_ins,agg):
|
||||
done = 0
|
||||
try:
|
||||
info = ffmpeg.probe(inp_path, cmd="ffprobe")
|
||||
if(info["streams"][0]["channels"]==2 and info["streams"][0]["sample_rate"]=="44100"):
|
||||
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
|
||||
except:
|
||||
need_reformat = 1
|
||||
traceback.print_exc()
|
||||
if(need_reformat==1):
|
||||
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))
|
||||
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:
|
||||
@ -672,12 +688,18 @@ 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))
|
||||
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))
|
||||
@ -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],
|
||||
)
|
||||
|
@ -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"),
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user