WIP: refactoring

This commit is contained in:
wataru 2023-04-28 10:56:52 +09:00
parent 234595eeeb
commit bd3667117e

View File

@ -90,109 +90,6 @@ class VC(object):
f0_coarse = np.rint(f0_mel).astype(np.int)
return f0_coarse, f0bak # 1-0
# def vc(
# self,
# model,
# net_g,
# sid,
# audio0,
# pitch,
# pitchf,
# index,
# big_npy,
# index_rate,
# embChannels=256,
# ): # ,file_index,file_big_npy
# feats = torch.from_numpy(audio0)
# if self.is_half is True:
# feats = feats.half()
# else:
# feats = feats.float()
# if feats.dim() == 2: # double channels
# feats = feats.mean(-1)
# assert feats.dim() == 1, feats.dim()
# feats = feats.view(1, -1)
# padding_mask = torch.BoolTensor(feats.shape).to(self.device).fill_(False)
# if embChannels == 256:
# inputs = {
# "source": feats.to(self.device),
# "padding_mask": padding_mask,
# "output_layer": 9, # layer 9
# }
# else:
# inputs = {
# "source": feats.to(self.device),
# "padding_mask": padding_mask,
# }
# with torch.no_grad():
# logits = model.extract_features(**inputs)
# if embChannels == 256:
# feats = model.final_proj(logits[0])
# else:
# feats = logits[0]
# if (
# isinstance(index, type(None)) is False
# and isinstance(big_npy, type(None)) is False
# and index_rate != 0
# ):
# npy = feats[0].cpu().numpy()
# if self.is_half is True:
# npy = npy.astype("float32")
# D, I = index.search(npy, 1)
# npy = big_npy[I.squeeze()]
# if self.is_half is True:
# npy = npy.astype("float16")
# feats = (
# torch.from_numpy(npy).unsqueeze(0).to(self.device) * index_rate
# + (1 - index_rate) * feats
# )
# feats = F.interpolate(feats.permute(0, 2, 1), scale_factor=2).permute(0, 2, 1)
# p_len = audio0.shape[0] // self.window
# if feats.shape[1] < p_len:
# p_len = feats.shape[1]
# if pitch is not None and pitchf is not None:
# pitch = pitch[:, :p_len]
# pitchf = pitchf[:, :p_len]
# p_len = torch.tensor([p_len], device=self.device).long()
# with torch.no_grad():
# if pitch is not None:
# audio1 = (
# (net_g.infer(feats, p_len, pitch, pitchf, sid)[0][0, 0] * 32768)
# .data.cpu()
# .float()
# .numpy()
# .astype(np.int16)
# )
# else:
# if hasattr(net_g, "infer_pitchless"):
# audio1 = (
# (net_g.infer_pitchless(feats, p_len, sid)[0][0, 0] * 32768)
# .data.cpu()
# .float()
# .numpy()
# .astype(np.int16)
# )
# else:
# audio1 = (
# (net_g.infer(feats, p_len, sid)[0][0, 0] * 32768)
# .data.cpu()
# .float()
# .numpy()
# .astype(np.int16)
# )
# del feats, p_len, padding_mask
# torch.cuda.empty_cache()
# return audio1
def pipeline(
self,
embedder,
@ -331,24 +228,3 @@ class VC(object):
del pitch, pitchf, sid
torch.cuda.empty_cache()
return audio1
# output = self.vc(
# embedder,
# model,
# sid,
# audio_pad,
# pitch,
# pitchf,
# index,
# big_npy,
# index_rate,
# embChannels,
# )
# if self.t_pad_tgt != 0:
# offset = self.t_pad_tgt
# end = -1 * self.t_pad_tgt
# output = output[offset:end]
# del pitch, pitchf, sid
# torch.cuda.empty_cache()
# return output