mirror of
https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI.git
synced 2026-01-20 02:51:09 +00:00
fix: 卸载音色省显存
顺便将所有print换成了统一的logger
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import traceback
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
import numpy as np
|
||||
import soundfile as sf
|
||||
@@ -30,14 +32,7 @@ class VC:
|
||||
self.config = config
|
||||
|
||||
def get_vc(self, sid, *to_return_protect):
|
||||
person = f'{os.getenv("weight_root")}/{sid}'
|
||||
print(f"Loading: {person}")
|
||||
|
||||
self.cpt = torch.load(person, map_location="cpu")
|
||||
self.tgt_sr = self.cpt["config"][-1]
|
||||
self.cpt["config"][-3] = self.cpt["weight"]["emb_g.weight"].shape[0] # n_spk
|
||||
self.if_f0 = self.cpt.get("f0", 1)
|
||||
self.version = self.cpt.get("version", "v1")
|
||||
logger.info("Get sid: " + sid)
|
||||
|
||||
to_return_protect0 = {
|
||||
"visible": self.if_f0 != 0,
|
||||
@@ -54,6 +49,57 @@ class VC:
|
||||
"__type__": "update",
|
||||
}
|
||||
|
||||
if not sid:
|
||||
if self.hubert_model is not None: # 考虑到轮询, 需要加个判断看是否 sid 是由有模型切换到无模型的
|
||||
logger.info("Clean model cache")
|
||||
del self.net_g, self.n_spk, self.vc, self.hubert_model, self.tgt_sr # ,cpt
|
||||
self.hubert_model = self.net_g = self.n_spk = self.vc = self.hubert_model = self.tgt_sr = None
|
||||
if torch.cuda.is_available():
|
||||
torch.cuda.empty_cache()
|
||||
###楼下不这么折腾清理不干净
|
||||
self.if_f0 = self.cpt.get("f0", 1)
|
||||
self.version = self.cpt.get("version", "v1")
|
||||
if self.version == "v1":
|
||||
if self.if_f0 == 1:
|
||||
self.net_g = SynthesizerTrnMs256NSFsid(
|
||||
*self.cpt["config"], is_half=self.config.is_half
|
||||
)
|
||||
else:
|
||||
self.net_g = SynthesizerTrnMs256NSFsid_nono(*self.cpt["config"])
|
||||
elif self.version == "v2":
|
||||
if self.if_f0 == 1:
|
||||
self.net_g = SynthesizerTrnMs768NSFsid(
|
||||
*self.cpt["config"], is_half=self.config.is_half
|
||||
)
|
||||
else:
|
||||
self.net_g = SynthesizerTrnMs768NSFsid_nono(*self.cpt["config"])
|
||||
del self.net_g, self.cpt
|
||||
if torch.cuda.is_available():
|
||||
torch.cuda.empty_cache()
|
||||
return (
|
||||
{"visible": False, "__type__": "update"},
|
||||
{
|
||||
"visible": True,
|
||||
"value": to_return_protect0,
|
||||
"__type__": "update",
|
||||
},
|
||||
{
|
||||
"visible": True,
|
||||
"value": to_return_protect1,
|
||||
"__type__": "update",
|
||||
},
|
||||
"",
|
||||
"",
|
||||
)
|
||||
person = f'{os.getenv("weight_root")}/{sid}'
|
||||
logger.info(f"Loading: {person}")
|
||||
|
||||
self.cpt = torch.load(person, map_location="cpu")
|
||||
self.tgt_sr = self.cpt["config"][-1]
|
||||
self.cpt["config"][-3] = self.cpt["weight"]["emb_g.weight"].shape[0] # n_spk
|
||||
self.if_f0 = self.cpt.get("f0", 1)
|
||||
self.version = self.cpt.get("version", "v1")
|
||||
|
||||
synthesizer_class = {
|
||||
("v1", 1): SynthesizerTrnMs256NSFsid,
|
||||
("v1", 0): SynthesizerTrnMs256NSFsid_nono,
|
||||
@@ -77,7 +123,7 @@ class VC:
|
||||
self.pipeline = Pipeline(self.tgt_sr, self.config)
|
||||
n_spk = self.cpt["config"][-3]
|
||||
index = {"value": get_index_path_from_model(sid), "__type__": "update"}
|
||||
print("Select index:", index["value"])
|
||||
logger.info("Select index: " + index["value"])
|
||||
|
||||
return (
|
||||
(
|
||||
@@ -165,7 +211,7 @@ class VC:
|
||||
)
|
||||
except:
|
||||
info = traceback.format_exc()
|
||||
print(info)
|
||||
logger.warn(info)
|
||||
return info, (None, None)
|
||||
|
||||
def vc_multi(
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
from functools import lru_cache
|
||||
from time import time as ttime
|
||||
|
||||
@@ -139,7 +142,7 @@ class Pipeline(object):
|
||||
if not hasattr(self, "model_rmvpe"):
|
||||
from infer.lib.rmvpe import RMVPE
|
||||
|
||||
print(
|
||||
logger.info(
|
||||
"Loading rmvpe model,%s" % "%s/rmvpe.pt" % os.environ["rmvpe_root"]
|
||||
)
|
||||
self.model_rmvpe = RMVPE(
|
||||
@@ -152,7 +155,7 @@ class Pipeline(object):
|
||||
if "privateuseone" in str(self.device): # clean ortruntime memory
|
||||
del self.model_rmvpe.model
|
||||
del self.model_rmvpe
|
||||
print("Cleaning ortruntime memory")
|
||||
logger.info("Cleaning ortruntime memory")
|
||||
|
||||
f0 *= pow(2, f0_up_key / 12)
|
||||
# with open("test.txt","w")as f:f.write("\n".join([str(i)for i in f0.tolist()]))
|
||||
|
||||
Reference in New Issue
Block a user