feat: model embed author

This commit is contained in:
源文雨 2024-06-03 17:07:13 +09:00
parent ccecac6133
commit 07c66d3676
4 changed files with 309 additions and 291 deletions

View File

@ -480,6 +480,7 @@ def click_train(
if_cache_gpu17,
if_save_every_weights18,
version19,
author,
):
# 生成filelist
exp_dir = "%s/logs/%s" % (now_dir, exp_dir1)
@ -548,8 +549,6 @@ def click_train(
with open("%s/filelist.txt" % exp_dir, "w") as f:
f.write("\n".join(opt))
logger.debug("Write filelist done")
# 生成config#无需生成config
# 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"
logger.info("Use gpus: %s", str(gpus16))
if pretrained_G14 == "":
logger.info("No pretrained Generator")
@ -570,45 +569,25 @@ def click_train(
sort_keys=True,
)
f.write("\n")
cmd = '"%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 -a "%s"' % (
config.python_cmd,
exp_dir1,
sr2,
1 if if_f0_3 else 0,
batch_size12,
total_epoch11,
save_epoch10,
'-pg "%s"' % pretrained_G14 if pretrained_G14 != "" else "",
'-pd "%s"' % pretrained_D15 if pretrained_D15 != "" else "",
1 if if_save_latest13 == i18n("") else 0,
1 if if_cache_gpu17 == i18n("") else 0,
1 if if_save_every_weights18 == i18n("") else 0,
version19,
author
)
if gpus16:
cmd = (
'"%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'
% (
config.python_cmd,
exp_dir1,
sr2,
1 if if_f0_3 else 0,
batch_size12,
gpus16,
total_epoch11,
save_epoch10,
"-pg %s" % pretrained_G14 if pretrained_G14 != "" else "",
"-pd %s" % pretrained_D15 if pretrained_D15 != "" else "",
1 if if_save_latest13 == i18n("") else 0,
1 if if_cache_gpu17 == i18n("") else 0,
1 if if_save_every_weights18 == i18n("") else 0,
version19,
)
)
else:
cmd = (
'"%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'
% (
config.python_cmd,
exp_dir1,
sr2,
1 if if_f0_3 else 0,
batch_size12,
total_epoch11,
save_epoch10,
"-pg %s" % pretrained_G14 if pretrained_G14 != "" else "",
"-pd %s" % pretrained_D15 if pretrained_D15 != "" else "",
1 if if_save_latest13 == i18n("") else 0,
1 if if_cache_gpu17 == i18n("") else 0,
1 if if_save_every_weights18 == i18n("") else 0,
version19,
)
)
cmd += '-g "%s"' % (gpus16)
logger.info("Execute: " + cmd)
p = Popen(cmd, shell=True, cwd=now_dir)
p.wait()
@ -734,6 +713,7 @@ def train1key(
if_save_every_weights18,
version19,
gpus_rmvpe,
author
):
infos = []
@ -771,6 +751,7 @@ def train1key(
if_cache_gpu17,
if_save_every_weights18,
version19,
author
)
yield get_info_str(
i18n("训练结束, 您可查看控制台训练日志或实验文件夹下的train.log")
@ -837,7 +818,7 @@ with gr.Blocks(title="RVC WebUI") as app:
clean_button.click(
fn=clean, inputs=[], outputs=[sid0], api_name="infer_clean"
)
modelinfo = gr.Textbox(label=i18n("模型信息"))
modelinfo = gr.Textbox(label=i18n("模型信息"), max_lines=8)
with gr.TabItem(i18n("单次推理")):
with gr.Group():
with gr.Row():
@ -1066,7 +1047,6 @@ with gr.Blocks(title="RVC WebUI") as app:
interactive=True,
)
but1 = gr.Button(i18n("转换"), variant="primary")
vc_output3 = gr.Textbox(label=i18n("输出信息"))
but1.click(
@ -1165,11 +1145,21 @@ with gr.Blocks(title="RVC WebUI") as app:
with gr.TabItem(i18n("训练")):
gr.Markdown(
value=i18n(
"step1: 填写实验配置. 实验数据放在logs下, 每个实验一个文件夹, 需手工输入实验名路径, 内含实验配置, 日志, 训练得到的模型文件. "
"### 第一步 填写实验配置\n实验数据放在logs下, 每个实验一个文件夹, 需手工输入实验名路径, 内含实验配置, 日志, 训练得到的模型文件."
)
)
with gr.Row():
exp_dir1 = gr.Textbox(label=i18n("输入实验名"), value="mi-test")
author = gr.Textbox(label=i18n("模型作者(可空)"))
np7 = gr.Slider(
minimum=0,
maximum=config.n_cpu,
step=1,
label=i18n("提取音高和处理数据使用的CPU进程数"),
value=int(np.ceil(config.n_cpu / 1.5)),
interactive=True,
)
with gr.Row():
sr2 = gr.Radio(
label=i18n("目标采样率"),
choices=["40k", "48k"],
@ -1189,21 +1179,14 @@ with gr.Blocks(title="RVC WebUI") as app:
interactive=True,
visible=True,
)
np7 = gr.Slider(
minimum=0,
maximum=config.n_cpu,
step=1,
label=i18n("提取音高和处理数据使用的CPU进程数"),
value=int(np.ceil(config.n_cpu / 1.5)),
interactive=True,
)
with gr.Group(): # 暂时单人的, 后面支持最多4人的#数据处理
gr.Markdown(
value=i18n(
"step2a: 自动遍历训练文件夹下所有可解码成音频的文件并进行切片归一化, 在实验目录下生成2个wav文件夹; 暂时只支持单人训练. "
"### 第二步 音频处理\n#### 1. 音频切片\n自动遍历训练文件夹下所有可解码成音频的文件并进行切片归一化, 在实验目录下生成2个wav文件夹; 暂时只支持单人训练."
)
)
with gr.Row():
with gr.Column():
trainset_dir4 = gr.Textbox(
label=i18n("输入训练文件夹路径"),
value=i18n("E:\\语音音频+标注\\米津玄师\\src"),
@ -1217,6 +1200,7 @@ with gr.Blocks(title="RVC WebUI") as app:
interactive=True,
)
but1 = gr.Button(i18n("处理数据"), variant="primary")
with gr.Column():
info1 = gr.Textbox(label=i18n("输出信息"), value="")
but1.click(
preprocess_dataset,
@ -1227,11 +1211,14 @@ with gr.Blocks(title="RVC WebUI") as app:
with gr.Group():
gr.Markdown(
value=i18n(
"step2b: 使用CPU提取音高(如果模型带音高), 使用GPU提取特征(选择卡号)"
"#### 2. 特征提取\n使用CPU提取音高(如果模型带音高), 使用GPU提取特征(选择卡号)."
)
)
with gr.Row():
with gr.Column():
gpu_info9 = gr.Textbox(
label=i18n("显卡信息"), value=gpu_info, visible=F0GPUVisible
)
gpus6 = gr.Textbox(
label=i18n(
"以-分隔输入使用的卡号, 例如 0-1-2 使用卡0和卡1和卡2"
@ -1240,18 +1227,6 @@ with gr.Blocks(title="RVC WebUI") as app:
interactive=True,
visible=F0GPUVisible,
)
gpu_info9 = gr.Textbox(
label=i18n("显卡信息"), value=gpu_info, visible=F0GPUVisible
)
with gr.Column():
f0method8 = gr.Radio(
label=i18n(
"选择音高提取算法:输入歌声可用pm提速,高质量语音但CPU差可用dio提速,harvest质量更好但慢,rmvpe效果最好且微吃CPU/GPU"
),
choices=["pm", "harvest", "dio", "rmvpe", "rmvpe_gpu"],
value="rmvpe_gpu",
interactive=True,
)
gpus_rmvpe = gr.Textbox(
label=i18n(
"rmvpe卡号配置以-分隔输入使用的不同进程卡号,例如0-0-1使用在卡0上跑2个进程并在卡1上跑1个进程"
@ -1260,6 +1235,15 @@ with gr.Blocks(title="RVC WebUI") as app:
interactive=True,
visible=F0GPUVisible,
)
f0method8 = gr.Radio(
label=i18n(
"选择音高提取算法:输入歌声可用pm提速,高质量语音但CPU差可用dio提速,harvest质量更好但慢,rmvpe效果最好且微吃CPU/GPU"
),
choices=["pm", "harvest", "dio", "rmvpe", "rmvpe_gpu"],
value="rmvpe_gpu",
interactive=True,
)
with gr.Column():
but2 = gr.Button(i18n("特征提取"), variant="primary")
info2 = gr.Textbox(label=i18n("输出信息"), value="", max_lines=8)
f0method8.change(
@ -1282,8 +1266,9 @@ with gr.Blocks(title="RVC WebUI") as app:
api_name="train_extract_f0_feature",
)
with gr.Group():
gr.Markdown(value=i18n("step3: 填写训练设置, 开始训练模型和索引"))
gr.Markdown(value=i18n("### 第三步 开始训练\n填写训练设置, 开始训练模型和索引."))
with gr.Row():
with gr.Column():
save_epoch10 = gr.Slider(
minimum=1,
maximum=50,
@ -1330,7 +1315,7 @@ with gr.Blocks(title="RVC WebUI") as app:
value=i18n(""),
interactive=True,
)
with gr.Row():
with gr.Column():
pretrained_G14 = gr.Textbox(
label=i18n("加载预训练底模G路径"),
value="assets/pretrained_v2/f0G40k.pth",
@ -1341,6 +1326,13 @@ with gr.Blocks(title="RVC WebUI") as app:
value="assets/pretrained_v2/f0D40k.pth",
interactive=True,
)
gpus16 = gr.Textbox(
label=i18n(
"以-分隔输入使用的卡号, 例如 0-1-2 使用卡0和卡1和卡2"
),
value=gpus,
interactive=True,
)
sr2.change(
change_sr2,
[sr2, if_f0_3, version19],
@ -1356,16 +1348,11 @@ with gr.Blocks(title="RVC WebUI") as app:
[if_f0_3, sr2, version19],
[f0method8, gpus_rmvpe, pretrained_G14, pretrained_D15],
)
gpus16 = gr.Textbox(
label=i18n(
"以-分隔输入使用的卡号, 例如 0-1-2 使用卡0和卡1和卡2"
),
value=gpus,
interactive=True,
)
but3 = gr.Button(i18n("训练模型"), variant="primary")
but4 = gr.Button(i18n("训练特征索引"), variant="primary")
but5 = gr.Button(i18n("一键训练"), variant="primary")
with gr.Row():
info3 = gr.Textbox(label=i18n("输出信息"), value="", max_lines=10)
but3.click(
click_train,
@ -1384,6 +1371,7 @@ with gr.Blocks(title="RVC WebUI") as app:
if_cache_gpu17,
if_save_every_weights18,
version19,
author,
],
info3,
api_name="train_start",
@ -1410,6 +1398,7 @@ with gr.Blocks(title="RVC WebUI") as app:
if_save_every_weights18,
version19,
gpus_rmvpe,
author,
],
info3,
api_name="train_start_all",
@ -1443,6 +1432,7 @@ with gr.Blocks(title="RVC WebUI") as app:
with gr.Group():
gr.Markdown(value=i18n("### 模型融合\n可用于测试音色融合"))
with gr.Row():
with gr.Column():
ckpt_a = gr.Textbox(
label=i18n("A模型路径"), value="", interactive=True
)
@ -1456,7 +1446,7 @@ with gr.Blocks(title="RVC WebUI") as app:
value=0.5,
interactive=True,
)
with gr.Row():
with gr.Column():
sr_ = gr.Radio(
label=i18n("目标采样率"),
choices=["40k", "48k"],
@ -1475,6 +1465,7 @@ with gr.Blocks(title="RVC WebUI") as app:
max_lines=8,
interactive=True,
)
with gr.Column():
name_to_save0 = gr.Textbox(
label=i18n("保存的模型名不带后缀"),
value="",
@ -1487,8 +1478,8 @@ with gr.Blocks(title="RVC WebUI") as app:
value="v1",
interactive=True,
)
with gr.Row():
but6 = gr.Button(i18n("融合"), variant="primary")
with gr.Row():
info4 = gr.Textbox(label=i18n("输出信息"), value="", max_lines=8)
but6.click(
merge,
@ -1512,6 +1503,7 @@ with gr.Blocks(title="RVC WebUI") as app:
)
)
with gr.Row():
with gr.Column():
ckpt_path0 = gr.Textbox(
label=i18n("模型路径"), value="", interactive=True
)
@ -1527,7 +1519,7 @@ with gr.Blocks(title="RVC WebUI") as app:
max_lines=8,
interactive=True,
)
with gr.Row():
with gr.Column():
but7 = gr.Button(i18n("修改"), variant="primary")
info5 = gr.Textbox(label=i18n("输出信息"), value="", max_lines=8)
but7.click(
@ -1543,10 +1535,12 @@ with gr.Blocks(title="RVC WebUI") as app:
)
)
with gr.Row():
with gr.Column():
ckpt_path1 = gr.Textbox(
label=i18n("模型路径"), value="", interactive=True
)
but8 = gr.Button(i18n("查看"), variant="primary")
with gr.Column():
info6 = gr.Textbox(label=i18n("输出信息"), value="", max_lines=8)
but8.click(show_info, [ckpt_path1], info6, api_name="ckpt_show")
with gr.Group():
@ -1556,6 +1550,7 @@ with gr.Blocks(title="RVC WebUI") as app:
)
)
with gr.Row():
with gr.Column():
ckpt_path2 = gr.Textbox(
label=i18n("模型路径"),
value="E:\\codes\\py39\\logs\\mi-test_f0_48k\\G_23333.pth",
@ -1564,6 +1559,7 @@ with gr.Blocks(title="RVC WebUI") as app:
save_name = gr.Textbox(
label=i18n("保存名"), value="", interactive=True
)
with gr.Row():
sr__ = gr.Radio(
label=i18n("目标采样率"),
choices=["32k", "40k", "48k"],
@ -1588,6 +1584,13 @@ with gr.Blocks(title="RVC WebUI") as app:
max_lines=8,
interactive=True,
)
extauthor = gr.Textbox(
label=i18n("模型作者"),
value="",
max_lines=1,
interactive=True,
)
with gr.Column():
but9 = gr.Button(i18n("提取"), variant="primary")
info7 = gr.Textbox(label=i18n("输出信息"), value="", max_lines=8)
ckpt_path2.change(
@ -1595,7 +1598,7 @@ with gr.Blocks(title="RVC WebUI") as app:
)
but9.click(
extract_small_model,
[ckpt_path2, save_name, sr__, if_f0__, info___, version_1],
[ckpt_path2, save_name, extauthor, sr__, if_f0__, info___, version_1],
info7,
api_name="ckpt_extract",
)

View File

@ -43,6 +43,7 @@ def save_small_model(ckpt, sr, if_f0, name, epoch, version, hps):
opt["info"] = "%sepoch" % epoch
opt["name"] = name
opt["timestamp"] = int(time())
if hps.author: opt["author"] = hps.author
opt["sr"] = sr
opt["f0"] = if_f0
opt["version"] = version
@ -55,7 +56,7 @@ def save_small_model(ckpt, sr, if_f0, name, epoch, version, hps):
return traceback.format_exc()
def extract_small_model(path, name, sr, if_f0, info, version):
def extract_small_model(path, name, author, sr, if_f0, info, version):
try:
ckpt = torch.load(path, map_location="cpu")
if "model" in ckpt:
@ -178,6 +179,7 @@ def extract_small_model(path, name, sr, if_f0, info, version):
opt["info"] = info
opt["name"] = name
opt["timestamp"] = int(time())
if author: opt["author"] = author
opt["version"] = version
opt["sr"] = sr
opt["f0"] = int(if_f0)
@ -215,6 +217,13 @@ def merge(path1, path2, alpha1, sr, f0, info, name, version):
opt["weight"][key] = a[key]
return opt
def authors(c1, c2):
a1, a2 = c1.get("author", ""), c2.get("author", "")
if a1 == a2: return a1
if not a1: a1 = "Unknown"
if not a2: a2 = "Unknown"
return f"{a1} & {a2}"
ckpt1 = torch.load(path1, map_location="cpu")
ckpt2 = torch.load(path2, map_location="cpu")
cfg = ckpt1["config"]
@ -242,8 +251,7 @@ def merge(path1, path2, alpha1, sr, f0, info, name, version):
opt["weight"][key] = (
alpha1 * (ckpt1[key].float()) + (1 - alpha1) * (ckpt2[key].float())
).half()
# except:
# pdb.set_trace()
author = authors(ckpt1, ckpt2)
opt["config"] = cfg
"""
if(sr=="40k"):opt["config"] = [1025, 32, 192, 192, 768, 2, 6, 3, 0, "1", [3, 7, 11], [[1, 3, 5], [1, 3, 5], [1, 3, 5]], [10, 10, 2, 2], 512, [16, 16, 4, 4,4], 109, 256, 40000]
@ -252,6 +260,7 @@ def merge(path1, path2, alpha1, sr, f0, info, name, version):
"""
opt["name"] = name
opt["timestamp"] = int(time())
if author: opt["author"] = author
opt["sr"] = sr
opt["f0"] = 1 if f0 == i18n("") else 0
opt["version"] = version

View File

@ -358,6 +358,9 @@ def get_hparams(init=True):
required=True,
help="if caching the dataset in GPU memory, 1 or 0",
)
parser.add_argument(
"-a", "--author", type=str, default="", help="Model author"
)
args = parser.parse_args()
name = args.experiment_dir
@ -383,9 +386,10 @@ def get_hparams(init=True):
hparams.save_every_weights = args.save_every_weights
hparams.if_cache_data_in_gpu = args.if_cache_data_in_gpu
hparams.data.training_files = "%s/filelist.txt" % experiment_dir
hparams.author = args.author
return hparams
"""
def get_hparams_from_dir(model_dir):
config_save_path = os.path.join(model_dir, "config.json")
with open(config_save_path, "r") as f:
@ -429,7 +433,7 @@ def check_git_hash(model_dir):
)
else:
open(path, "w").write(cur_hash)
"""
def get_logger(model_dir, filename="train.log"):
global logger

View File

@ -38,18 +38,20 @@ def show_model_info(cpt, show_long_id=False):
)
txt = f"""{i18n("模型名")}: %s
{i18n("封装时间")}: %s
{i18n("模型作者")}: %s
{i18n("信息")}: %s
{i18n("采样率")}: %s
{i18n("音高引导(f0)")}: %s
{i18n("版本")}: %s
{i18n("ID(短)")}: %s
{i18n("ID(长)")}: %s""" % (
cpt.get("name", "None"),
cpt.get("name", i18n("Unknown")),
datetime.fromtimestamp(float(cpt.get("timestamp", 0))),
cpt.get("info", "None"),
cpt.get("sr", "None"),
cpt.get("author", i18n("Unknown")),
cpt.get("info", i18n("None")),
cpt.get("sr", i18n("Unknown")),
i18n("") if cpt.get("f0", 0) == 1 else i18n(""),
cpt.get("version", "None"),
cpt.get("version", i18n("None")),
id,
h,
)