chore(format): run black on dev (#1619)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
github-actions[bot] 2023-12-20 14:47:37 +09:00 committed by GitHub
parent d269d14768
commit 0f8a5facd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,22 +46,23 @@ def printt(strr, *args):
# config.is_half=False########强制cpu测试 # config.is_half=False########强制cpu测试
class RVC: class RVC:
def __init__( def __init__(
self, self,
key, key,
pth_path, pth_path,
index_path, index_path,
index_rate, index_rate,
n_cpu, n_cpu,
inp_q, inp_q,
opt_q, opt_q,
config: Config, config: Config,
last_rvc=None, last_rvc=None,
) -> None: ) -> None:
""" """
初始化 初始化
""" """
try: try:
if config.dml == True: if config.dml == True:
def forward_dml(ctx, x, scale): def forward_dml(ctx, x, scale):
ctx.scale = scale ctx.scale = scale
res = x.clone().detach() res = x.clone().detach()
@ -205,7 +206,7 @@ class RVC:
f0bak = f0.copy() f0bak = f0.copy()
f0_mel = 1127 * np.log(1 + f0 / 700) f0_mel = 1127 * np.log(1 + f0 / 700)
f0_mel[f0_mel > 0] = (f0_mel[f0_mel > 0] - f0_mel_min) * 254 / ( f0_mel[f0_mel > 0] = (f0_mel[f0_mel > 0] - f0_mel_min) * 254 / (
f0_mel_max - f0_mel_min f0_mel_max - f0_mel_min
) + 1 ) + 1
f0_mel[f0_mel <= 1] = 1 f0_mel[f0_mel <= 1] = 1
f0_mel[f0_mel > 255] = 255 f0_mel[f0_mel > 255] = 255
@ -261,7 +262,7 @@ class RVC:
self.inp_q.put((idx, x[:tail], res_f0, n_cpu, ts)) self.inp_q.put((idx, x[:tail], res_f0, n_cpu, ts))
else: else:
self.inp_q.put( self.inp_q.put(
(idx, x[part_length * idx - 320: tail], res_f0, n_cpu, ts) (idx, x[part_length * idx - 320 : tail], res_f0, n_cpu, ts)
) )
while 1: while 1:
res_ts = self.opt_q.get() res_ts = self.opt_q.get()
@ -276,7 +277,7 @@ class RVC:
else: else:
f0 = f0[2:] f0 = f0[2:]
f0bak[ f0bak[
part_length * idx // 160: part_length * idx // 160 + f0.shape[0] part_length * idx // 160 : part_length * idx // 160 + f0.shape[0]
] = f0 ] = f0
f0bak = signal.medfilt(f0bak, 3) f0bak = signal.medfilt(f0bak, 3)
f0bak *= pow(2, f0_up_key / 12) f0bak *= pow(2, f0_up_key / 12)
@ -328,26 +329,32 @@ class RVC:
def get_f0_fcpe(self, x, f0_up_key): def get_f0_fcpe(self, x, f0_up_key):
if hasattr(self, "model_fcpe") == False: if hasattr(self, "model_fcpe") == False:
from torchfcpe import spawn_bundled_infer_model from torchfcpe import spawn_bundled_infer_model
printt("Loading fcpe model") printt("Loading fcpe model")
self.model_fcpe = spawn_bundled_infer_model(self.device) self.model_fcpe = spawn_bundled_infer_model(self.device)
f0 = self.model_fcpe.infer( f0 = (
torch.from_numpy(x).to(self.device).unsqueeze(0).float(), self.model_fcpe.infer(
sr=16000, torch.from_numpy(x).to(self.device).unsqueeze(0).float(),
decoder_mode='local_argmax', sr=16000,
threshold=0.006, decoder_mode="local_argmax",
).squeeze().cpu().numpy() threshold=0.006,
)
.squeeze()
.cpu()
.numpy()
)
f0 *= pow(2, f0_up_key / 12) f0 *= pow(2, f0_up_key / 12)
return self.get_f0_post(f0) return self.get_f0_post(f0)
def infer( def infer(
self, self,
feats: torch.Tensor, feats: torch.Tensor,
indata: np.ndarray, indata: np.ndarray,
block_frame_16k, block_frame_16k,
rate, rate,
cache_pitch, cache_pitch,
cache_pitchf, cache_pitchf,
f0method, f0method,
) -> np.ndarray: ) -> np.ndarray:
feats = feats.view(1, -1) feats = feats.view(1, -1)
if self.config.is_half: if self.config.is_half:
@ -380,8 +387,8 @@ class RVC:
if self.config.is_half: if self.config.is_half:
npy = npy.astype("float16") npy = npy.astype("float16")
feats[0][-leng_replace_head:] = ( feats[0][-leng_replace_head:] = (
torch.from_numpy(npy).unsqueeze(0).to(self.device) * self.index_rate torch.from_numpy(npy).unsqueeze(0).to(self.device) * self.index_rate
+ (1 - self.index_rate) * feats[0][-leng_replace_head:] + (1 - self.index_rate) * feats[0][-leng_replace_head:]
) )
else: else:
printt("Index search FAILED or disabled") printt("Index search FAILED or disabled")