voice-changer/server/voice_changer/RVC/RVCModelMerger.py

23 lines
948 B
Python
Raw Permalink Normal View History

2023-06-23 08:54:39 +03:00
import os
import torch
from const import UPLOAD_DIR
from voice_changer.RVC.modelMerger.MergeModel import merge_model
from voice_changer.utils.ModelMerger import ModelMerger, ModelMergerRequest
2023-08-04 21:02:43 +03:00
from voice_changer.utils.VoiceChangerParams import VoiceChangerParams
2023-06-23 08:54:39 +03:00
class RVCModelMerger(ModelMerger):
@classmethod
2023-08-04 21:02:43 +03:00
def merge_models(cls, params: VoiceChangerParams, request: ModelMergerRequest, storeSlot: int):
merged = merge_model(params, request)
2023-06-23 08:54:39 +03:00
# いったんは、アップロードフォルダに格納する。(歴史的経緯)
# 後続のloadmodelを呼び出すことで永続化モデルフォルダに移動させられる。
2023-08-04 21:02:43 +03:00
storeDir = os.path.join(UPLOAD_DIR)
2023-06-23 08:54:39 +03:00
print("[Voice Changer] store merged model to:", storeDir)
os.makedirs(storeDir, exist_ok=True)
storeFile = os.path.join(storeDir, "merged.pth")
torch.save(merged, storeFile)
return storeFile