improve gui

This commit is contained in:
wataru 2023-04-25 16:15:13 +09:00
parent 87e4ab0cb7
commit cbc454ebf7
5 changed files with 80 additions and 31 deletions

File diff suppressed because one or more lines are too long

View File

@ -14,7 +14,6 @@ export const ModelSwitchRow = (_props: ModelSwitchRowProps) => {
const onSwitchModelClicked = async (index: number, filename: string) => {
const framework: Framework = filename.endsWith(".onnx") ? "ONNX" : "PyTorch"
console.log("Framework:::", filename, framework)
// Quick hack for same slot is selected. 下桁が実際のSlotID
const dummyModelSlotIndex = (Math.floor(Date.now() / 1000)) * 1000 + index
@ -25,13 +24,26 @@ export const ModelSwitchRow = (_props: ModelSwitchRowProps) => {
let filename = ""
if (x.pyTorchModelFile && x.pyTorchModelFile.length > 0) {
filename = x.pyTorchModelFile.replace(/^.*[\\\/]/, '')
return <div key={index} className={className} onClick={() => { onSwitchModelClicked(index, filename) }}>{filename}</div>
} else if (x.onnxModelFile && x.onnxModelFile.length > 0) {
filename = x.onnxModelFile.replace(/^.*[\\\/]/, '')
return <div key={index} className={className} onClick={() => { onSwitchModelClicked(index, filename) }}>{filename}</div>
} else {
return <div key={index} ></div>
}
const f0str = x.f0 == true ? "f0" : "nof0"
const srstr = Math.floor(x.samplingRate / 1000) + "K"
const embedstr = x.embChannels
const typestr = x.modelType == 0 ? "org" : "webui"
const metadata = x.deprecated ? "[deprecated version]" : `[${f0str},${srstr},${embedstr},${typestr}]`
return (
<div key={index} className={className} onClick={() => { onSwitchModelClicked(index, filename) }}>
<div>
{filename}
</div>
<div>{metadata}</div>
</div>
)
})

View File

@ -28,11 +28,15 @@ class ModelWrapper:
self.samplingRate = metadata["samplingRate"]
self.f0 = metadata["f0"]
self.embChannels = metadata["embChannels"]
self.modelType = metadata["modelType"]
self.deprecated = False
print(f"[Voice Changer] Onnx metadata: sr:{self.samplingRate}, f0:{self.f0}")
except:
self.samplingRate = 48000
self.f0 = True
self.embChannels = 256
self.modelType = 0
self.deprecated = True
print(f"[Voice Changer] ############## !!!! CAUTION !!!! ####################")
print(f"[Voice Changer] This onnx's version is depricated. Please regenerate onnxfile. Fallback to default")
print(f"[Voice Changer] Onnx metadata: sr:{self.samplingRate}, f0:{self.f0}")
@ -47,6 +51,12 @@ class ModelWrapper:
def getEmbChannels(self):
return self.embChannels
def getModelType(self):
return self.modelType
def getDeprecated(self):
return self.deprecated
def set_providers(self, providers, provider_options=[{}]):
self.onnx_session.set_providers(providers=providers, provider_options=provider_options)

View File

@ -50,9 +50,10 @@ class ModelSlot():
samplingRate: int = -1
f0: bool = True
embChannels: int = 256
samplingRateOnnx: int = -1
f0Onnx: bool = True
embChannelsOnnx: int = 256
deprecated: bool = False
# samplingRateOnnx: int = -1
# f0Onnx: bool = True
# embChannelsOnnx: int = 256
@dataclass
@ -130,6 +131,12 @@ class RVC:
print("[Voice Changer] RVC loading... slot:", tmp_slot)
# Load metadata
if self.settings.modelSlots[tmp_slot].pyTorchModelFile != None and self.settings.modelSlots[tmp_slot].pyTorchModelFile != "":
self._setInfoByPytorch(tmp_slot, self.settings.modelSlots[tmp_slot].pyTorchModelFile)
if self.settings.modelSlots[tmp_slot].onnxModelFile != None and self.settings.modelSlots[tmp_slot].onnxModelFile != "":
self._setInfoByONNX(tmp_slot, self.settings.modelSlots[tmp_slot].onnxModelFile)
try:
hubert_path = self.params["hubert_base"]
models, saved_cfg, task = checkpoint_utils.load_model_ensemble_and_task([hubert_path], suffix="",)
@ -151,6 +158,28 @@ class RVC:
return self.get_info()
def _setInfoByPytorch(self, slot, file):
cpt = torch.load(file, map_location="cpu")
config_len = len(cpt["config"])
if config_len == 18:
self.settings.modelSlots[slot].modelType = RVC_MODEL_TYPE_RVC
self.settings.modelSlots[slot].embChannels = 256
else:
self.settings.modelSlots[slot].modelType = RVC_MODEL_TYPE_WEBUI
self.settings.modelSlots[slot].embChannels = cpt["config"][17]
self.settings.modelSlots[slot].f0 = True if cpt["f0"] == 1 else False
self.settings.modelSlots[slot].samplingRate = cpt["config"][-1]
self.settings.modelSamplingRate = cpt["config"][-1]
def _setInfoByONNX(self, slot, file):
tmp_onnx_session = ModelWrapper(file)
self.settings.modelSlots[slot].modelType = tmp_onnx_session.getModelType()
self.settings.modelSlots[slot].embChannelsOnnx = tmp_onnx_session.getEmbChannels()
self.settings.modelSlots[slot].f0 = tmp_onnx_session.getF0()
self.settings.modelSlots[slot].samplingRate = tmp_onnx_session.getSamplingRate()
self.settings.modelSlots[slot].deprecated = tmp_onnx_session.getDeprecated()
def prepareModel(self, slot: int):
print("[Voice Changer] Prepare Model of slot:", slot)
pyTorchModelFile = self.settings.modelSlots[slot].pyTorchModelFile
@ -172,17 +201,17 @@ class RVC:
(2-2) rvc-webuiの(256 or 768) x (ーマルor pitchレス)判定 256, or 768 は17番目の要素で判定, ーマルor pitchレスはckp["f0"]で判定
'''
config_len = len(cpt["config"])
if config_len == 18:
self.settings.modelSlots[slot].modelType = RVC_MODEL_TYPE_RVC
self.settings.modelSlots[slot].embChannels = 256
else:
self.settings.modelSlots[slot].modelType = RVC_MODEL_TYPE_WEBUI
self.settings.modelSlots[slot].embChannels = cpt["config"][17]
self.settings.modelSlots[slot].f0 = True if cpt["f0"] == 1 else False
self.settings.modelSlots[slot].samplingRate = cpt["config"][-1]
# config_len = len(cpt["config"])
# if config_len == 18:
# self.settings.modelSlots[slot].modelType = RVC_MODEL_TYPE_RVC
# self.settings.modelSlots[slot].embChannels = 256
# else:
# self.settings.modelSlots[slot].modelType = RVC_MODEL_TYPE_WEBUI
# self.settings.modelSlots[slot].embChannels = cpt["config"][17]
# self.settings.modelSlots[slot].f0 = True if cpt["f0"] == 1 else False
# self.settings.modelSlots[slot].samplingRate = cpt["config"][-1]
self.settings.modelSamplingRate = cpt["config"][-1]
# self.settings.modelSamplingRate = cpt["config"][-1]
if self.settings.modelSlots[slot].modelType == RVC_MODEL_TYPE_RVC and self.settings.modelSlots[slot].f0 == True:
net_g = SynthesizerTrnMs256NSFsid(*cpt["config"], is_half=self.is_half)
@ -213,16 +242,14 @@ class RVC:
if onnxModelFile != None and onnxModelFile != "":
print("[Voice Changer] Loading ONNX Model...")
self.next_onnx_session = ModelWrapper(onnxModelFile)
self.settings.modelSlots[slot].samplingRateOnnx = self.next_onnx_session.getSamplingRate()
self.settings.modelSlots[slot].f0Onnx = self.next_onnx_session.getF0()
# if self.settings.modelSlots[slot].samplingRate == -1: # ONNXにsampling rateが入っていない
# self.settings.modelSlots[slot].samplingRate = self.settings.modelSamplingRate
self.settings.modelSlots[slot].embChannelsOnnx = self.next_onnx_session.getEmbChannels()
# self.settings.modelSlots[slot].samplingRateOnnx = self.next_onnx_session.getSamplingRate()
# self.settings.modelSlots[slot].f0Onnx = self.next_onnx_session.getF0()
# self.settings.modelSlots[slot].embChannelsOnnx = self.next_onnx_session.getEmbChannels()
# ONNXがある場合は、ONNXの設定を優先
self.settings.modelSlots[slot].samplingRate = self.settings.modelSlots[slot].samplingRateOnnx
self.settings.modelSlots[slot].f0 = self.settings.modelSlots[slot].f0Onnx
self.settings.modelSlots[slot].embChannels = self.settings.modelSlots[slot].embChannelsOnnx
# # ONNXがある場合は、ONNXの設定を優先
# self.settings.modelSlots[slot].samplingRate = self.settings.modelSlots[slot].samplingRateOnnx
# self.settings.modelSlots[slot].f0 = self.settings.modelSlots[slot].f0Onnx
# self.settings.modelSlots[slot].embChannels = self.settings.modelSlots[slot].embChannelsOnnx
else:
print("[Voice Changer] Skip Loading ONNX Model...")
self.next_onnx_session = None
@ -469,7 +496,7 @@ class RVC:
metadata = {
"application": "VC_CLIENT",
"version": "1",
"ModelType": self.settings.modelSlots[self.settings.modelSlotIndex].modelType,
"modelType": self.settings.modelSlots[self.settings.modelSlotIndex].modelType,
"samplingRate": self.settings.modelSlots[self.settings.modelSlotIndex].samplingRate,
"f0": self.settings.modelSlots[self.settings.modelSlotIndex].f0,
"embChannels": self.settings.modelSlots[self.settings.modelSlotIndex].embChannels,

View File

@ -371,13 +371,13 @@ def export2onnx(input_model, output_model, output_model_simple, is_half, metadat
else:
dev = torch.device("cpu")
if metadata["f0"] == True and metadata["ModelType"] == RVC_MODEL_TYPE_RVC:
if metadata["f0"] == True and metadata["modelType"] == RVC_MODEL_TYPE_RVC:
net_g_onnx = SynthesizerTrnMs256NSFsid_ONNX(*cpt["config"], is_half=is_half)
elif metadata["f0"] == True and metadata["ModelType"] == RVC_MODEL_TYPE_WEBUI:
elif metadata["f0"] == True and metadata["modelType"] == RVC_MODEL_TYPE_WEBUI:
net_g_onnx = SynthesizerTrnMsNSFsid_webui_ONNX(**cpt["params"], is_half=is_half)
elif metadata["f0"] == False and metadata["ModelType"] == RVC_MODEL_TYPE_RVC:
elif metadata["f0"] == False and metadata["modelType"] == RVC_MODEL_TYPE_RVC:
net_g_onnx = SynthesizerTrnMs256NSFsid_nono_ONNX(*cpt["config"])
elif metadata["f0"] == False and metadata["ModelType"] == RVC_MODEL_TYPE_WEBUI:
elif metadata["f0"] == False and metadata["modelType"] == RVC_MODEL_TYPE_WEBUI:
net_g_onnx = SynthesizerTrnMsNSFsidNono_webui_ONNX(**cpt["params"])
net_g_onnx.eval().to(dev)