voice-changer/server/voice_changer/RVC/inferencer/OnnxRVCInferencerNono.py

42 lines
1.3 KiB
Python
Raw Normal View History

2023-05-02 14:57:12 +03:00
import torch
import numpy as np
2023-05-31 08:30:35 +03:00
from const import EnumInferenceTypes
2023-05-02 14:57:12 +03:00
2023-05-03 07:14:00 +03:00
from voice_changer.RVC.inferencer.OnnxRVCInferencer import OnnxRVCInferencer
2023-05-02 14:57:12 +03:00
2023-05-03 07:14:00 +03:00
class OnnxRVCInferencerNono(OnnxRVCInferencer):
2023-05-31 08:30:35 +03:00
def loadModel(self, file: str, gpu: int):
super().loadModel(file, gpu)
2023-06-04 22:08:03 +03:00
self.setProps(EnumInferenceTypes.onnxRVCNono, file, self.isHalf, gpu)
2023-06-04 11:56:12 +03:00
return self
2023-05-31 08:30:35 +03:00
2023-05-02 14:57:12 +03:00
def infer(
self,
feats: torch.Tensor,
pitch_length: torch.Tensor,
pitch: torch.Tensor | None,
pitchf: torch.Tensor | None,
sid: torch.Tensor,
) -> torch.Tensor:
if self.isHalf:
audio1 = self.model.run(
["audio"],
{
"feats": feats.cpu().numpy().astype(np.float16),
"p_len": pitch_length.cpu().numpy().astype(np.int64),
"sid": sid.cpu().numpy().astype(np.int64),
},
)
else:
audio1 = self.model.run(
["audio"],
{
"feats": feats.cpu().numpy().astype(np.float32),
"p_len": pitch_length.cpu().numpy().astype(np.int64),
"sid": sid.cpu().numpy().astype(np.int64),
},
)
return torch.tensor(np.array(audio1))