Skip to content

Commit a3089e6

Browse files
committed
fix: train step2a & add arg --port --pycmd --noparallel
1 parent 9d1eb26 commit a3089e6

File tree

7 files changed

+63
-58
lines changed

7 files changed

+63
-58
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ __pycache__
33
/TEMP
44
*.pyd
55
hubert_base.pt
6+
/logs

config.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import argparse
2+
parser = argparse.ArgumentParser()
3+
parser.add_argument("--port", type=int, default=7865, help="Listen port")
4+
parser.add_argument("--pycmd", type=str, default="python", help="Python command")
5+
parser.add_argument("--colab", action='store_true', help="Launch in colab")
6+
parser.add_argument("--noparallel", action='store_true', help="Disable parallel processing")
7+
cmd_opts = parser.parse_args()
18
############离线VC参数
29
inp_root=r"白鹭霜华长条"#对输入目录下所有音频进行转换,别放非音频文件
310
opt_root=r"opt"#输出目录
@@ -7,10 +14,15 @@
714
device = "cuda:0"#填写cuda:x或cpu,x指代第几张卡,只支持N卡加速
815
is_half=True#9-10-20-30-40系显卡无脑True,不影响质量,>=20显卡开启有加速
916
n_cpu=0#默认0用上所有线程,写数字限制CPU资源使用
17+
############python命令路径
18+
python_cmd=cmd_opts.pycmd
19+
listen_port=cmd_opts.port
20+
iscolab=cmd_opts.colab
21+
noparallel=cmd_opts.noparallel
1022
############下头别动
1123
import torch
1224
if(torch.cuda.is_available()==False):
13-
print("没有发现支持的N卡使用CPU进行推理")
25+
print("没有发现支持的N卡, 使用CPU进行推理")
1426
device="cpu"
1527
is_half=False
1628
if(device!="cpu"):

infer-web.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from multiprocessing import cpu_count
22
import threading
33
from time import sleep
4-
from subprocess import Popen,PIPE,run as runn
4+
from subprocess import Popen
55
from time import sleep
6-
import torch, pdb, os,traceback,sys,warnings,shutil,numpy as np,faiss
6+
import torch, os,traceback,sys,warnings,shutil,numpy as np
7+
import faiss
78
#判断是否有能用来训练和加速推理的N卡
89
ncpu=cpu_count()
910
ngpu=torch.cuda.device_count()
@@ -33,11 +34,9 @@
3334
from scipy.io import wavfile
3435
from fairseq import checkpoint_utils
3536
import gradio as gr
36-
import librosa
3737
import logging
3838
from vc_infer_pipeline import VC
39-
import soundfile as sf
40-
from config import is_half,device,is_half
39+
from config import is_half,device,is_half,python_cmd,listen_port,iscolab,noparallel
4140
from infer_uvr5 import _audio_pre_
4241
from my_utils import load_audio
4342
from train.process_ckpt import show_info,change_info,merge,extract_small_model
@@ -222,7 +221,7 @@ def preprocess_dataset(trainset_dir,exp_dir,sr,n_p=ncpu):
222221
os.makedirs("%s/logs/%s"%(now_dir,exp_dir),exist_ok=True)
223222
f = open("%s/logs/%s/preprocess.log"%(now_dir,exp_dir), "w")
224223
f.close()
225-
cmd="python trainset_preprocess_pipeline_print.py %s %s %s %s/logs/%s"%(trainset_dir,sr,n_p,now_dir,exp_dir)
224+
cmd=python_cmd + " trainset_preprocess_pipeline_print.py %s %s %s %s/logs/%s "%(trainset_dir,sr,n_p,now_dir,exp_dir)+str(noparallel)
226225
print(cmd)
227226
p = Popen(cmd, shell=True)#, stdin=PIPE, stdout=PIPE,stderr=PIPE,cwd=now_dir
228227
###煞笔gr,popen read都非得全跑完了再一次性读取,不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
@@ -242,7 +241,7 @@ def extract_f0_feature(gpus,n_p,f0method,if_f0,exp_dir):
242241
f = open("%s/logs/%s/extract_f0_feature.log"%(now_dir,exp_dir), "w")
243242
f.close()
244243
if(if_f0=="是"):
245-
cmd="python extract_f0_print.py %s/logs/%s %s %s"%(now_dir,exp_dir,n_p,f0method)
244+
cmd=python_cmd + " extract_f0_print.py %s/logs/%s %s %s"%(now_dir,exp_dir,n_p,f0method)
246245
print(cmd)
247246
p = Popen(cmd, shell=True,cwd=now_dir)#, stdin=PIPE, stdout=PIPE,stderr=PIPE
248247
###煞笔gr,popen read都非得全跑完了再一次性读取,不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
@@ -266,7 +265,7 @@ def extract_f0_feature(gpus,n_p,f0method,if_f0,exp_dir):
266265
leng=len(gpus)
267266
ps=[]
268267
for idx,n_g in enumerate(gpus):
269-
cmd="python extract_feature_print.py %s %s %s %s/logs/%s"%(leng,idx,n_g,now_dir,exp_dir)
268+
cmd=python_cmd + " extract_feature_print.py %s %s %s %s/logs/%s"%(leng,idx,n_g,now_dir,exp_dir)
270269
print(cmd)
271270
p = Popen(cmd, shell=True, cwd=now_dir)#, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=now_dir
272271
ps.append(p)
@@ -305,8 +304,8 @@ def click_train(exp_dir1,sr2,if_f0_3,spk_id5,save_epoch10,total_epoch11,batch_si
305304
with open("%s/filelist.txt"%exp_dir,"w")as f:f.write("\n".join(opt))
306305
print("write filelist done")
307306
#生成config#无需生成config
308-
# cmd = "python train_nsf_sim_cache_sid_load_pretrain.py -e mi-test -sr 40k -f0 1 -bs 4 -g 0 -te 10 -se 5 -pg pretrained/f0G40k.pth -pd pretrained/f0D40k.pth -l 1 -c 0"
309-
cmd = "python 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,sr2,1 if if_f0_3=="是"else 0,batch_size12,gpus16,total_epoch11,save_epoch10,pretrained_G14,pretrained_D15,1 if if_save_latest13=="是"else 0,1 if if_cache_gpu17=="是"else 0)
307+
# cmd = python_cmd + " train_nsf_sim_cache_sid_load_pretrain.py -e mi-test -sr 40k -f0 1 -bs 4 -g 0 -te 10 -se 5 -pg pretrained/f0G40k.pth -pd pretrained/f0D40k.pth -l 1 -c 0"
308+
cmd = 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,sr2,1 if if_f0_3=="是"else 0,batch_size12,gpus16,total_epoch11,save_epoch10,pretrained_G14,pretrained_D15,1 if if_save_latest13=="是"else 0,1 if if_cache_gpu17=="是"else 0)
310309
print(cmd)
311310
p = Popen(cmd, shell=True, cwd=now_dir)
312311
p.wait()
@@ -351,7 +350,7 @@ def get_info_str(strr):
351350
os.makedirs("%s/logs/%s"%(now_dir,exp_dir1),exist_ok=True)
352351
#########step1:处理数据
353352
open("%s/logs/%s/preprocess.log"%(now_dir,exp_dir1), "w").close()
354-
cmd="python trainset_preprocess_pipeline_print.py %s %s %s %s/logs/%s"%(trainset_dir4,sr_dict[sr2],ncpu,now_dir,exp_dir1)
353+
cmd=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)
355354
yield get_info_str("step1:正在处理数据")
356355
yield get_info_str(cmd)
357356
p = Popen(cmd, shell=True)
@@ -361,7 +360,7 @@ def get_info_str(strr):
361360
open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir1), "w")
362361
if(if_f0_3=="是"):
363362
yield get_info_str("step2a:正在提取音高")
364-
cmd="python extract_f0_print.py %s/logs/%s %s %s"%(now_dir,exp_dir1,np7,f0method8)
363+
cmd=python_cmd + " extract_f0_print.py %s/logs/%s %s %s"%(now_dir,exp_dir1,np7,f0method8)
365364
yield get_info_str(cmd)
366365
p = Popen(cmd, shell=True,cwd=now_dir)
367366
p.wait()
@@ -373,7 +372,7 @@ def get_info_str(strr):
373372
leng=len(gpus)
374373
ps=[]
375374
for idx,n_g in enumerate(gpus):
376-
cmd="python extract_feature_print.py %s %s %s %s/logs/%s"%(leng,idx,n_g,now_dir,exp_dir1)
375+
cmd=python_cmd + " extract_feature_print.py %s %s %s %s/logs/%s"%(leng,idx,n_g,now_dir,exp_dir1)
377376
yield get_info_str(cmd)
378377
p = Popen(cmd, shell=True, cwd=now_dir)#, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=now_dir
379378
ps.append(p)
@@ -399,7 +398,7 @@ def get_info_str(strr):
399398
opt.append("%s/%s.wav|%s/%s.npy|%s"%(gt_wavs_dir.replace("\\","\\\\"),name,co256_dir.replace("\\","\\\\"),name,spk_id5))
400399
with open("%s/filelist.txt"%exp_dir,"w")as f:f.write("\n".join(opt))
401400
yield get_info_str("write filelist done")
402-
cmd = "python 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,sr2,1 if if_f0_3=="是"else 0,batch_size12,gpus16,total_epoch11,save_epoch10,pretrained_G14,pretrained_D15,1 if if_save_latest13=="是"else 0,1 if if_cache_gpu17=="是"else 0)
401+
cmd = 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,sr2,1 if if_f0_3=="是"else 0,batch_size12,gpus16,total_epoch11,save_epoch10,pretrained_G14,pretrained_D15,1 if if_save_latest13=="是"else 0,1 if if_cache_gpu17=="是"else 0)
403402
yield get_info_str(cmd)
404403
p = Popen(cmd, shell=True, cwd=now_dir)
405404
p.wait()
@@ -630,11 +629,7 @@ def change_info_(ckpt_path):
630629
with gr.TabItem("点击查看交流、问题反馈群号"):
631630
gr.Markdown(value="""xxxxx""")
632631

633-
import argparse
634-
parser = argparse.ArgumentParser()
635-
parser.add_argument("--colab", action='store_true', help="Launch in colab")
636-
cmd_opts = parser.parse_args()
637-
if cmd_opts.colab:
632+
if iscolab:
638633
app.queue(concurrency_count=511, max_size=1022).launch(share=True)
639634
else:
640-
app.queue(concurrency_count=511, max_size=1022).launch(server_name="0.0.0.0",inbrowser=True,server_port=7865,quiet=True)
635+
app.queue(concurrency_count=511, max_size=1022).launch(server_name="0.0.0.0",inbrowser=True,server_port=listen_port,quiet=True)

my_utils.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ def load_audio(file,sr):
1010
.output("-", format="s16le", acodec="pcm_s16le", ac=1, ar=sr)
1111
.run(cmd=["ffmpeg", "-nostdin"], capture_stdout=True, capture_stderr=True)
1212
)
13-
except ffmpeg.Error as e:
14-
raise RuntimeError(f"Failed to load audio: {e.stderr.decode()}") from e
13+
except Exception as e:
14+
raise RuntimeError(f"Failed to load audio: {e}")
1515

1616
return np.frombuffer(out, np.int16).flatten().astype(np.float32) / 32768.0
17-
18-
if __name__=='__main__' :
19-
print(load_audio(r"C:\CloudMusic\宮野幸子,森下唯 - 月夜に謳う君 -LUNA-.mp3",16000).shape)

slicer2.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# This function is obtained from librosa.
55
def get_rms(
66
y,
7-
*,
87
frame_length=2048,
98
hop_length=512,
109
pad_mode="constant",

trainset_preprocess_pipeline_print.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
1-
import sys,os,pdb,multiprocessing
1+
import sys,os,multiprocessing
22
now_dir=os.getcwd()
33
sys.path.append(now_dir)
44

55
inp_root = sys.argv[1]
66
sr = int(sys.argv[2])
77
n_p = int(sys.argv[3])
88
exp_dir = sys.argv[4]
9-
import numpy as np,ffmpeg,os,traceback
9+
noparallel = sys.argv[5] == "True"
10+
import numpy as np,os,traceback
1011
from slicer2 import Slicer
11-
from joblib import Parallel, delayed
1212
import librosa,traceback
1313
from scipy.io import wavfile
1414
import multiprocessing
1515
from my_utils import load_audio
16-
from time import sleep
1716

18-
f = open("%s/preprocess.log"%exp_dir, "a+")
19-
def printt(strr):
20-
print(strr)
21-
f.write("%s\n" % strr)
22-
f.flush()
17+
mutex = multiprocessing.Lock()
2318

2419
class PreProcess():
2520
def __init__(self,sr,exp_dir):
@@ -40,10 +35,18 @@ def __init__(self,sr,exp_dir):
4035
self.exp_dir=exp_dir
4136
self.gt_wavs_dir="%s/0_gt_wavs"%exp_dir
4237
self.wavs16k_dir="%s/1_16k_wavs"%exp_dir
38+
self.f = open("%s/preprocess.log"%exp_dir, "a+")
4339
os.makedirs(self.exp_dir,exist_ok=True)
4440
os.makedirs(self.gt_wavs_dir,exist_ok=True)
4541
os.makedirs(self.wavs16k_dir,exist_ok=True)
4642

43+
def print(self, strr):
44+
mutex.acquire()
45+
print(strr)
46+
self.f.write("%s\n" % strr)
47+
self.f.flush()
48+
mutex.release()
49+
4750
def norm_write(self,tmp_audio,idx0,idx1):
4851
tmp_audio = (tmp_audio / np.abs(tmp_audio).max() * (self.max * self.alpha)) + (1 - self.alpha) * tmp_audio
4952
wavfile.write("%s/%s_%s.wav" % (self.gt_wavs_dir, idx0, idx1), self.sr, (tmp_audio*32768).astype(np.int16))
@@ -67,9 +70,9 @@ def pipeline(self,path, idx0):
6770
tmp_audio = audio[start:]
6871
break
6972
self.norm_write(tmp_audio, idx0, idx1)
70-
printt("%s->Suc."%path)
73+
self.print("%s->Suc."%path)
7174
except:
72-
printt("%s->%s"%(path,traceback.format_exc()))
75+
self.print("%s->%s"%(path,traceback.format_exc()))
7376

7477
def pipeline_mp(self,infos):
7578
for path, idx0 in infos:
@@ -78,27 +81,24 @@ def pipeline_mp(self,infos):
7881
def pipeline_mp_inp_dir(self,inp_root,n_p):
7982
try:
8083
infos = [("%s/%s" % (inp_root, name), idx) for idx, name in enumerate(sorted(list(os.listdir(inp_root))))]
81-
ps=[]
82-
for i in range(n_p):
83-
p=multiprocessing.Process(target=self.pipeline_mp,args=(infos[i::n_p],))
84-
p.start()
85-
ps.append(p)
86-
for p in ps:p.join()
84+
if noparallel:
85+
for i in range(n_p): self.pipeline_mp(infos[i::n_p])
86+
else:
87+
ps=[]
88+
for i in range(n_p):
89+
p=multiprocessing.Process(target=self.pipeline_mp,args=(infos[i::n_p],))
90+
p.start()
91+
ps.append(p)
92+
for p in ps:p.join()
8793
except:
88-
printt("Fail. %s"%traceback.format_exc())
89-
90-
if __name__=='__main__':
91-
# f = open("logs/log_preprocess.log", "w")
92-
printt(sys.argv)
93-
######################################################
94-
# inp_root=r"E:\语音音频+标注\米津玄师\src"
95-
# inp_root=r"E:\codes\py39\vits_vc_gpu_train\todo-songs"
96-
# sr=40000
97-
# n_p = 6
98-
# exp_dir=r"E:\codes\py39\dataset\mi-test"
94+
self.print("Fail. %s"%traceback.format_exc())
9995

100-
######################################################
101-
printt("start preprocess")
96+
def preprocess_trainset(inp_root, sr, n_p, exp_dir):
10297
pp=PreProcess(sr,exp_dir)
98+
pp.print("start preprocess")
99+
pp.print(sys.argv)
103100
pp.pipeline_mp_inp_dir(inp_root,n_p)
104-
printt("end preprocess")
101+
pp.print("end preprocess")
102+
103+
if __name__=='__main__':
104+
preprocess_trainset(inp_root, sr, n_p, exp_dir)

使用需遵守的协议-LICENSE.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
MIT License
22

33
Copyright (c) 2023 liujing04
4+
Copyright (c) 2023 源文雨
45

56
本软件及其相关代码以MIT协议开源,作者不对软件具备任何控制力,使用软件者、传播软件导出的声音者自负全责。
67
如不认可该条款,则不能使用或引用软件包内任何代码和文件。

0 commit comments

Comments
 (0)