Skip to content

Commit 23f64d3

Browse files
committed
optimize: cpt as #836 mentioned
1 parent 76c18b5 commit 23f64d3

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

infer-web.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import os
22
import shutil
3-
import sys
4-
5-
now_dir = os.getcwd()
6-
sys.path.append(now_dir)
73
import traceback, pdb
84
import warnings
95

@@ -40,7 +36,7 @@
4036

4137
logging.getLogger("numba").setLevel(logging.WARNING)
4238

43-
39+
now_dir = os.getcwd()
4440
tmp = os.path.join(now_dir, "TEMP")
4541
shutil.rmtree(tmp, ignore_errors=True)
4642
shutil.rmtree(
@@ -156,6 +152,7 @@ def load_hubert():
156152
if name.endswith(".pth") or "onnx" in name:
157153
uvr5_names.append(name.replace(".pth", ""))
158154

155+
cpt = None
159156

160157
def vc_single(
161158
sid,
@@ -172,7 +169,7 @@ def vc_single(
172169
rms_mix_rate,
173170
protect,
174171
): # spk_item, input_audio0, vc_transform0,f0_file,f0method0
175-
global tgt_sr, net_g, vc, hubert_model, version
172+
global tgt_sr, net_g, vc, hubert_model, version, cpt
176173
if input_audio_path is None:
177174
return "You need to upload an audio", None
178175
f0_up_key = int(f0_up_key)
@@ -429,9 +426,7 @@ def get_vc(sid, to_return_protect0, to_return_protect1):
429426
else:
430427
net_g = SynthesizerTrnMs768NSFsid_nono(*cpt["config"])
431428
del net_g, cpt
432-
if torch.cuda.is_available():
433-
torch.cuda.empty_cache()
434-
cpt = None
429+
if torch.cuda.is_available(): torch.cuda.empty_cache()
435430
return {"visible": False, "__type__": "update"}
436431
person = "%s/%s" % (weight_root, sid)
437432
print("loading %s" % person)
@@ -1253,6 +1248,7 @@ def change_info_(ckpt_path):
12531248

12541249

12551250
def export_onnx(ModelPath, ExportedPath):
1251+
global cpt
12561252
cpt = torch.load(ModelPath, map_location="cpu")
12571253
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0]
12581254
vec_channels = 256 if cpt.get("version", "v1") == "v1" else 768

0 commit comments

Comments
 (0)