Add files via upload

This commit is contained in:
RVC-Boss
2023-08-13 01:05:58 +08:00
committed by GitHub
parent 7f78dce483
commit 03e7c68c11
11 changed files with 478 additions and 270 deletions

View File

@@ -1,12 +1,12 @@
import os, sys
import faiss, torch, traceback, parselmouth, numpy as np, torchcrepe, torch.nn as nn, pyworld
from fairseq import checkpoint_utils
import fairseq
from lib.infer_pack.models import (
SynthesizerTrnMs256NSFsid,
SynthesizerTrnMs256NSFsid_nono,
SynthesizerTrnMs768NSFsid,
SynthesizerTrnMs768NSFsid_nono,
)
import os, sys
from time import time as ttime
import torch.nn.functional as F
import scipy.signal as signal
@@ -18,8 +18,14 @@ from multiprocessing import Manager as M
mm = M()
config = Config()
if(config.dml==True):
def forward_dml(ctx, x, scale):
ctx.scale = scale
res = x.clone().detach()
return res
fairseq.modules.grad_multiply.GradMultiply.forward=forward_dml
# config.device=torch.device("cpu")########强制cpu测试
# config.is_half=False########强制cpu测试
class RVC:
def __init__(
self, key, pth_path, index_path, index_rate, n_cpu, inp_q, opt_q, device
@@ -31,6 +37,7 @@ class RVC:
global config
self.inp_q = inp_q
self.opt_q = opt_q
# device="cpu"########强制cpu测试
self.device = device
self.f0_up_key = key
self.time_step = 160 / 16000 * 1000
@@ -46,7 +53,7 @@ class RVC:
self.big_npy = self.index.reconstruct_n(0, self.index.ntotal)
print("index search enabled")
self.index_rate = index_rate
models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
models, _, _ = fairseq.checkpoint_utils.load_model_ensemble_and_task(
["hubert_base.pt"],
suffix="",
)
@@ -80,6 +87,7 @@ class RVC:
del self.net_g.enc_q
print(self.net_g.load_state_dict(cpt["weight"], strict=False))
self.net_g.eval().to(device)
# print(2333333333,device,config.device,self.device)#net_g是devicehubert是config.device
if config.is_half:
self.net_g = self.net_g.half()
else:
@@ -124,7 +132,7 @@ class RVC:
pad_size = (p_len - len(f0) + 1) // 2
if pad_size > 0 or p_len - len(f0) - pad_size > 0:
print(pad_size, p_len - len(f0) - pad_size)
# print(pad_size, p_len - len(f0) - pad_size)
f0 = np.pad(
f0, [[pad_size, p_len - len(f0) - pad_size]], mode="constant"
)
@@ -175,7 +183,10 @@ class RVC:
return self.get_f0_post(f0bak)
def get_f0_crepe(self, x, f0_up_key):
if self.device.type == "privateuseone":###不支持dmlcpu又太慢用不成拿pm顶替
return self.get_f0(x, f0_up_key,1,"pm")
audio = torch.tensor(np.copy(x))[None].float()
# print("using crepe,device:%s"%self.device)
f0, pd = torchcrepe.predict(
audio,
self.sr,
@@ -184,6 +195,7 @@ class RVC:
self.f0_max,
"full",
batch_size=512,
# device=self.device if self.device.type!="privateuseone" else "cpu",###crepe不用半精度全部是全精度所以不愁###cpu延迟高到没法用
device=self.device,
return_periodicity=True,
)
@@ -197,10 +209,12 @@ class RVC:
def get_f0_rmvpe(self, x, f0_up_key):
if hasattr(self, "model_rmvpe") == False:
from lib.rmvpe import RMVPE
print("loading rmvpe model")
self.model_rmvpe = RMVPE(
"rmvpe.pt", is_half=self.is_half, device=self.device
# "rmvpe.pt", is_half=self.is_half if self.device.type!="privateuseone" else False, device=self.device if self.device.type!="privateuseone"else "cpu"####dml时强制对rmvpe用cpu跑
# "rmvpe.pt", is_half=False, device=self.device####dml配置
# "rmvpe.pt", is_half=False, device="cpu"####锁定cpu配置
"rmvpe.pt", is_half=self.is_half, device=self.device####正常逻辑
)
# self.model_rmvpe = RMVPE("aug2_58000_half.pt", is_half=self.is_half, device=self.device)
f0 = self.model_rmvpe.infer_from_audio(x, thred=0.03)
@@ -279,6 +293,7 @@ class RVC:
sid = torch.LongTensor([ii]).to(self.device)
with torch.no_grad():
if self.if_f0 == 1:
# print(12222222222,feats.device,p_len.device,cache_pitch.device,cache_pitchf.device,sid.device,rate2)
infered_audio = (
self.net_g.infer(
feats, p_len, cache_pitch, cache_pitchf, sid, rate2