externalize content vec model

This commit is contained in:
wataru 2023-03-16 08:11:38 +09:00
parent c089e6bc51
commit 03d481ab67
5 changed files with 23 additions and 25 deletions

View File

@ -40,7 +40,7 @@ def setupArgParser():
parser.add_argument("--modelType", type=str,
default="MMVCv15", help="model type: MMVCv13, MMVCv15, so-vits-svc-40v2")
parser.add_argument("--cluster", type=str, help="path to cluster model")
parser.add_argument("--hubert", type=str, help="path to hubert model, 現バージョンではhubertTorchModelは固定値で上書きされるため、設定しても効果ない。")
parser.add_argument("--hubert", type=str, help="path to hubert model")
parser.add_argument("--internal", type=strtobool, default=False, help="各種パスをmac appの中身に変換")
return parser
@ -84,7 +84,7 @@ PORT = args.p
CONFIG = args.c if args.c != None else None
MODEL = args.m if args.m != None else None
ONNX_MODEL = args.o if args.o != None else None
HUBERT_MODEL = args.hubert if args.hubert != None else None
HUBERT_MODEL = args.hubert if args.hubert != None else None # hubertはユーザがダウンロードして解凍フォルダに格納する運用。
CLUSTER_MODEL = args.cluster if args.cluster != None else None
if args.internal and hasattr(sys, "_MEIPASS"):
print("use internal path")
@ -122,13 +122,12 @@ if args.colab == True:
os.environ["colab"] = "True"
if __name__ == 'MMVCServerSIO':
voiceChangerManager = VoiceChangerManager.get_instance()
voiceChangerManager = VoiceChangerManager.get_instance({"hubert": HUBERT_MODEL})
if CONFIG and (MODEL or ONNX_MODEL):
if MODEL_TYPE == "MMVCv15" or MODEL_TYPE == "MMVCv13":
voiceChangerManager.loadModel(CONFIG, MODEL, ONNX_MODEL, None, None)
voiceChangerManager.loadModel(CONFIG, MODEL, ONNX_MODEL, None)
else:
# !! 注意 !! hubertTorchModelは固定値で上書きされるため、設定しても効果ない。
voiceChangerManager.loadModel(CONFIG, MODEL, ONNX_MODEL, CLUSTER_MODEL, HUBERT_MODEL)
voiceChangerManager.loadModel(CONFIG, MODEL, ONNX_MODEL, CLUSTER_MODEL)
app_fastapi = MMVC_Rest.get_instance(voiceChangerManager)
app_socketio = MMVC_SocketIOApp.get_instance(app_fastapi, voiceChangerManager)

View File

@ -64,9 +64,8 @@ class MMVC_Rest_Fileuploader:
clusterTorchModelFilePath = os.path.join(UPLOAD_DIR, clusterTorchModelFilename) if clusterTorchModelFilename != "-" else None
hubertTorchModelFilePath = os.path.join(UPLOAD_DIR, hubertTorchModelFilename) if hubertTorchModelFilename != "-" else None
# !! 注意 !! hubertTorchModelは固定値で上書きされるため、設定しても効果ない。
info = self.voiceChangerManager.loadModel(configFilePath, pyTorchModelFilePath, onnxModelFilePath,
clusterTorchModelFilePath, hubertTorchModelFilePath)
clusterTorchModelFilePath)
json_compatible_item_data = jsonable_encoder(info)
return JSONResponse(content=json_compatible_item_data)
# return {"load": f"{configFilePath}, {pyTorchModelFilePath}, {onnxModelFilePath}"}

View File

@ -55,7 +55,7 @@ class SoVitsSvc40v2Settings():
class SoVitsSvc40v2:
def __init__(self):
def __init__(self, params):
self.settings = SoVitsSvc40v2Settings()
self.net_g = None
self.onnx_session = None
@ -63,9 +63,10 @@ class SoVitsSvc40v2:
self.raw_path = io.BytesIO()
self.gpu_num = torch.cuda.device_count()
self.prevVol = 0
self.params = params
print("so-vits-initialization:", params)
def loadModel(self, config: str, pyTorch_model_file: str = None, onnx_model_file: str = None, clusterTorchModel: str = None, hubertTorchModel: str = None):
# !! 注意 !! hubertTorchModelは固定値で上書きされるため、設定しても効果ない。
def loadModel(self, config: str, pyTorch_model_file: str = None, onnx_model_file: str = None, clusterTorchModel: str = None):
self.settings.configFile = config
self.hps = utils.get_hparams_from_file(config)
@ -73,10 +74,11 @@ class SoVitsSvc40v2:
# hubert model
try:
if sys.platform.startswith('darwin'):
vec_path = os.path.join(sys._MEIPASS, "hubert/checkpoint_best_legacy_500.pt")
else:
vec_path = "hubert/checkpoint_best_legacy_500.pt"
# if sys.platform.startswith('darwin'):
# vec_path = os.path.join(sys._MEIPASS, "hubert/checkpoint_best_legacy_500.pt")
# else:
# vec_path = "hubert/checkpoint_best_legacy_500.pt"
vec_path = self.params["hubert"]
models, saved_cfg, task = checkpoint_utils.load_model_ensemble_and_task(
[vec_path],

View File

@ -39,7 +39,7 @@ class VocieChangerSettings():
class VoiceChanger():
def __init__(self):
def __init__(self, params):
# 初期化
self.settings = VocieChangerSettings()
self.onnx_session = None
@ -58,7 +58,7 @@ class VoiceChanger():
self.voiceChanger = MMVCv13()
elif self.modelType == "so-vits-svc-40v2" or self.modelType == "so-vits-svc-40v2_tsukuyomi":
from voice_changer.SoVitsSvc40v2.SoVitsSvc40v2 import SoVitsSvc40v2
self.voiceChanger = SoVitsSvc40v2()
self.voiceChanger = SoVitsSvc40v2(params)
else:
from voice_changer.MMVCv13.MMVCv13 import MMVCv13
@ -70,12 +70,11 @@ class VoiceChanger():
print(f"VoiceChanger Initialized (GPU_NUM:{self.gpu_num}, mps_enabled:{self.mps_enabled})")
def loadModel(self, config: str, pyTorch_model_file: str = None, onnx_model_file: str = None, clusterTorchModel: str = None, hubertTorchModel: str = None):
def loadModel(self, config: str, pyTorch_model_file: str = None, onnx_model_file: str = None, clusterTorchModel: str = None):
if self.modelType == "MMVCv15" or self.modelType == "MMVCv13":
return self.voiceChanger.loadModel(config, pyTorch_model_file, onnx_model_file)
else: # so-vits-svc-40v2
# !! 注意 !! hubertTorchModelは固定値で上書きされるため、設定しても効果ない。
return self.voiceChanger.loadModel(config, pyTorch_model_file, onnx_model_file, clusterTorchModel, hubertTorchModel)
return self.voiceChanger.loadModel(config, pyTorch_model_file, onnx_model_file, clusterTorchModel)
def get_info(self):
data = asdict(self.settings)

View File

@ -4,15 +4,14 @@ from voice_changer.VoiceChanger import VoiceChanger
class VoiceChangerManager():
@classmethod
def get_instance(cls):
def get_instance(cls, params):
if not hasattr(cls, "_instance"):
cls._instance = cls()
cls._instance.voiceChanger = VoiceChanger()
cls._instance.voiceChanger = VoiceChanger(params)
return cls._instance
def loadModel(self, config, model, onnx_model, clusterTorchModel, hubertTorchModel):
# !! 注意 !! hubertTorchModelは固定値で上書きされるため、設定しても効果ない。
info = self.voiceChanger.loadModel(config, model, onnx_model, clusterTorchModel, hubertTorchModel)
def loadModel(self, config, model, onnx_model, clusterTorchModel):
info = self.voiceChanger.loadModel(config, model, onnx_model, clusterTorchModel)
info["status"] = "OK"
return info