Next commited on
Commit
1c1294e
·
verified ·
1 Parent(s): 46ac88a

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -1474
app.py DELETED
@@ -1,1474 +0,0 @@
1
- import os, sys
2
- import datetime, subprocess
3
- from mega import Mega
4
- now_dir = os.getcwd()
5
- sys.path.append(now_dir)
6
- import logging
7
- import shutil
8
- import threading
9
- import traceback
10
- import warnings
11
- from random import shuffle
12
- from subprocess import Popen
13
- from time import sleep
14
- import json
15
- import pathlib
16
-
17
- import fairseq
18
- import faiss
19
- import gradio as gr
20
- import numpy as np
21
- import torch
22
- from dotenv import load_dotenv
23
- from sklearn.cluster import MiniBatchKMeans
24
-
25
- from configs.config import Config
26
- from i18n.i18n import I18nAuto
27
- from infer.lib.train.process_ckpt import (
28
- change_info,
29
- extract_small_model,
30
- merge,
31
- show_info,
32
- )
33
- from infer.modules.uvr5.modules import uvr
34
- from infer.modules.vc.modules import VC
35
- logging.getLogger("numba").setLevel(logging.WARNING)
36
-
37
- logger = logging.getLogger(__name__)
38
-
39
- tmp = os.path.join(now_dir, "TEMP")
40
- shutil.rmtree(tmp, ignore_errors=True)
41
- shutil.rmtree("%s/runtime/Lib/site-packages/infer_pack" % (now_dir), ignore_errors=True)
42
- shutil.rmtree("%s/runtime/Lib/site-packages/uvr5_pack" % (now_dir), ignore_errors=True)
43
- os.makedirs(tmp, exist_ok=True)
44
- os.makedirs(os.path.join(now_dir, "logs"), exist_ok=True)
45
- os.makedirs(os.path.join(now_dir, "assets/weights"), exist_ok=True)
46
- os.makedirs(os.path.join(now_dir, "audios"), exist_ok=True)
47
- os.environ["TEMP"] = tmp
48
- warnings.filterwarnings("ignore")
49
- torch.manual_seed(114514)
50
-
51
-
52
- load_dotenv()
53
- config = Config()
54
- vc = VC(config)
55
-
56
- if config.dml == True:
57
-
58
- def forward_dml(ctx, x, scale):
59
- ctx.scale = scale
60
- res = x.clone().detach()
61
- return res
62
-
63
- fairseq.modules.grad_multiply.GradMultiply.forward = forward_dml
64
- i18n = I18nAuto()
65
- logger.info(i18n)
66
- # 判断是否有能用来训练和加速推理的N卡
67
- ngpu = torch.cuda.device_count()
68
- gpu_infos = []
69
- mem = []
70
- if_gpu_ok = False
71
-
72
- if torch.cuda.is_available() or ngpu != 0:
73
- for i in range(ngpu):
74
- gpu_name = torch.cuda.get_device_name(i)
75
- if any(
76
- value in gpu_name.upper()
77
- for value in [
78
- "10",
79
- "16",
80
- "20",
81
- "30",
82
- "40",
83
- "A2",
84
- "A3",
85
- "A4",
86
- "P4",
87
- "A50",
88
- "500",
89
- "A60",
90
- "70",
91
- "80",
92
- "90",
93
- "M4",
94
- "T4",
95
- "TITAN",
96
- ]
97
- ):
98
- # A10#A100#V100#A40#P40#M40#K80#A4500
99
- if_gpu_ok = True # 至少有一张能用的N卡
100
- gpu_infos.append("%s\t%s" % (i, gpu_name))
101
- mem.append(
102
- int(
103
- torch.cuda.get_device_properties(i).total_memory
104
- / 1024
105
- / 1024
106
- / 1024
107
- + 0.4
108
- )
109
- )
110
- if if_gpu_ok and len(gpu_infos) > 0:
111
- gpu_info = "\n".join(gpu_infos)
112
- default_batch_size = min(mem) // 2
113
- else:
114
- gpu_info = i18n("很遗憾您这没有能用的显卡来支持您训练")
115
- default_batch_size = 1
116
- gpus = "-".join([i[0] for i in gpu_infos])
117
-
118
-
119
- class ToolButton(gr.Button, gr.components.FormComponent):
120
- """Small button with single emoji as text, fits inside gradio forms"""
121
-
122
- def __init__(self, **kwargs):
123
- super().__init__(variant="tool", **kwargs)
124
-
125
- def get_block_name(self):
126
- return "button"
127
-
128
-
129
- weight_root = os.getenv("weight_root")
130
- weight_uvr5_root = os.getenv("weight_uvr5_root")
131
- index_root = os.getenv("index_root")
132
-
133
- names = []
134
- for name in os.listdir(weight_root):
135
- if name.endswith(".pth"):
136
- names.append(name)
137
- index_paths = []
138
- for root, dirs, files in os.walk(index_root, topdown=False):
139
- for name in files:
140
- if name.endswith(".index") and "trained" not in name:
141
- index_paths.append("%s/%s" % (root, name))
142
- uvr5_names = []
143
- for name in os.listdir(weight_uvr5_root):
144
- if name.endswith(".pth") or "onnx" in name:
145
- uvr5_names.append(name.replace(".pth", ""))
146
-
147
-
148
- def change_choices():
149
- names = []
150
- for name in os.listdir(weight_root):
151
- if name.endswith(".pth"):
152
- names.append(name)
153
- index_paths = []
154
- for root, dirs, files in os.walk(index_root, topdown=False):
155
- for name in files:
156
- if name.endswith(".index") and "trained" not in name:
157
- index_paths.append("%s/%s" % (root, name))
158
- audio_files=[]
159
- for filename in os.listdir("./audios"):
160
- if filename.endswith(('.wav','.mp3','.ogg')):
161
- audio_files.append('./audios/'+filename)
162
- return {"choices": sorted(names), "__type__": "update"}, {
163
- "choices": sorted(index_paths),
164
- "__type__": "update",
165
- }, {"choices": sorted(audio_files), "__type__": "update"}
166
-
167
- def clean():
168
- return {"value": "", "__type__": "update"}
169
-
170
-
171
- def export_onnx():
172
- from infer.modules.onnx.export import export_onnx as eo
173
-
174
- eo()
175
-
176
-
177
- sr_dict = {
178
- "32k": 32000,
179
- "40k": 40000,
180
- "48k": 48000,
181
- }
182
-
183
-
184
- def if_done(done, p):
185
- while 1:
186
- if p.poll() is None:
187
- sleep(0.5)
188
- else:
189
- break
190
- done[0] = True
191
-
192
-
193
- def if_done_multi(done, ps):
194
- while 1:
195
- # poll==None代表进程未结束
196
- # 只要有一个进程未结束都不停
197
- flag = 1
198
- for p in ps:
199
- if p.poll() is None:
200
- flag = 0
201
- sleep(0.5)
202
- break
203
- if flag == 1:
204
- break
205
- done[0] = True
206
-
207
-
208
- def preprocess_dataset(trainset_dir, exp_dir, sr, n_p):
209
- sr = sr_dict[sr]
210
- os.makedirs("%s/logs/%s" % (now_dir, exp_dir), exist_ok=True)
211
- f = open("%s/logs/%s/preprocess.log" % (now_dir, exp_dir), "w")
212
- f.close()
213
- per = 3.0 if config.is_half else 3.7
214
- cmd = '"%s" infer/modules/train/preprocess.py "%s" %s %s "%s/logs/%s" %s %.1f' % (
215
- config.python_cmd,
216
- trainset_dir,
217
- sr,
218
- n_p,
219
- now_dir,
220
- exp_dir,
221
- config.noparallel,
222
- per,
223
- )
224
- logger.info(cmd)
225
- p = Popen(cmd, shell=True) # , stdin=PIPE, stdout=PIPE,stderr=PIPE,cwd=now_dir
226
- ###煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
227
- done = [False]
228
- threading.Thread(
229
- target=if_done,
230
- args=(
231
- done,
232
- p,
233
- ),
234
- ).start()
235
- while 1:
236
- with open("%s/logs/%s/preprocess.log" % (now_dir, exp_dir), "r") as f:
237
- yield (f.read())
238
- sleep(1)
239
- if done[0]:
240
- break
241
- with open("%s/logs/%s/preprocess.log" % (now_dir, exp_dir), "r") as f:
242
- log = f.read()
243
- logger.info(log)
244
- yield log
245
-
246
-
247
- # but2.click(extract_f0,[gpus6,np7,f0method8,if_f0_3,trainset_dir4],[info2])
248
- def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir, version19, gpus_rmvpe):
249
- gpus = gpus.split("-")
250
- os.makedirs("%s/logs/%s" % (now_dir, exp_dir), exist_ok=True)
251
- f = open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "w")
252
- f.close()
253
- if if_f0:
254
- if f0method != "rmvpe_gpu":
255
- cmd = (
256
- '"%s" infer/modules/train/extract/extract_f0_print.py "%s/logs/%s" %s %s'
257
- % (
258
- config.python_cmd,
259
- now_dir,
260
- exp_dir,
261
- n_p,
262
- f0method,
263
- )
264
- )
265
- logger.info(cmd)
266
- p = Popen(
267
- cmd, shell=True, cwd=now_dir
268
- ) # , stdin=PIPE, stdout=PIPE,stderr=PIPE
269
- ###煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
270
- done = [False]
271
- threading.Thread(
272
- target=if_done,
273
- args=(
274
- done,
275
- p,
276
- ),
277
- ).start()
278
- else:
279
- if gpus_rmvpe != "-":
280
- gpus_rmvpe = gpus_rmvpe.split("-")
281
- leng = len(gpus_rmvpe)
282
- ps = []
283
- for idx, n_g in enumerate(gpus_rmvpe):
284
- cmd = (
285
- '"%s" infer/modules/train/extract/extract_f0_rmvpe.py %s %s %s "%s/logs/%s" %s '
286
- % (
287
- config.python_cmd,
288
- leng,
289
- idx,
290
- n_g,
291
- now_dir,
292
- exp_dir,
293
- config.is_half,
294
- )
295
- )
296
- logger.info(cmd)
297
- p = Popen(
298
- cmd, shell=True, cwd=now_dir
299
- ) # , shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=now_dir
300
- ps.append(p)
301
- ###煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
302
- done = [False]
303
- threading.Thread(
304
- target=if_done_multi, #
305
- args=(
306
- done,
307
- ps,
308
- ),
309
- ).start()
310
- else:
311
- cmd = (
312
- config.python_cmd
313
- + ' infer/modules/train/extract/extract_f0_rmvpe_dml.py "%s/logs/%s" '
314
- % (
315
- now_dir,
316
- exp_dir,
317
- )
318
- )
319
- logger.info(cmd)
320
- p = Popen(
321
- cmd, shell=True, cwd=now_dir
322
- ) # , shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=now_dir
323
- p.wait()
324
- done = [True]
325
- while 1:
326
- with open(
327
- "%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r"
328
- ) as f:
329
- yield (f.read())
330
- sleep(1)
331
- if done[0]:
332
- break
333
- with open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r") as f:
334
- log = f.read()
335
- logger.info(log)
336
- yield log
337
- ####对不同part分别开多进程
338
- """
339
- n_part=int(sys.argv[1])
340
- i_part=int(sys.argv[2])
341
- i_gpu=sys.argv[3]
342
- exp_dir=sys.argv[4]
343
- os.environ["CUDA_VISIBLE_DEVICES"]=str(i_gpu)
344
- """
345
- leng = len(gpus)
346
- ps = []
347
- for idx, n_g in enumerate(gpus):
348
- cmd = (
349
- '"%s" infer/modules/train/extract_feature_print.py %s %s %s %s "%s/logs/%s" %s True'
350
- % (
351
- config.python_cmd,
352
- config.device,
353
- leng,
354
- idx,
355
- n_g,
356
- now_dir,
357
- exp_dir,
358
- version19,
359
- )
360
- )
361
- logger.info(cmd)
362
- p = Popen(
363
- cmd, shell=True, cwd=now_dir
364
- ) # , shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=now_dir
365
- ps.append(p)
366
- ###煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
367
- done = [False]
368
- threading.Thread(
369
- target=if_done_multi,
370
- args=(
371
- done,
372
- ps,
373
- ),
374
- ).start()
375
- while 1:
376
- with open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r") as f:
377
- yield (f.read())
378
- sleep(1)
379
- if done[0]:
380
- break
381
- with open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r") as f:
382
- log = f.read()
383
- logger.info(log)
384
- yield log
385
-
386
-
387
- def get_pretrained_models(path_str, f0_str, sr2):
388
- if_pretrained_generator_exist = os.access(
389
- "assets/pretrained%s/%sG%s.pth" % (path_str, f0_str, sr2), os.F_OK
390
- )
391
- if_pretrained_discriminator_exist = os.access(
392
- "assets/pretrained%s/%sD%s.pth" % (path_str, f0_str, sr2), os.F_OK
393
- )
394
- if not if_pretrained_generator_exist:
395
- logger.warn(
396
- "assets/pretrained%s/%sG%s.pth not exist, will not use pretrained model",
397
- path_str,
398
- f0_str,
399
- sr2,
400
- )
401
- if not if_pretrained_discriminator_exist:
402
- logger.warn(
403
- "assets/pretrained%s/%sD%s.pth not exist, will not use pretrained model",
404
- path_str,
405
- f0_str,
406
- sr2,
407
- )
408
- return (
409
- "assets/pretrained%s/%sG%s.pth" % (path_str, f0_str, sr2)
410
- if if_pretrained_generator_exist
411
- else "",
412
- "assets/pretrained%s/%sD%s.pth" % (path_str, f0_str, sr2)
413
- if if_pretrained_discriminator_exist
414
- else "",
415
- )
416
-
417
-
418
- def change_sr2(sr2, if_f0_3, version19):
419
- path_str = "" if version19 == "v1" else "_v2"
420
- f0_str = "f0" if if_f0_3 else ""
421
- return get_pretrained_models(path_str, f0_str, sr2)
422
-
423
-
424
- def change_version19(sr2, if_f0_3, version19):
425
- path_str = "" if version19 == "v1" else "_v2"
426
- if sr2 == "32k" and version19 == "v1":
427
- sr2 = "40k"
428
- to_return_sr2 = (
429
- {"choices": ["40k", "48k"], "__type__": "update", "value": sr2}
430
- if version19 == "v1"
431
- else {"choices": ["40k", "48k", "32k"], "__type__": "update", "value": sr2}
432
- )
433
- f0_str = "f0" if if_f0_3 else ""
434
- return (
435
- *get_pretrained_models(path_str, f0_str, sr2),
436
- to_return_sr2,
437
- )
438
-
439
-
440
- def change_f0(if_f0_3, sr2, version19): # f0method8,pretrained_G14,pretrained_D15
441
- path_str = "" if version19 == "v1" else "_v2"
442
- return (
443
- {"visible": if_f0_3, "__type__": "update"},
444
- *get_pretrained_models(path_str, "f0", sr2),
445
- )
446
-
447
-
448
- # but3.click(click_train,[exp_dir1,sr2,if_f0_3,save_epoch10,total_epoch11,batch_size12,if_save_latest13,pretrained_G14,pretrained_D15,gpus16])
449
- def click_train(
450
- exp_dir1,
451
- sr2,
452
- if_f0_3,
453
- spk_id5,
454
- save_epoch10,
455
- total_epoch11,
456
- batch_size12,
457
- if_save_latest13,
458
- pretrained_G14,
459
- pretrained_D15,
460
- gpus16,
461
- if_cache_gpu17,
462
- if_save_every_weights18,
463
- version19,
464
- ):
465
- # 生成filelist
466
- exp_dir = "%s/logs/%s" % (now_dir, exp_dir1)
467
- os.makedirs(exp_dir, exist_ok=True)
468
- gt_wavs_dir = "%s/0_gt_wavs" % (exp_dir)
469
- feature_dir = (
470
- "%s/3_feature256" % (exp_dir)
471
- if version19 == "v1"
472
- else "%s/3_feature768" % (exp_dir)
473
- )
474
- if if_f0_3:
475
- f0_dir = "%s/2a_f0" % (exp_dir)
476
- f0nsf_dir = "%s/2b-f0nsf" % (exp_dir)
477
- names = (
478
- set([name.split(".")[0] for name in os.listdir(gt_wavs_dir)])
479
- & set([name.split(".")[0] for name in os.listdir(feature_dir)])
480
- & set([name.split(".")[0] for name in os.listdir(f0_dir)])
481
- & set([name.split(".")[0] for name in os.listdir(f0nsf_dir)])
482
- )
483
- else:
484
- names = set([name.split(".")[0] for name in os.listdir(gt_wavs_dir)]) & set(
485
- [name.split(".")[0] for name in os.listdir(feature_dir)]
486
- )
487
- opt = []
488
- for name in names:
489
- if if_f0_3:
490
- opt.append(
491
- "%s/%s.wav|%s/%s.npy|%s/%s.wav.npy|%s/%s.wav.npy|%s"
492
- % (
493
- gt_wavs_dir.replace("\\", "\\\\"),
494
- name,
495
- feature_dir.replace("\\", "\\\\"),
496
- name,
497
- f0_dir.replace("\\", "\\\\"),
498
- name,
499
- f0nsf_dir.replace("\\", "\\\\"),
500
- name,
501
- spk_id5,
502
- )
503
- )
504
- else:
505
- opt.append(
506
- "%s/%s.wav|%s/%s.npy|%s"
507
- % (
508
- gt_wavs_dir.replace("\\", "\\\\"),
509
- name,
510
- feature_dir.replace("\\", "\\\\"),
511
- name,
512
- spk_id5,
513
- )
514
- )
515
- fea_dim = 256 if version19 == "v1" else 768
516
- if if_f0_3:
517
- for _ in range(2):
518
- opt.append(
519
- "%s/logs/mute/0_gt_wavs/mute%s.wav|%s/logs/mute/3_feature%s/mute.npy|%s/logs/mute/2a_f0/mute.wav.npy|%s/logs/mute/2b-f0nsf/mute.wav.npy|%s"
520
- % (now_dir, sr2, now_dir, fea_dim, now_dir, now_dir, spk_id5)
521
- )
522
- else:
523
- for _ in range(2):
524
- opt.append(
525
- "%s/logs/mute/0_gt_wavs/mute%s.wav|%s/logs/mute/3_feature%s/mute.npy|%s"
526
- % (now_dir, sr2, now_dir, fea_dim, spk_id5)
527
- )
528
- shuffle(opt)
529
- with open("%s/filelist.txt" % exp_dir, "w") as f:
530
- f.write("\n".join(opt))
531
- logger.debug("Write filelist done")
532
- # 生成config#无需生成config
533
- # 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"
534
- logger.info("Use gpus: %s", str(gpus16))
535
- if pretrained_G14 == "":
536
- logger.info("No pretrained Generator")
537
- if pretrained_D15 == "":
538
- logger.info("No pretrained Discriminator")
539
- if version19 == "v1" or sr2 == "40k":
540
- config_path = "v1/%s.json" % sr2
541
- else:
542
- config_path = "v2/%s.json" % sr2
543
- config_save_path = os.path.join(exp_dir, "config.json")
544
- if not pathlib.Path(config_save_path).exists():
545
- with open(config_save_path, "w", encoding="utf-8") as f:
546
- json.dump(
547
- config.json_config[config_path],
548
- f,
549
- ensure_ascii=False,
550
- indent=4,
551
- sort_keys=True,
552
- )
553
- f.write("\n")
554
- if gpus16:
555
- cmd = (
556
- '"%s" infer/modules/train/train.py -e "%s" -sr %s -f0 %s -bs %s -g %s -te %s -se %s %s %s -l %s -c %s -sw %s -v %s'
557
- % (
558
- config.python_cmd,
559
- exp_dir1,
560
- sr2,
561
- 1 if if_f0_3 else 0,
562
- batch_size12,
563
- gpus16,
564
- total_epoch11,
565
- save_epoch10,
566
- "-pg %s" % pretrained_G14 if pretrained_G14 != "" else "",
567
- "-pd %s" % pretrained_D15 if pretrained_D15 != "" else "",
568
- 1 if if_save_latest13 == i18n("是") else 0,
569
- 1 if if_cache_gpu17 == i18n("是") else 0,
570
- 1 if if_save_every_weights18 == i18n("是") else 0,
571
- version19,
572
- )
573
- )
574
- else:
575
- cmd = (
576
- '"%s" infer/modules/train/train.py -e "%s" -sr %s -f0 %s -bs %s -te %s -se %s %s %s -l %s -c %s -sw %s -v %s'
577
- % (
578
- config.python_cmd,
579
- exp_dir1,
580
- sr2,
581
- 1 if if_f0_3 else 0,
582
- batch_size12,
583
- total_epoch11,
584
- save_epoch10,
585
- "-pg %s" % pretrained_G14 if pretrained_G14 != "" else "",
586
- "-pd %s" % pretrained_D15 if pretrained_D15 != "" else "",
587
- 1 if if_save_latest13 == i18n("是") else 0,
588
- 1 if if_cache_gpu17 == i18n("是") else 0,
589
- 1 if if_save_every_weights18 == i18n("是") else 0,
590
- version19,
591
- )
592
- )
593
- logger.info(cmd)
594
- p = Popen(cmd, shell=True, cwd=now_dir)
595
- p.wait()
596
- return "训练结束, 您可查看控制台训练日志或实验文件夹下的train.log"
597
-
598
-
599
- # but4.click(train_index, [exp_dir1], info3)
600
- def train_index(exp_dir1, version19):
601
- # exp_dir = "%s/logs/%s" % (now_dir, exp_dir1)
602
- exp_dir = "logs/%s" % (exp_dir1)
603
- os.makedirs(exp_dir, exist_ok=True)
604
- feature_dir = (
605
- "%s/3_feature256" % (exp_dir)
606
- if version19 == "v1"
607
- else "%s/3_feature768" % (exp_dir)
608
- )
609
- if not os.path.exists(feature_dir):
610
- return "请先进行特征提取!"
611
- listdir_res = list(os.listdir(feature_dir))
612
- if len(listdir_res) == 0:
613
- return "请先进行特征提取!"
614
- infos = []
615
- npys = []
616
- for name in sorted(listdir_res):
617
- phone = np.load("%s/%s" % (feature_dir, name))
618
- npys.append(phone)
619
- big_npy = np.concatenate(npys, 0)
620
- big_npy_idx = np.arange(big_npy.shape[0])
621
- np.random.shuffle(big_npy_idx)
622
- big_npy = big_npy[big_npy_idx]
623
- if big_npy.shape[0] > 2e5:
624
- infos.append("Trying doing kmeans %s shape to 10k centers." % big_npy.shape[0])
625
- yield "\n".join(infos)
626
- try:
627
- big_npy = (
628
- MiniBatchKMeans(
629
- n_clusters=10000,
630
- verbose=True,
631
- batch_size=256 * config.n_cpu,
632
- compute_labels=False,
633
- init="random",
634
- )
635
- .fit(big_npy)
636
- .cluster_centers_
637
- )
638
- except:
639
- info = traceback.format_exc()
640
- logger.info(info)
641
- infos.append(info)
642
- yield "\n".join(infos)
643
-
644
- np.save("%s/total_fea.npy" % exp_dir, big_npy)
645
- n_ivf = min(int(16 * np.sqrt(big_npy.shape[0])), big_npy.shape[0] // 39)
646
- infos.append("%s,%s" % (big_npy.shape, n_ivf))
647
- yield "\n".join(infos)
648
- index = faiss.index_factory(256 if version19 == "v1" else 768, "IVF%s,Flat" % n_ivf)
649
- # index = faiss.index_factory(256if version19=="v1"else 768, "IVF%s,PQ128x4fs,RFlat"%n_ivf)
650
- infos.append("training")
651
- yield "\n".join(infos)
652
- index_ivf = faiss.extract_index_ivf(index) #
653
- index_ivf.nprobe = 1
654
- index.train(big_npy)
655
- faiss.write_index(
656
- index,
657
- "%s/trained_IVF%s_Flat_nprobe_%s_%s_%s.index"
658
- % (exp_dir, n_ivf, index_ivf.nprobe, exp_dir1, version19),
659
- )
660
-
661
- infos.append("adding")
662
- yield "\n".join(infos)
663
- batch_size_add = 8192
664
- for i in range(0, big_npy.shape[0], batch_size_add):
665
- index.add(big_npy[i : i + batch_size_add])
666
- faiss.write_index(
667
- index,
668
- "%s/added_IVF%s_Flat_nprobe_%s_%s_%s.index"
669
- % (exp_dir, n_ivf, index_ivf.nprobe, exp_dir1, version19),
670
- )
671
- infos.append(
672
- "成功构建索引,added_IVF%s_Flat_nprobe_%s_%s_%s.index"
673
- % (n_ivf, index_ivf.nprobe, exp_dir1, version19)
674
- )
675
- # faiss.write_index(index, '%s/added_IVF%s_Flat_FastScan_%s.index'%(exp_dir,n_ivf,version19))
676
- # infos.append("成功构建索引,added_IVF%s_Flat_FastScan_%s.index"%(n_ivf,version19))
677
- yield "\n".join(infos)
678
-
679
-
680
- # but5.click(train1key, [exp_dir1, sr2, if_f0_3, trainset_dir4, spk_id5, gpus6, np7, f0method8, save_epoch10, total_epoch11, batch_size12, if_save_latest13, pretrained_G14, pretrained_D15, gpus16, if_cache_gpu17], info3)
681
- def train1key(
682
- exp_dir1,
683
- sr2,
684
- if_f0_3,
685
- trainset_dir4,
686
- spk_id5,
687
- np7,
688
- f0method8,
689
- save_epoch10,
690
- total_epoch11,
691
- batch_size12,
692
- if_save_latest13,
693
- pretrained_G14,
694
- pretrained_D15,
695
- gpus16,
696
- if_cache_gpu17,
697
- if_save_every_weights18,
698
- version19,
699
- gpus_rmvpe,
700
- ):
701
- infos = []
702
-
703
- def get_info_str(strr):
704
- infos.append(strr)
705
- return "\n".join(infos)
706
-
707
- ####### step1:处理数据
708
- yield get_info_str(i18n("step1:正在处理数据"))
709
- [get_info_str(_) for _ in preprocess_dataset(trainset_dir4, exp_dir1, sr2, np7)]
710
-
711
- ####### step2a:提取音高
712
- yield get_info_str(i18n("step2:正在提取音高&正在提取特征"))
713
- [
714
- get_info_str(_)
715
- for _ in extract_f0_feature(
716
- gpus16, np7, f0method8, if_f0_3, exp_dir1, version19, gpus_rmvpe
717
- )
718
- ]
719
-
720
- ####### step3a:训练模型
721
- yield get_info_str(i18n("step3a:正在训练模型"))
722
- click_train(
723
- exp_dir1,
724
- sr2,
725
- if_f0_3,
726
- spk_id5,
727
- save_epoch10,
728
- total_epoch11,
729
- batch_size12,
730
- if_save_latest13,
731
- pretrained_G14,
732
- pretrained_D15,
733
- gpus16,
734
- if_cache_gpu17,
735
- if_save_every_weights18,
736
- version19,
737
- )
738
- yield get_info_str(i18n("训练结束, 您可查看控制台训练日志或实验文件夹下的train.log"))
739
-
740
- ####### step3b:训练索引
741
- [get_info_str(_) for _ in train_index(exp_dir1, version19)]
742
- yield get_info_str(i18n("全流程结束!"))
743
-
744
-
745
- # ckpt_path2.change(change_info_,[ckpt_path2],[sr__,if_f0__])
746
- def change_info_(ckpt_path):
747
- if not os.path.exists(ckpt_path.replace(os.path.basename(ckpt_path), "train.log")):
748
- return {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}
749
- try:
750
- with open(
751
- ckpt_path.replace(os.path.basename(ckpt_path), "train.log"), "r"
752
- ) as f:
753
- info = eval(f.read().strip("\n").split("\n")[0].split("\t")[-1])
754
- sr, f0 = info["sample_rate"], info["if_f0"]
755
- version = "v2" if ("version" in info and info["version"] == "v2") else "v1"
756
- return sr, str(f0), version
757
- except:
758
- traceback.print_exc()
759
- return {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}
760
-
761
-
762
- F0GPUVisible = config.dml == False
763
-
764
-
765
- def change_f0_method(f0method8):
766
- if f0method8 == "rmvpe_gpu":
767
- visible = F0GPUVisible
768
- else:
769
- visible = False
770
- return {"visible": visible, "__type__": "update"}
771
-
772
- def find_model():
773
- if len(names) > 0:
774
- vc.get_vc(sorted(names)[0],None,None)
775
- return sorted(names)[0]
776
- else:
777
- try:
778
- gr.Info("Do not forget to choose a model.")
779
- except:
780
- pass
781
- return ''
782
-
783
- def find_audios(index=False):
784
- audio_files=[]
785
- if not os.path.exists('./audios'): os.mkdir("./audios")
786
- for filename in os.listdir("./audios"):
787
- if filename.endswith(('.wav','.mp3','.ogg')):
788
- audio_files.append("./audios/"+filename)
789
- if index:
790
- if len(audio_files) > 0: return sorted(audio_files)[0]
791
- else: return ""
792
- elif len(audio_files) > 0: return sorted(audio_files)
793
- else: return []
794
-
795
- def get_index():
796
- if find_model() != '':
797
- chosen_model=sorted(names)[0].split(".")[0]
798
- logs_path="./logs/"+chosen_model
799
- if os.path.exists(logs_path):
800
- for file in os.listdir(logs_path):
801
- if file.endswith(".index"):
802
- return os.path.join(logs_path, file)
803
- return ''
804
- else:
805
- return ''
806
-
807
- def get_indexes():
808
- indexes_list=[]
809
- for dirpath, dirnames, filenames in os.walk("./logs/"):
810
- for filename in filenames:
811
- if filename.endswith(".index"):
812
- indexes_list.append(os.path.join(dirpath,filename))
813
- if len(indexes_list) > 0:
814
- return indexes_list
815
- else:
816
- return ''
817
-
818
- def save_wav(file):
819
- try:
820
- file_path=file.name
821
- shutil.move(file_path,'./audios')
822
- return './audios/'+os.path.basename(file_path)
823
- except AttributeError:
824
- try:
825
- new_name = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")+'.wav'
826
- new_path='./audios/'+new_name
827
- shutil.move(file,new_path)
828
- return new_path
829
- except TypeError:
830
- return None
831
-
832
- def download_from_url(url, model):
833
- if model =='':
834
- try:
835
- model = url.split('/')[-1].split('?')[0]
836
- except:
837
- return "You need to name your model. For example: My-Model"
838
- url=url.replace('/blob/main/','/resolve/main/')
839
- model=model.replace('.pth','').replace('.index','').replace('.zip','')
840
- if url == '':
841
- return "URL cannot be left empty."
842
- url = url.strip()
843
- zip_dirs = ["zips", "unzips"]
844
- for directory in zip_dirs:
845
- if os.path.exists(directory):
846
- shutil.rmtree(directory)
847
- os.makedirs("zips", exist_ok=True)
848
- os.makedirs("unzips", exist_ok=True)
849
- zipfile = model + '.zip'
850
- zipfile_path = './zips/' + zipfile
851
- try:
852
- if url.endswith('.pth'):
853
- subprocess.run(["wget", url, "-O", f'./assets/weights/{model}.pth'])
854
- return f"Sucessfully downloaded as {model}.pth"
855
- if url.endswith('.index'):
856
- if not os.path.exists(f'./logs/{model}'): os.makedirs(f'./logs/{model}')
857
- subprocess.run(["wget", url, "-O", f'./logs/{model}/added_{model}.index'])
858
- return f"Successfully downloaded as added_{model}.index"
859
- if "drive.google.com" in url:
860
- subprocess.run(["gdown", url, "--fuzzy", "-O", zipfile_path])
861
- elif "mega.nz" in url:
862
- m = Mega()
863
- m.download_url(url, './zips')
864
- else:
865
- subprocess.run(["wget", url, "-O", zipfile_path])
866
- for filename in os.listdir("./zips"):
867
- if filename.endswith(".zip"):
868
- zipfile_path = os.path.join("./zips/",filename)
869
- shutil.unpack_archive(zipfile_path, "./unzips", 'zip')
870
- else:
871
- return "No zipfile found."
872
- for root, dirs, files in os.walk('./unzips'):
873
- for file in files:
874
- file_path = os.path.join(root, file)
875
- if file.endswith(".index"):
876
- os.mkdir(f'./logs/{model}')
877
- shutil.copy2(file_path,f'./logs/{model}')
878
- elif "G_" not in file and "D_" not in file and file.endswith(".pth"):
879
- shutil.copy(file_path,f'./assets/weights/{model}.pth')
880
- shutil.rmtree("zips")
881
- shutil.rmtree("unzips")
882
- return "Success."
883
- except:
884
- return "There's been an error."
885
-
886
- def upload_to_dataset(files, dir):
887
- if dir == '':
888
- dir = './dataset/'+datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
889
- if not os.path.exists(dir):
890
- os.makedirs(dir)
891
- for file in files:
892
- path=file.name
893
- shutil.copy2(path,dir)
894
- try:
895
- gr.Info(i18n("处理数据"))
896
- except:
897
- pass
898
- return i18n("处理数据"), {"value":dir,"__type__":"update"}
899
-
900
- def download_model_files(model):
901
- model_found = False
902
- index_found = False
903
- if os.path.exists(f'./assets/weights/{model}.pth'): model_found = True
904
- if os.path.exists(f'./logs/{model}'):
905
- for file in os.listdir(f'./logs/{model}'):
906
- if file.endswith('.index') and 'added' in file:
907
- log_file = file
908
- index_found = True
909
- if model_found and index_found:
910
- return [f'./assets/weights/{model}.pth', f'./logs/{model}/{log_file}'], "Done"
911
- elif model_found and not index_found:
912
- return f'./assets/weights/{model}.pth', "Could not find Index file."
913
- elif index_found and not model_found:
914
- return f'./logs/{model}/{log_file}', f'Make sure the Voice Name is correct. I could not find {model}.pth'
915
- else:
916
- return None, f'Could not find {model}.pth or corresponding Index file.'
917
-
918
- def update_visibility(visible):
919
- if visible:
920
- return {"visible":True,"__type__":"update"},{"visible":True,"__type__":"update"}
921
- else:
922
- return {"visible":False,"__type__":"update"},{"visible":False,"__type__":"update"}
923
-
924
- def get_pretrains(string):
925
- pretrains = []
926
- for file in os.listdir('assets/pretrained_v2'):
927
- if string in file:
928
- pretrains.append(os.path.join('assets/pretrained_v2',file))
929
- return pretrains
930
-
931
- with gr.Blocks(title="🔊",theme=gr.themes.Base(primary_hue="rose",neutral_hue="zinc")) as app:
932
- with gr.Row():
933
- gr.HTML("<img src='file/a.png' alt='image'>")
934
- with gr.Tabs():
935
- with gr.TabItem(i18n("模型推理")):
936
- with gr.Row():
937
- sid0 = gr.Dropdown(label=i18n("推理音色"), choices=sorted(names), value=find_model())
938
- refresh_button = gr.Button(i18n("刷新音色列表和索引路径"), variant="primary")
939
- #clean_button = gr.Button(i18n("卸载音色省显存"), variant="primary")
940
- spk_item = gr.Slider(
941
- minimum=0,
942
- maximum=2333,
943
- step=1,
944
- label=i18n("请选择说话人id"),
945
- value=0,
946
- visible=False,
947
- interactive=True,
948
- )
949
- #clean_button.click(
950
- # fn=clean, inputs=[], outputs=[sid0], api_name="infer_clean"
951
- #)
952
- vc_transform0 = gr.Number(
953
- label=i18n("变调(整数, 半音数量, 升八度12降八度-12)"), value=0
954
- )
955
- but0 = gr.Button(i18n("转换"), variant="primary")
956
- with gr.Row():
957
- with gr.Column():
958
- with gr.Row():
959
- dropbox = gr.File(label="Drop your audio here & hit the Reload button.")
960
- with gr.Row():
961
- record_button=gr.Audio(source="microphone", label="OR Record audio.", type="filepath")
962
- with gr.Row():
963
- input_audio0 = gr.Dropdown(
964
- label=i18n("输入待处理音频文件路径(默认是正确格式示例)"),
965
- value=find_audios(True),
966
- choices=find_audios()
967
- )
968
- record_button.change(fn=save_wav, inputs=[record_button], outputs=[input_audio0])
969
- dropbox.upload(fn=save_wav, inputs=[dropbox], outputs=[input_audio0])
970
- with gr.Column():
971
- with gr.Accordion(label=i18n("自动检测index路径,下拉式选择(dropdown)"), open=False):
972
- file_index2 = gr.Dropdown(
973
- label=i18n("自动检测index路径,下拉式选择(dropdown)"),
974
- choices=get_indexes(),
975
- interactive=True,
976
- value=get_index()
977
- )
978
- index_rate1 = gr.Slider(
979
- minimum=0,
980
- maximum=1,
981
- label=i18n("检索特征占比"),
982
- value=0.66,
983
- interactive=True,
984
- )
985
- vc_output2 = gr.Audio(label=i18n("输出音频(右下角三个点,点了可以下载)"))
986
- with gr.Accordion(label=i18n("常规设置"), open=False):
987
- f0method0 = gr.Radio(
988
- label=i18n(
989
- "选择音高提取算法,输入歌声可用pm提速,harvest低音好但巨慢无比,crepe效果好但吃GPU,rmvpe效果最好且微吃GPU"
990
- ),
991
- choices=["pm", "harvest", "crepe", "rmvpe"]
992
- if config.dml == False
993
- else ["pm", "harvest", "rmvpe"],
994
- value="rmvpe",
995
- interactive=True,
996
- )
997
- filter_radius0 = gr.Slider(
998
- minimum=0,
999
- maximum=7,
1000
- label=i18n(">=3则使用对harvest音高识别的结果使用中值滤波,数值为滤波半径,使用可以削弱哑音"),
1001
- value=3,
1002
- step=1,
1003
- interactive=True,
1004
- )
1005
- resample_sr0 = gr.Slider(
1006
- minimum=0,
1007
- maximum=48000,
1008
- label=i18n("后处理重采样至最终采样率,0为不进行重采样"),
1009
- value=0,
1010
- step=1,
1011
- interactive=True,
1012
- visible=False
1013
- )
1014
- rms_mix_rate0 = gr.Slider(
1015
- minimum=0,
1016
- maximum=1,
1017
- label=i18n("输入源音量包络替换输出音量包络融合比例,越靠近1越使用输出包络"),
1018
- value=0.21,
1019
- interactive=True,
1020
- )
1021
- protect0 = gr.Slider(
1022
- minimum=0,
1023
- maximum=0.5,
1024
- label=i18n(
1025
- "保护清辅音和呼吸声,防止电音撕裂等artifact,拉满0.5不开启,调低加大保护力度但可能降低索引效果"
1026
- ),
1027
- value=0.33,
1028
- step=0.01,
1029
- interactive=True,
1030
- )
1031
- file_index1 = gr.Textbox(
1032
- label=i18n("特征检索库文件路径,为空则使用下拉的选择结果"),
1033
- value="",
1034
- interactive=True,
1035
- visible=False
1036
- )
1037
- refresh_button.click(
1038
- fn=change_choices,
1039
- inputs=[],
1040
- outputs=[sid0, file_index2, input_audio0],
1041
- api_name="infer_refresh",
1042
- )
1043
- # file_big_npy1 = gr.Textbox(
1044
- # label=i18n("特征文件路径"),
1045
- # value="E:\\codes\py39\\vits_vc_gpu_train\\logs\\mi-test-1key\\total_fea.npy",
1046
- # interactive=True,
1047
- # )
1048
- with gr.Row():
1049
- f0_file = gr.File(label=i18n("F0曲线文件, 可选, 一行一个音高, 代替默认F0及升降调"), visible=False)
1050
- with gr.Row():
1051
- vc_output1 = gr.Textbox(label=i18n("输出信息"))
1052
- but0.click(
1053
- vc.vc_single,
1054
- [
1055
- spk_item,
1056
- input_audio0,
1057
- vc_transform0,
1058
- f0_file,
1059
- f0method0,
1060
- file_index1,
1061
- file_index2,
1062
- # file_big_npy1,
1063
- index_rate1,
1064
- filter_radius0,
1065
- resample_sr0,
1066
- rms_mix_rate0,
1067
- protect0,
1068
- ],
1069
- [vc_output1, vc_output2],
1070
- api_name="infer_convert",
1071
- )
1072
- with gr.Row():
1073
- with gr.Accordion(open=False, label=i18n("批量转换, 输入待转换音频文件夹, 或上传多个音频文件, 在指定文件夹(默认opt)下输出转换的音频. ")):
1074
- with gr.Row():
1075
- opt_input = gr.Textbox(label=i18n("指定输出文件夹"), value="opt")
1076
- vc_transform1 = gr.Number(
1077
- label=i18n("变调(整数, 半音数量, 升八度12降八度-12)"), value=0
1078
- )
1079
- f0method1 = gr.Radio(
1080
- label=i18n(
1081
- "选择音高提取算法,输入歌声可用pm提速,harvest低音好但巨慢无比,crepe效果好但吃GPU,rmvpe效果最好且微吃GPU"
1082
- ),
1083
- choices=["pm", "harvest", "crepe", "rmvpe"]
1084
- if config.dml == False
1085
- else ["pm", "harvest", "rmvpe"],
1086
- value="pm",
1087
- interactive=True,
1088
- )
1089
- with gr.Row():
1090
- filter_radius1 = gr.Slider(
1091
- minimum=0,
1092
- maximum=7,
1093
- label=i18n(">=3则使用对harvest音高识别的结果使用中值滤波,数值为滤波半径,使用可以削弱哑音"),
1094
- value=3,
1095
- step=1,
1096
- interactive=True,
1097
- visible=False
1098
- )
1099
- with gr.Row():
1100
- file_index3 = gr.Textbox(
1101
- label=i18n("特征检索库文件路径,为空则使用下拉的选择结果"),
1102
- value="",
1103
- interactive=True,
1104
- visible=False
1105
- )
1106
- file_index4 = gr.Dropdown(
1107
- label=i18n("自动检测index路径,下拉式选择(dropdown)"),
1108
- choices=sorted(index_paths),
1109
- interactive=True,
1110
- visible=False
1111
- )
1112
- refresh_button.click(
1113
- fn=lambda: change_choices()[1],
1114
- inputs=[],
1115
- outputs=file_index4,
1116
- api_name="infer_refresh_batch",
1117
- )
1118
- # file_big_npy2 = gr.Textbox(
1119
- # label=i18n("特征文件路径"),
1120
- # value="E:\\codes\\py39\\vits_vc_gpu_train\\logs\\mi-test-1key\\total_fea.npy",
1121
- # interactive=True,
1122
- # )
1123
- index_rate2 = gr.Slider(
1124
- minimum=0,
1125
- maximum=1,
1126
- label=i18n("检索特征占比"),
1127
- value=1,
1128
- interactive=True,
1129
- visible=False
1130
- )
1131
- with gr.Row():
1132
- resample_sr1 = gr.Slider(
1133
- minimum=0,
1134
- maximum=48000,
1135
- label=i18n("后处理重采样至最终采样率,0为不进行重采样"),
1136
- value=0,
1137
- step=1,
1138
- interactive=True,
1139
- visible=False
1140
- )
1141
- rms_mix_rate1 = gr.Slider(
1142
- minimum=0,
1143
- maximum=1,
1144
- label=i18n("输入源音量包络替换输出音量包络融合比例,越靠近1越使用输出包络"),
1145
- value=0.21,
1146
- interactive=True,
1147
- )
1148
- protect1 = gr.Slider(
1149
- minimum=0,
1150
- maximum=0.5,
1151
- label=i18n(
1152
- "保护清辅音和呼吸声,防止电音撕裂等artifact,拉满0.5不开启,调低加大保护力度但可能降低索引效果"
1153
- ),
1154
- value=0.33,
1155
- step=0.01,
1156
- interactive=True,
1157
- )
1158
- with gr.Row():
1159
- dir_input = gr.Textbox(
1160
- label=i18n("输入待处理音频文件夹路径(去文件管理器地址栏拷就行了)"),
1161
- value="./audios",
1162
- )
1163
- inputs = gr.File(
1164
- file_count="multiple", label=i18n("也可批量输入音频文件, 二选一, 优先读文件夹")
1165
- )
1166
- with gr.Row():
1167
- format1 = gr.Radio(
1168
- label=i18n("导出文件格式"),
1169
- choices=["wav", "flac", "mp3", "m4a"],
1170
- value="wav",
1171
- interactive=True,
1172
- )
1173
- but1 = gr.Button(i18n("转换"), variant="primary")
1174
- vc_output3 = gr.Textbox(label=i18n("输出信息"))
1175
- but1.click(
1176
- vc.vc_multi,
1177
- [
1178
- spk_item,
1179
- dir_input,
1180
- opt_input,
1181
- inputs,
1182
- vc_transform1,
1183
- f0method1,
1184
- file_index1,
1185
- file_index2,
1186
- # file_big_npy2,
1187
- index_rate1,
1188
- filter_radius1,
1189
- resample_sr1,
1190
- rms_mix_rate1,
1191
- protect1,
1192
- format1,
1193
- ],
1194
- [vc_output3],
1195
- api_name="infer_convert_batch",
1196
- )
1197
- sid0.change(
1198
- fn=vc.get_vc,
1199
- inputs=[sid0, protect0, protect1],
1200
- outputs=[spk_item, protect0, protect1, file_index2, file_index4],
1201
- )
1202
- with gr.TabItem("Download Model"):
1203
- with gr.Row():
1204
- url=gr.Textbox(label="Enter the URL to the Model:")
1205
- with gr.Row():
1206
- model = gr.Textbox(label="Name your model:")
1207
- download_button=gr.Button("Download")
1208
- with gr.Row():
1209
- status_bar=gr.Textbox(label="")
1210
- download_button.click(fn=download_from_url, inputs=[url, model], outputs=[status_bar])
1211
- with gr.Row():
1212
- gr.Markdown(
1213
- """
1214
- ❤️ If you use this and like it, help me keep it.❤️
1215
- https://paypal.me/lesantillan
1216
- """
1217
- )
1218
- with gr.TabItem(i18n("训练")):
1219
- with gr.Row():
1220
- with gr.Column():
1221
- exp_dir1 = gr.Textbox(label=i18n("输入实验名"), value="My-Voice")
1222
- np7 = gr.Slider(
1223
- minimum=0,
1224
- maximum=config.n_cpu,
1225
- step=1,
1226
- label=i18n("提取音高和处理数据使用的CPU进程数"),
1227
- value=int(np.ceil(config.n_cpu / 1.5)),
1228
- interactive=True,
1229
- )
1230
- sr2 = gr.Radio(
1231
- label=i18n("目标采样率"),
1232
- choices=["40k", "32k"],
1233
- value="40k",
1234
- interactive=True,
1235
- visible=True
1236
- )
1237
- if_f0_3 = gr.Radio(
1238
- label=i18n("模型是否带音高指导(唱歌一定要, 语音可以不要)"),
1239
- choices=[True, False],
1240
- value=True,
1241
- interactive=True,
1242
- visible=False
1243
- )
1244
- version19 = gr.Radio(
1245
- label=i18n("版本"),
1246
- choices=["v1", "v2"],
1247
- value="v2",
1248
- interactive=True,
1249
- visible=False,
1250
- )
1251
- trainset_dir4 = gr.Textbox(
1252
- label=i18n("输入训练文件夹路径"), value='./dataset/'+datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
1253
- )
1254
- easy_uploader = gr.Files(label=i18n("也可批量输入音频文件, 二选一, 优先读文件夹"),file_types=['audio'])
1255
- but1 = gr.Button(i18n("处理数据"), variant="primary")
1256
- info1 = gr.Textbox(label=i18n("输出信息"), value="")
1257
- easy_uploader.upload(fn=upload_to_dataset, inputs=[easy_uploader, trainset_dir4], outputs=[info1, trainset_dir4])
1258
- gpus6 = gr.Textbox(
1259
- label=i18n("以-分隔输入使用的卡号, 例如 0-1-2 使用卡0和卡1和卡2"),
1260
- value=gpus,
1261
- interactive=True,
1262
- visible=F0GPUVisible,
1263
- )
1264
- gpu_info9 = gr.Textbox(
1265
- label=i18n("显卡信息"), value=gpu_info, visible=F0GPUVisible
1266
- )
1267
- spk_id5 = gr.Slider(
1268
- minimum=0,
1269
- maximum=4,
1270
- step=1,
1271
- label=i18n("请指定说话人id"),
1272
- value=0,
1273
- interactive=True,
1274
- visible=False
1275
- )
1276
- but1.click(
1277
- preprocess_dataset,
1278
- [trainset_dir4, exp_dir1, sr2, np7],
1279
- [info1],
1280
- api_name="train_preprocess",
1281
- )
1282
- with gr.Column():
1283
- f0method8 = gr.Radio(
1284
- label=i18n(
1285
- "选择音高提取算法:输入歌声可用pm提速,高质量语音但CPU差可用dio提速,harvest质量更好但慢,rmvpe效果最好且微吃CPU/GPU"
1286
- ),
1287
- choices=["pm", "harvest", "dio", "rmvpe", "rmvpe_gpu"],
1288
- value="rmvpe_gpu",
1289
- interactive=True,
1290
- )
1291
- gpus_rmvpe = gr.Textbox(
1292
- label=i18n(
1293
- "rmvpe卡号配置:以-分隔输入使用的不同进程卡号,例如0-0-1使用在卡0上跑2个进程并在卡1上跑1个进程"
1294
- ),
1295
- value="%s-%s" % (gpus, gpus),
1296
- interactive=True,
1297
- visible=F0GPUVisible,
1298
- )
1299
- but2 = gr.Button(i18n("特征提取"), variant="primary")
1300
- info2 = gr.Textbox(label=i18n("输出信息"), value="", max_lines=8)
1301
- f0method8.change(
1302
- fn=change_f0_method,
1303
- inputs=[f0method8],
1304
- outputs=[gpus_rmvpe],
1305
- )
1306
- but2.click(
1307
- extract_f0_feature,
1308
- [
1309
- gpus6,
1310
- np7,
1311
- f0method8,
1312
- if_f0_3,
1313
- exp_dir1,
1314
- version19,
1315
- gpus_rmvpe,
1316
- ],
1317
- [info2],
1318
- api_name="train_extract_f0_feature",
1319
- )
1320
- with gr.Column():
1321
- total_epoch11 = gr.Slider(
1322
- minimum=2,
1323
- maximum=1000,
1324
- step=1,
1325
- label=i18n("总训练轮数total_epoch"),
1326
- value=150,
1327
- interactive=True,
1328
- )
1329
- gpus16 = gr.Textbox(
1330
- label=i18n("以-分隔输入使用的卡号, 例如 0-1-2 使用卡0和卡1和卡2"),
1331
- value="0",
1332
- interactive=True,
1333
- visible=True
1334
- )
1335
- but3 = gr.Button(i18n("训练模型"), variant="primary")
1336
- but4 = gr.Button(i18n("训练特征索引"), variant="primary")
1337
- info3 = gr.Textbox(label=i18n("输出信息"), value="", max_lines=10)
1338
- with gr.Accordion(label=i18n("常规设置"), open=False):
1339
- save_epoch10 = gr.Slider(
1340
- minimum=1,
1341
- maximum=50,
1342
- step=1,
1343
- label=i18n("保存频率save_every_epoch"),
1344
- value=25,
1345
- interactive=True,
1346
- )
1347
- batch_size12 = gr.Slider(
1348
- minimum=1,
1349
- maximum=40,
1350
- step=1,
1351
- label=i18n("每张显卡的batch_size"),
1352
- value=default_batch_size,
1353
- interactive=True,
1354
- )
1355
- if_save_latest13 = gr.Radio(
1356
- label=i18n("是否仅保存最新的ckpt文件以节省硬盘空间"),
1357
- choices=[i18n("是"), i18n("否")],
1358
- value=i18n("是"),
1359
- interactive=True,
1360
- visible=False
1361
- )
1362
- if_cache_gpu17 = gr.Radio(
1363
- label=i18n(
1364
- "是否缓存所有训练集至显存. 10min以下小数据可缓存以加速训练, 大数据缓存会炸显存也加不了多少速"
1365
- ),
1366
- choices=[i18n("是"), i18n("否")],
1367
- value=i18n("否"),
1368
- interactive=True,
1369
- )
1370
- if_save_every_weights18 = gr.Radio(
1371
- label=i18n("是否在每次保存时间点将最终小模型保存至weights文件夹"),
1372
- choices=[i18n("是"), i18n("否")],
1373
- value=i18n("是"),
1374
- interactive=True,
1375
- )
1376
- display_advanced_settings = gr.Checkbox(
1377
- value=False,
1378
- label="Advanced Settings"
1379
- )
1380
- pretrained_G14 = gr.Dropdown(
1381
- label=i18n("加载预训练底模G路径"),
1382
- value="assets/pretrained_v2/f0G40k.pth",
1383
- choices=get_pretrains('G'),
1384
- interactive=True,
1385
- visible=False
1386
- )
1387
- pretrained_D15 = gr.Dropdown(
1388
- label=i18n("加载预训练底模D路径"),
1389
- value="assets/pretrained_v2/f0D40k.pth",
1390
- interactive=True,
1391
- choices=get_pretrains('D'),
1392
- visible=False
1393
- )
1394
- display_advanced_settings.change(fn=update_visibility,inputs=[display_advanced_settings],outputs=[pretrained_G14,pretrained_D15])
1395
- with gr.Row():
1396
- download_model = gr.Button('5.Download Model')
1397
- with gr.Row():
1398
- model_files = gr.Files(label='Your Model and Index file can be downloaded here:')
1399
- download_model.click(fn=download_model_files, inputs=[exp_dir1], outputs=[model_files, info3])
1400
- with gr.Row():
1401
- sr2.change(
1402
- change_sr2,
1403
- [sr2, if_f0_3, version19],
1404
- [pretrained_G14, pretrained_D15],
1405
- )
1406
- version19.change(
1407
- change_version19,
1408
- [sr2, if_f0_3, version19],
1409
- [pretrained_G14, pretrained_D15, sr2],
1410
- )
1411
- if_f0_3.change(
1412
- change_f0,
1413
- [if_f0_3, sr2, version19],
1414
- [f0method8, pretrained_G14, pretrained_D15],
1415
- )
1416
- with gr.Row():
1417
- but5 = gr.Button(i18n("一键训练"), variant="primary", visible=False)
1418
- but3.click(
1419
- click_train,
1420
- [
1421
- exp_dir1,
1422
- sr2,
1423
- if_f0_3,
1424
- spk_id5,
1425
- save_epoch10,
1426
- total_epoch11,
1427
- batch_size12,
1428
- if_save_latest13,
1429
- pretrained_G14,
1430
- pretrained_D15,
1431
- gpus16,
1432
- if_cache_gpu17,
1433
- if_save_every_weights18,
1434
- version19,
1435
- ],
1436
- info3,
1437
- api_name="train_start",
1438
- )
1439
- but4.click(train_index, [exp_dir1, version19], info3)
1440
- but5.click(
1441
- train1key,
1442
- [
1443
- exp_dir1,
1444
- sr2,
1445
- if_f0_3,
1446
- trainset_dir4,
1447
- spk_id5,
1448
- np7,
1449
- f0method8,
1450
- save_epoch10,
1451
- total_epoch11,
1452
- batch_size12,
1453
- if_save_latest13,
1454
- pretrained_G14,
1455
- pretrained_D15,
1456
- gpus16,
1457
- if_cache_gpu17,
1458
- if_save_every_weights18,
1459
- version19,
1460
- gpus_rmvpe,
1461
- ],
1462
- info3,
1463
- api_name="train_start_all",
1464
- )
1465
-
1466
- if config.iscolab:
1467
- app.queue().launch(share=True,debug=True)
1468
- else:
1469
- app.queue().launch(
1470
- server_name="0.0.0.0",
1471
- inbrowser=not config.noautoopen,
1472
- server_port=config.listen_port,
1473
- quiet=True,
1474
- )