Spaces:
Running
Running
kevinwang676
commited on
Update GPT_SoVITS/app_vc.py
Browse files- GPT_SoVITS/app_vc.py +13 -10
GPT_SoVITS/app_vc.py
CHANGED
@@ -54,10 +54,10 @@ def get_pretrain_model_path(env_name, log_file, def_path):
|
|
54 |
device = 'cpu'
|
55 |
|
56 |
gpt_path = get_pretrain_model_path('gpt_path', "./gweight.txt",
|
57 |
-
"GPT_SoVITS/pretrained_models/s1bert25hz-
|
58 |
|
59 |
sovits_path = get_pretrain_model_path('sovits_path', "./sweight.txt",
|
60 |
-
"GPT_SoVITS/pretrained_models/
|
61 |
|
62 |
cnhubert_base_path = get_pretrain_model_path("cnhubert_base_path", '', "GPT_SoVITS/pretrained_models/chinese-hubert-base")
|
63 |
|
@@ -145,11 +145,17 @@ def change_sovits_weights(sovits_path):
|
|
145 |
hps = dict_s2["config"]
|
146 |
hps = DictToAttrRecursive(hps)
|
147 |
hps.model.semantic_frame_rate = "25hz"
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
vq_model = SynthesizerTrn(
|
149 |
hps.data.filter_length // 2 + 1,
|
150 |
hps.train.segment_size // hps.data.hop_length,
|
151 |
n_speakers=hps.data.n_speakers,
|
152 |
-
**
|
153 |
)
|
154 |
if ("pretrained" not in sovits_path):
|
155 |
del vq_model.enc_q
|
@@ -158,9 +164,7 @@ def change_sovits_weights(sovits_path):
|
|
158 |
else:
|
159 |
vq_model = vq_model.to(device)
|
160 |
vq_model.eval()
|
161 |
-
|
162 |
-
with open("./sweight.txt", "w", encoding="utf-8") as f:
|
163 |
-
f.write(sovits_path)
|
164 |
|
165 |
|
166 |
change_sovits_weights(sovits_path)
|
@@ -179,8 +183,7 @@ def change_gpt_weights(gpt_path):
|
|
179 |
t2s_model = t2s_model.to(device)
|
180 |
t2s_model.eval()
|
181 |
total = sum([param.nelement() for param in t2s_model.parameters()])
|
182 |
-
|
183 |
-
with open("./gweight.txt", "w", encoding="utf-8") as f: f.write(gpt_path)
|
184 |
|
185 |
|
186 |
change_gpt_weights(gpt_path)
|
@@ -293,8 +296,8 @@ def change_choices():
|
|
293 |
return {"choices": sorted(SoVITS_names, key=custom_sort_key), "__type__": "update"}, {"choices": sorted(GPT_names, key=custom_sort_key), "__type__": "update"}
|
294 |
|
295 |
|
296 |
-
pretrained_sovits_name = "GPT_SoVITS/pretrained_models/
|
297 |
-
pretrained_gpt_name = "GPT_SoVITS/pretrained_models/s1bert25hz-
|
298 |
SoVITS_weight_root = "SoVITS_weights"
|
299 |
GPT_weight_root = "GPT_weights"
|
300 |
os.makedirs(SoVITS_weight_root, exist_ok=True)
|
|
|
54 |
device = 'cpu'
|
55 |
|
56 |
gpt_path = get_pretrain_model_path('gpt_path', "./gweight.txt",
|
57 |
+
"GPT_SoVITS/pretrained_models/gsv-v2final-pretrained/s1bert25hz-5kh-longer-epoch=12-step=369668.ckpt")
|
58 |
|
59 |
sovits_path = get_pretrain_model_path('sovits_path', "./sweight.txt",
|
60 |
+
"GPT_SoVITS/pretrained_models/gsv-v2final-pretrained/s2G2333k.pth")
|
61 |
|
62 |
cnhubert_base_path = get_pretrain_model_path("cnhubert_base_path", '', "GPT_SoVITS/pretrained_models/chinese-hubert-base")
|
63 |
|
|
|
145 |
hps = dict_s2["config"]
|
146 |
hps = DictToAttrRecursive(hps)
|
147 |
hps.model.semantic_frame_rate = "25hz"
|
148 |
+
if dict_s2['weight']['enc_p.text_embedding.weight'].shape[0] == 322:
|
149 |
+
hps.model.version = "v1"
|
150 |
+
else:
|
151 |
+
hps.model.version = "v2"
|
152 |
+
print("sovits版本:",hps.model.version)
|
153 |
+
model_params_dict = vars(hps.model)
|
154 |
vq_model = SynthesizerTrn(
|
155 |
hps.data.filter_length // 2 + 1,
|
156 |
hps.train.segment_size // hps.data.hop_length,
|
157 |
n_speakers=hps.data.n_speakers,
|
158 |
+
**model_params_dict
|
159 |
)
|
160 |
if ("pretrained" not in sovits_path):
|
161 |
del vq_model.enc_q
|
|
|
164 |
else:
|
165 |
vq_model = vq_model.to(device)
|
166 |
vq_model.eval()
|
167 |
+
vq_model.load_state_dict(dict_s2["weight"], strict=False)
|
|
|
|
|
168 |
|
169 |
|
170 |
change_sovits_weights(sovits_path)
|
|
|
183 |
t2s_model = t2s_model.to(device)
|
184 |
t2s_model.eval()
|
185 |
total = sum([param.nelement() for param in t2s_model.parameters()])
|
186 |
+
logger.info("Number of parameter: %.2fM" % (total / 1e6))
|
|
|
187 |
|
188 |
|
189 |
change_gpt_weights(gpt_path)
|
|
|
296 |
return {"choices": sorted(SoVITS_names, key=custom_sort_key), "__type__": "update"}, {"choices": sorted(GPT_names, key=custom_sort_key), "__type__": "update"}
|
297 |
|
298 |
|
299 |
+
pretrained_sovits_name = "GPT_SoVITS/pretrained_models/gsv-v2final-pretrained/s2G2333k.pth"
|
300 |
+
pretrained_gpt_name = "GPT_SoVITS/pretrained_models/gsv-v2final-pretrained/s1bert25hz-5kh-longer-epoch=12-step=369668.ckpt"
|
301 |
SoVITS_weight_root = "SoVITS_weights"
|
302 |
GPT_weight_root = "GPT_weights"
|
303 |
os.makedirs(SoVITS_weight_root, exist_ok=True)
|