mirror of
https://github.com/w-okada/voice-changer.git
synced 2025-01-23 13:35:12 +03:00
WIP:improve model selector (so-vits-svc40v2)
This commit is contained in:
parent
0bb660ab2f
commit
069ebc22da
@ -32,22 +32,36 @@
|
||||
],
|
||||
"modelSetting": [
|
||||
{
|
||||
"name": "modelUploader",
|
||||
"name": "modelUploaderv2",
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"name": "commonFileSelect",
|
||||
"options": {
|
||||
"showConfig": true,
|
||||
"showOnnx": false,
|
||||
"showPyTorch": true,
|
||||
"showCorrespondence": false,
|
||||
"showPyTorchCluster": true,
|
||||
"showPyTorchEnableCheckBox": true,
|
||||
"defaultEnablePyTorch": true
|
||||
"title": "Config(.json)",
|
||||
"acceptExtentions": ["json"],
|
||||
"fileKind": "soVitsSvc40v2Config"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "framework",
|
||||
"name": "commonFileSelect",
|
||||
"options": {
|
||||
"showFramework": true
|
||||
"title": "Model(.pth, .pt)",
|
||||
"acceptExtentions": ["pth", "pt"],
|
||||
"fileKind": "soVitsSvc40v2Model"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "commonFileSelect",
|
||||
"options": {
|
||||
"title": "Cluster(.pth, .pt)",
|
||||
"acceptExtentions": ["pth", "pt"],
|
||||
"fileKind": "soVitsSvc40v2Cluster"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "modelUploadButtonRow2",
|
||||
"options": {}
|
||||
}
|
||||
],
|
||||
"lab": [],
|
||||
|
4
client/demo/dist/index.js
vendored
4
client/demo/dist/index.js
vendored
File diff suppressed because one or more lines are too long
@ -32,22 +32,36 @@
|
||||
],
|
||||
"modelSetting": [
|
||||
{
|
||||
"name": "modelUploader",
|
||||
"name": "modelUploaderv2",
|
||||
"options": {}
|
||||
},
|
||||
{
|
||||
"name": "commonFileSelect",
|
||||
"options": {
|
||||
"showConfig": true,
|
||||
"showOnnx": false,
|
||||
"showPyTorch": true,
|
||||
"showCorrespondence": false,
|
||||
"showPyTorchCluster": true,
|
||||
"showPyTorchEnableCheckBox": true,
|
||||
"defaultEnablePyTorch": true
|
||||
"title": "Config(.json)",
|
||||
"acceptExtentions": ["json"],
|
||||
"fileKind": "soVitsSvc40v2Config"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "framework",
|
||||
"name": "commonFileSelect",
|
||||
"options": {
|
||||
"showFramework": true
|
||||
"title": "Model(.pth, .pt)",
|
||||
"acceptExtentions": ["pth", "pt"],
|
||||
"fileKind": "soVitsSvc40v2Model"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "commonFileSelect",
|
||||
"options": {
|
||||
"title": "Cluster(.pth, .pt)",
|
||||
"acceptExtentions": ["pth", "pt"],
|
||||
"fileKind": "soVitsSvc40v2Cluster"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "modelUploadButtonRow2",
|
||||
"options": {}
|
||||
}
|
||||
],
|
||||
"lab": [],
|
||||
|
@ -18,6 +18,9 @@ export const Filekinds = {
|
||||
"soVitsSvc40Config": "soVitsSvc40Config",
|
||||
"soVitsSvc40Model": "soVitsSvc40Model",
|
||||
"soVitsSvc40Cluster": "soVitsSvc40Cluster",
|
||||
"soVitsSvc40v2Config": "soVitsSvc40v2Config",
|
||||
"soVitsSvc40v2Model": "soVitsSvc40v2Model",
|
||||
"soVitsSvc40v2Cluster": "soVitsSvc40v2Cluster",
|
||||
|
||||
"ddspSvcModel": "ddspSvcModel",
|
||||
"ddspSvcModelConfig": "ddspSvcModelConfig",
|
||||
|
@ -32,6 +32,10 @@ export type FileUploadSetting = {
|
||||
soVitsSvc40Config: ModelData | null
|
||||
soVitsSvc40Model: ModelData | null
|
||||
soVitsSvc40Cluster: ModelData | null
|
||||
soVitsSvc40v2Config: ModelData | null
|
||||
soVitsSvc40v2Model: ModelData | null
|
||||
soVitsSvc40v2Cluster: ModelData | null
|
||||
|
||||
|
||||
ddspSvcModel: ModelData | null
|
||||
ddspSvcModelConfig: ModelData | null
|
||||
@ -62,6 +66,9 @@ const InitialFileUploadSetting: FileUploadSetting = {
|
||||
soVitsSvc40Config: null,
|
||||
soVitsSvc40Model: null,
|
||||
soVitsSvc40Cluster: null,
|
||||
soVitsSvc40v2Config: null,
|
||||
soVitsSvc40v2Model: null,
|
||||
soVitsSvc40v2Cluster: null,
|
||||
|
||||
ddspSvcModel: null,
|
||||
ddspSvcModelConfig: null,
|
||||
@ -257,6 +264,15 @@ export const useServerSetting = (props: UseServerSettingProps): ServerSettingSta
|
||||
alert("モデルファイルを指定する必要があります。")
|
||||
return
|
||||
}
|
||||
} else if (props.clientType == "so-vits-svc-40v2") {
|
||||
if (!fileUploadSettings[slot].soVitsSvc40v2Config) {
|
||||
alert("Configファイルを指定する必要があります。")
|
||||
return
|
||||
}
|
||||
if (!fileUploadSettings[slot].soVitsSvc40v2Model) {
|
||||
alert("モデルファイルを指定する必要があります。")
|
||||
return
|
||||
}
|
||||
} else if (props.clientType == "DDSP-SVC") {
|
||||
if (!fileUploadSettings[slot].ddspSvcModel) {
|
||||
alert("DDSPモデルを指定する必要があります。")
|
||||
@ -356,7 +372,10 @@ export const useServerSetting = (props: UseServerSettingProps): ServerSettingSta
|
||||
fileUploadSetting.mmvcv15Model,
|
||||
fileUploadSetting.soVitsSvc40Config,
|
||||
fileUploadSetting.soVitsSvc40Model,
|
||||
fileUploadSetting.soVitsSvc40Cluster
|
||||
fileUploadSetting.soVitsSvc40Cluster,
|
||||
fileUploadSetting.soVitsSvc40v2Config,
|
||||
fileUploadSetting.soVitsSvc40v2Model,
|
||||
fileUploadSetting.soVitsSvc40v2Cluster
|
||||
].filter(x => { return x != null }) as ModelData[]
|
||||
for (let i = 0; i < normalModels.length; i++) {
|
||||
if (!normalModels[i].data) {
|
||||
@ -400,6 +419,9 @@ export const useServerSetting = (props: UseServerSettingProps): ServerSettingSta
|
||||
soVitsSvc40Config: fileUploadSetting.soVitsSvc40Config?.filename || "",
|
||||
soVitsSvc40Model: fileUploadSetting.soVitsSvc40Model?.filename || "",
|
||||
soVitsSvc40Cluster: fileUploadSetting.soVitsSvc40Cluster?.filename || "",
|
||||
soVitsSvc40v2Config: fileUploadSetting.soVitsSvc40v2Config?.filename || "",
|
||||
soVitsSvc40v2Model: fileUploadSetting.soVitsSvc40v2Model?.filename || "",
|
||||
soVitsSvc40v2Cluster: fileUploadSetting.soVitsSvc40v2Cluster?.filename || "",
|
||||
|
||||
ddspSvcModel: fileUploadSetting.ddspSvcModel?.filename ? "ddsp_mod/" + fileUploadSetting.ddspSvcModel?.filename : "",
|
||||
ddspSvcModelConfig: fileUploadSetting.ddspSvcModelConfig?.filename ? "ddsp_mod/" + fileUploadSetting.ddspSvcModelConfig?.filename : "",
|
||||
@ -480,6 +502,9 @@ export const useServerSetting = (props: UseServerSettingProps): ServerSettingSta
|
||||
soVitsSvc40Config: fileUploadSetting.soVitsSvc40Config ? { data: fileUploadSetting.soVitsSvc40Config.data, filename: fileUploadSetting.soVitsSvc40Config.filename } : null,
|
||||
soVitsSvc40Model: fileUploadSetting.soVitsSvc40Model ? { data: fileUploadSetting.soVitsSvc40Model.data, filename: fileUploadSetting.soVitsSvc40Model.filename } : null,
|
||||
soVitsSvc40Cluster: fileUploadSetting.soVitsSvc40Cluster ? { data: fileUploadSetting.soVitsSvc40Cluster.data, filename: fileUploadSetting.soVitsSvc40Cluster.filename } : null,
|
||||
soVitsSvc40v2Config: fileUploadSetting.soVitsSvc40v2Config ? { data: fileUploadSetting.soVitsSvc40v2Config.data, filename: fileUploadSetting.soVitsSvc40v2Config.filename } : null,
|
||||
soVitsSvc40v2Model: fileUploadSetting.soVitsSvc40v2Model ? { data: fileUploadSetting.soVitsSvc40v2Model.data, filename: fileUploadSetting.soVitsSvc40v2Model.filename } : null,
|
||||
soVitsSvc40v2Cluster: fileUploadSetting.soVitsSvc40v2Cluster ? { data: fileUploadSetting.soVitsSvc40v2Cluster.data, filename: fileUploadSetting.soVitsSvc40v2Cluster.filename } : null,
|
||||
|
||||
ddspSvcModel: fileUploadSetting.ddspSvcModel ? { data: fileUploadSetting.ddspSvcModel.data, filename: fileUploadSetting.ddspSvcModel.filename } : null,
|
||||
ddspSvcModelConfig: fileUploadSetting.ddspSvcModelConfig ? { data: fileUploadSetting.ddspSvcModelConfig.data, filename: fileUploadSetting.ddspSvcModelConfig.filename } : null,
|
||||
|
@ -52,8 +52,8 @@ class SoVitsSvc40v2Settings:
|
||||
clusterInferRatio: float = 0.1
|
||||
|
||||
framework: str = "PyTorch" # PyTorch or ONNX
|
||||
pyTorchModelFile: str = ""
|
||||
onnxModelFile: str = ""
|
||||
pyTorchModelFile: str | None = ""
|
||||
onnxModelFile: str | None = ""
|
||||
configFile: str = ""
|
||||
|
||||
speakers: dict[str, int] = field(default_factory=lambda: {})
|
||||
@ -79,13 +79,20 @@ class SoVitsSvc40v2:
|
||||
print("so-vits-svc 40v2 initialization:", params)
|
||||
|
||||
def loadModel(self, props: LoadModelParams):
|
||||
self.settings.configFile = props.files.configFilename
|
||||
params = props.params
|
||||
self.settings.configFile = params["files"]["soVitsSvc40v2Config"]
|
||||
self.hps = utils.get_hparams_from_file(self.settings.configFile)
|
||||
self.settings.speakers = self.hps.spk
|
||||
|
||||
self.settings.pyTorchModelFile = props.files.pyTorchModelFilename
|
||||
self.settings.onnxModelFile = props.files.onnxModelFilename
|
||||
clusterTorchModel = props.files.clusterTorchModelFilename
|
||||
modelFile = params["files"]["soVitsSvc40v2Model"]
|
||||
if modelFile.endswith(".onnx"):
|
||||
self.settings.pyTorchModelFile = None
|
||||
self.settings.onnxModelFile = modelFile
|
||||
else:
|
||||
self.settings.pyTorchModelFile = modelFile
|
||||
self.settings.onnxModelFile = None
|
||||
|
||||
clusterTorchModel = params["files"]["soVitsSvc40v2Cluster"]
|
||||
|
||||
content_vec_path = self.params.content_vec_500
|
||||
hubert_base_path = self.params.hubert_base
|
||||
@ -123,41 +130,45 @@ class SoVitsSvc40v2:
|
||||
|
||||
# ONNXモデル生成
|
||||
if self.settings.onnxModelFile is not None:
|
||||
ort_options = onnxruntime.SessionOptions()
|
||||
ort_options.intra_op_num_threads = 8
|
||||
providers, options = self.getOnnxExecutionProvider()
|
||||
self.onnx_session = onnxruntime.InferenceSession(
|
||||
self.settings.onnxModelFile, providers=providers
|
||||
self.settings.onnxModelFile,
|
||||
providers=providers,
|
||||
provider_options=options,
|
||||
)
|
||||
# input_info = self.onnx_session.get_inputs()
|
||||
return self.get_info()
|
||||
|
||||
def update_settings(self, key: str, val: int | float | str):
|
||||
if key == "onnxExecutionProvider" and self.onnx_session is not None:
|
||||
if val == "CUDAExecutionProvider":
|
||||
if self.settings.gpu < 0 or self.settings.gpu >= self.gpu_num:
|
||||
self.settings.gpu = 0
|
||||
provider_options = [{"device_id": self.settings.gpu}]
|
||||
self.onnx_session.set_providers(
|
||||
providers=[val], provider_options=provider_options
|
||||
)
|
||||
def getOnnxExecutionProvider(self):
|
||||
if self.settings.gpu >= 0:
|
||||
return ["CUDAExecutionProvider"], [{"device_id": self.settings.gpu}]
|
||||
elif "DmlExecutionProvider" in onnxruntime.get_available_providers():
|
||||
return ["DmlExecutionProvider"], []
|
||||
else:
|
||||
self.onnx_session.set_providers(providers=[val])
|
||||
elif key in self.settings.intData:
|
||||
return ["CPUExecutionProvider"], [
|
||||
{
|
||||
"intra_op_num_threads": 8,
|
||||
"execution_mode": onnxruntime.ExecutionMode.ORT_PARALLEL,
|
||||
"inter_op_num_threads": 8,
|
||||
}
|
||||
]
|
||||
|
||||
def isOnnx(self):
|
||||
if self.settings.onnxModelFile is not None:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def update_settings(self, key: str, val: int | float | str):
|
||||
if key in self.settings.intData:
|
||||
val = int(val)
|
||||
setattr(self.settings, key, val)
|
||||
if (
|
||||
key == "gpu"
|
||||
and val >= 0
|
||||
and val < self.gpu_num
|
||||
and self.onnx_session is not None
|
||||
):
|
||||
providers = self.onnx_session.get_providers()
|
||||
print("Providers:", providers)
|
||||
if "CUDAExecutionProvider" in providers:
|
||||
provider_options = [{"device_id": self.settings.gpu}]
|
||||
|
||||
if key == "gpu" and self.isOnnx():
|
||||
providers, options = self.getOnnxExecutionProvider()
|
||||
if self.onnx_session is not None:
|
||||
self.onnx_session.set_providers(
|
||||
providers=["CUDAExecutionProvider"],
|
||||
provider_options=provider_options,
|
||||
providers=providers,
|
||||
provider_options=options,
|
||||
)
|
||||
elif key in self.settings.floatData:
|
||||
setattr(self.settings, key, float(val))
|
||||
@ -387,7 +398,7 @@ class SoVitsSvc40v2:
|
||||
return result
|
||||
|
||||
def inference(self, data):
|
||||
if self.settings.framework == "ONNX":
|
||||
if self.isOnnx():
|
||||
audio = self._onnx_inference(data)
|
||||
else:
|
||||
audio = self._pyTorch_inference(data)
|
||||
|
Loading…
Reference in New Issue
Block a user