Gorgefound commited on
Commit
520744e
·
verified ·
1 Parent(s): 7f98349

Delete app.py

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