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

41 lines
1.2 KiB
Python
Raw Normal View History

import torch
from torch import device
from const import EnumInferenceTypes
from voice_changer.RVC.inferencer.Inferencer import Inferencer
from voice_changer.RVC.deviceManager.DeviceManager import DeviceManager
2023-06-24 04:33:57 +03:00
from .voras_beta.models import Synthesizer
2023-06-24 04:33:57 +03:00
class VoRASInferencer(Inferencer):
def loadModel(self, file: str, gpu: device):
2023-06-24 04:33:57 +03:00
super().setProps(EnumInferenceTypes.pyTorchVoRASbeta, file, False, gpu)
dev = DeviceManager.get_instance().getDevice(gpu)
2023-07-23 01:20:48 +03:00
self.isHalf = False # DeviceManager.get_instance().halfPrecisionAvailable(gpu)
cpt = torch.load(file, map_location="cpu")
2023-06-24 04:33:57 +03:00
model = Synthesizer(**cpt["params"])
model.eval()
model.load_state_dict(cpt["weight"], strict=False)
2023-06-24 04:33:57 +03:00
model.remove_weight_norm()
model.change_speaker(0)
model = model.to(dev)
self.model = model
print("load model comprete")
return self
def infer(
self,
feats: torch.Tensor,
pitch_length: torch.Tensor,
pitch: torch.Tensor,
pitchf: torch.Tensor,
sid: torch.Tensor,
2023-07-01 10:45:25 +03:00
convert_length: int | None,
) -> torch.Tensor:
return self.model.infer(feats, pitch_length, pitch, pitchf, sid)