mirror of
https://github.com/w-okada/voice-changer.git
synced 2025-03-15 04:13:57 +03:00
36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
![]() |
import torch
|
||
|
|
||
|
from voice_changer.RVC.deviceManager.DeviceManager import DeviceManager
|
||
|
|
||
|
|
||
|
class RVCInferencer(Inferencer):
|
||
|
def loadModel(self, file: str, gpu: int):
|
||
|
self.setProps("DiffusionSVCCombo", file, True, gpu)
|
||
|
|
||
|
dev = DeviceManager.get_instance().getDevice(gpu)
|
||
|
isHalf = DeviceManager.get_instance().halfPrecisionAvailable(gpu)
|
||
|
|
||
|
cpt = torch.load(file, map_location="cpu")
|
||
|
model = SynthesizerTrnMs256NSFsid(*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,
|
||
|
pitchf: torch.Tensor,
|
||
|
sid: torch.Tensor,
|
||
|
convert_length: int | None,
|
||
|
) -> torch.Tensor:
|
||
|
return self.model.infer(feats, pitch_length, pitch, pitchf, sid, convert_length=convert_length)
|