mirror of
https://github.com/w-okada/voice-changer.git
synced 2025-01-24 22:15:02 +03:00
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
import torch
|
|
from const import EnumInferenceTypes
|
|
|
|
from voice_changer.RVC.deviceManager.DeviceManager import DeviceManager
|
|
from voice_changer.RVC.inferencer.Inferencer import Inferencer
|
|
from infer_pack.models import ( # type:ignore
|
|
SynthesizerTrnMs768NSFsid_nono,
|
|
)
|
|
|
|
|
|
class RVCInferencerv2Nono(Inferencer):
|
|
def loadModel(self, file: str, gpu: int):
|
|
self.setProps(EnumInferenceTypes.pyTorchRVCv2Nono, file, True, gpu)
|
|
|
|
dev = DeviceManager.get_instance().getDevice(gpu)
|
|
isHalf = DeviceManager.get_instance().halfPrecisionAvailable(gpu)
|
|
|
|
cpt = torch.load(file, map_location="cpu")
|
|
model = SynthesizerTrnMs768NSFsid_nono(*cpt["config"], is_half=isHalf)
|
|
|
|
model.eval()
|
|
model.load_state_dict(cpt["weight"], strict=False)
|
|
|
|
model = model.to(dev)
|
|
if isHalf:
|
|
model = model.half()
|
|
|
|
self.model = model
|
|
return self
|
|
|
|
def infer(
|
|
self,
|
|
feats: torch.Tensor,
|
|
pitch_length: torch.Tensor,
|
|
pitch: torch.Tensor | None,
|
|
pitchf: torch.Tensor | None,
|
|
sid: torch.Tensor,
|
|
) -> torch.Tensor:
|
|
return self.model.infer(feats, pitch_length, sid)
|