Skip to content

Commit a21f7ec

Browse files
authored
total_fea not needed now
total_fea not needed now
1 parent 71e2733 commit a21f7ec

File tree

1 file changed

+48
-38
lines changed

1 file changed

+48
-38
lines changed

infer-web.py

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def vc_single(
126126
f0_file,
127127
f0_method,
128128
file_index,
129-
file_big_npy,
129+
# file_big_npy,
130130
index_rate,
131131
): # spk_item, input_audio0, vc_transform0,f0_file,f0method0
132132
global tgt_sr, net_g, vc, hubert_model
@@ -147,9 +147,9 @@ def vc_single(
147147
.strip(" ")
148148
.replace("trained", "added")
149149
) # 防止小白写错,自动帮他替换掉
150-
file_big_npy = (
151-
file_big_npy.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
152-
)
150+
# file_big_npy = (
151+
# file_big_npy.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
152+
# )
153153
audio_opt = vc.pipeline(
154154
hubert_model,
155155
net_g,
@@ -159,7 +159,7 @@ def vc_single(
159159
f0_up_key,
160160
f0_method,
161161
file_index,
162-
file_big_npy,
162+
# file_big_npy,
163163
index_rate,
164164
if_f0,
165165
f0_file=f0_file,
@@ -182,7 +182,7 @@ def vc_multi(
182182
f0_up_key,
183183
f0_method,
184184
file_index,
185-
file_big_npy,
185+
# file_big_npy,
186186
index_rate,
187187
):
188188
try:
@@ -200,6 +200,14 @@ def vc_multi(
200200
traceback.print_exc()
201201
paths = [path.name for path in paths]
202202
infos = []
203+
file_index = (
204+
file_index.strip(" ")
205+
.strip('"')
206+
.strip("\n")
207+
.strip('"')
208+
.strip(" ")
209+
.replace("trained", "added")
210+
) # 防止小白写错,自动帮他替换掉
203211
for path in paths:
204212
info, opt = vc_single(
205213
sid,
@@ -208,7 +216,7 @@ def vc_multi(
208216
None,
209217
f0_method,
210218
file_index,
211-
file_big_npy,
219+
# file_big_npy,
212220
index_rate,
213221
)
214222
if info == "Success":
@@ -629,29 +637,29 @@ def train_index(exp_dir1):
629637
phone = np.load("%s/%s" % (feature_dir, name))
630638
npys.append(phone)
631639
big_npy = np.concatenate(npys, 0)
632-
np.save("%s/total_fea.npy" % exp_dir, big_npy)
633-
n_ivf = big_npy.shape[0] // 39
634-
infos = []
635-
infos.append("%s,%s" % (big_npy.shape, n_ivf))
640+
# np.save("%s/total_fea.npy" % exp_dir, big_npy)
641+
# n_ivf = big_npy.shape[0] // 39
642+
n_ivf = min(int(16 * np.sqrt(big_npy.shape[0])),big_npy.shape[0]// 39)
643+
infos=[]
644+
infos.append("%s,%s"%(big_npy.shape,n_ivf))
636645
yield "\n".join(infos)
637-
index = faiss.index_factory(256, "IVF%s,Flat" % n_ivf)
646+
index = faiss.index_factory(256, "IVF%s,Flat"%n_ivf)
647+
# index = faiss.index_factory(256, "IVF%s,PQ128x4fs,RFlat"%n_ivf)
638648
infos.append("training")
639649
yield "\n".join(infos)
640650
index_ivf = faiss.extract_index_ivf(index) #
641-
index_ivf.nprobe = int(np.power(n_ivf, 0.3))
651+
# index_ivf.nprobe = int(np.power(n_ivf,0.3))
652+
index_ivf.nprobe = 1
642653
index.train(big_npy)
643-
faiss.write_index(
644-
index,
645-
"%s/trained_IVF%s_Flat_nprobe_%s.index" % (exp_dir, n_ivf, index_ivf.nprobe),
646-
)
654+
faiss.write_index(index, '%s/trained_IVF%s_Flat_nprobe_%s.index'%(exp_dir,n_ivf,index_ivf.nprobe))
655+
# faiss.write_index(index, '%s/trained_IVF%s_Flat_FastScan.index'%(exp_dir,n_ivf))
647656
infos.append("adding")
648657
yield "\n".join(infos)
649658
index.add(big_npy)
650-
faiss.write_index(
651-
index,
652-
"%s/added_IVF%s_Flat_nprobe_%s.index" % (exp_dir, n_ivf, index_ivf.nprobe),
653-
)
654-
infos.append("成功构建索引, added_IVF%s_Flat_nprobe_%s.index" % (n_ivf, index_ivf.nprobe))
659+
faiss.write_index(index, '%s/added_IVF%s_Flat_nprobe_%s.index'%(exp_dir,n_ivf,index_ivf.nprobe))
660+
infos.append("成功构建索引,added_IVF%s_Flat_nprobe_%s.index"%(n_ivf,index_ivf.nprobe))
661+
# faiss.write_index(index, '%s/added_IVF%s_Flat_FastScan.index'%(exp_dir,n_ivf))
662+
# infos.append("成功构建索引,added_IVF%s_Flat_FastScan.index"%(n_ivf))
655663
yield "\n".join(infos)
656664

657665

@@ -842,13 +850,15 @@ def get_info_str(strr):
842850
phone = np.load("%s/%s" % (feature_dir, name))
843851
npys.append(phone)
844852
big_npy = np.concatenate(npys, 0)
845-
np.save("%s/total_fea.npy" % exp_dir, big_npy)
846-
n_ivf = big_npy.shape[0] // 39
853+
# np.save("%s/total_fea.npy" % exp_dir, big_npy)
854+
# n_ivf = big_npy.shape[0] // 39
855+
n_ivf = min(int(16 * np.sqrt(big_npy.shape[0])),big_npy.shape[0]// 39)
847856
yield get_info_str("%s,%s" % (big_npy.shape, n_ivf))
848857
index = faiss.index_factory(256, "IVF%s,Flat" % n_ivf)
849858
yield get_info_str("training index")
850859
index_ivf = faiss.extract_index_ivf(index) #
851-
index_ivf.nprobe = int(np.power(n_ivf, 0.3))
860+
# index_ivf.nprobe = int(np.power(n_ivf,0.3))
861+
index_ivf.nprobe = 1
852862
index.train(big_npy)
853863
faiss.write_index(
854864
index,
@@ -1022,16 +1032,16 @@ def export_onnx(ModelPath, ExportedPath, MoeVS=True):
10221032
value="E:\\codes\\py39\\vits_vc_gpu_train\\logs\\mi-test-1key\\added_IVF677_Flat_nprobe_7.index",
10231033
interactive=True,
10241034
)
1025-
file_big_npy1 = gr.Textbox(
1026-
label=i18n("特征文件路径"),
1027-
value="E:\\codes\py39\\vits_vc_gpu_train\\logs\\mi-test-1key\\total_fea.npy",
1028-
interactive=True,
1029-
)
1035+
# file_big_npy1 = gr.Textbox(
1036+
# label=i18n("特征文件路径"),
1037+
# value="E:\\codes\py39\\vits_vc_gpu_train\\logs\\mi-test-1key\\total_fea.npy",
1038+
# interactive=True,
1039+
# )
10301040
index_rate1 = gr.Slider(
10311041
minimum=0,
10321042
maximum=1,
10331043
label="检索特征占比",
1034-
value=0.6,
1044+
value=0.65,
10351045
interactive=True,
10361046
)
10371047
f0_file = gr.File(label=i18n("F0曲线文件, 可选, 一行一个音高, 代替默认F0及升降调"))
@@ -1048,7 +1058,7 @@ def export_onnx(ModelPath, ExportedPath, MoeVS=True):
10481058
f0_file,
10491059
f0method0,
10501060
file_index1,
1051-
file_big_npy1,
1061+
# file_big_npy1,
10521062
index_rate1,
10531063
],
10541064
[vc_output1, vc_output2],
@@ -1075,11 +1085,11 @@ def export_onnx(ModelPath, ExportedPath, MoeVS=True):
10751085
value="E:\\codes\\py39\\vits_vc_gpu_train\\logs\\mi-test-1key\\added_IVF677_Flat_nprobe_7.index",
10761086
interactive=True,
10771087
)
1078-
file_big_npy2 = gr.Textbox(
1079-
label=i18n("特征文件路径"),
1080-
value="E:\\codes\\py39\\vits_vc_gpu_train\\logs\\mi-test-1key\\total_fea.npy",
1081-
interactive=True,
1082-
)
1088+
# file_big_npy2 = gr.Textbox(
1089+
# label=i18n("特征文件路径"),
1090+
# value="E:\\codes\\py39\\vits_vc_gpu_train\\logs\\mi-test-1key\\total_fea.npy",
1091+
# interactive=True,
1092+
# )
10831093
index_rate2 = gr.Slider(
10841094
minimum=0,
10851095
maximum=1,
@@ -1107,7 +1117,7 @@ def export_onnx(ModelPath, ExportedPath, MoeVS=True):
11071117
vc_transform1,
11081118
f0method1,
11091119
file_index2,
1110-
file_big_npy2,
1120+
# file_big_npy2,
11111121
index_rate2,
11121122
],
11131123
[vc_output3],

0 commit comments

Comments
 (0)