Skip to content

Commit cfd9848

Browse files
Format code (#330)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 067731d commit cfd9848

File tree

6 files changed

+39
-22
lines changed

6 files changed

+39
-22
lines changed

config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import torch
33
from multiprocessing import cpu_count
44

5+
56
def config_file_change_fp32():
67
for config_file in ["32k.json", "40k.json", "48k.json"]:
78
with open(f"configs/{config_file}", "r") as f:
@@ -13,6 +14,7 @@ def config_file_change_fp32():
1314
with open("trainset_preprocess_pipeline_print.py", "w") as f:
1415
f.write(strr)
1516

17+
1618
class Config:
1719
def __init__(self):
1820
self.device = "cuda:0"

export_onnx.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,3 @@
5252
input_names=input_names,
5353
output_names=output_names,
5454
)
55-

gui.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'''
1+
"""
22
0416后的更新:
33
引入config中half
44
重建npy而不用填写
@@ -9,12 +9,14 @@
99
int16:
1010
增加无索引支持
1111
f0算法改harvest(怎么看就只有这个会影响CPU占用),但是不这么改效果不好
12-
'''
12+
"""
1313
import os, sys, traceback
14+
1415
now_dir = os.getcwd()
1516
sys.path.append(now_dir)
1617
from config import Config
17-
is_half=Config().is_half
18+
19+
is_half = Config().is_half
1820
import PySimpleGUI as sg
1921
import sounddevice as sd
2022
import noisereduce as nr
@@ -26,7 +28,12 @@
2628
import scipy.signal as signal
2729

2830
# import matplotlib.pyplot as plt
29-
from infer_pack.models import SynthesizerTrnMs256NSFsid, SynthesizerTrnMs256NSFsid_nono,SynthesizerTrnMs768NSFsid,SynthesizerTrnMs768NSFsid_nono
31+
from infer_pack.models import (
32+
SynthesizerTrnMs256NSFsid,
33+
SynthesizerTrnMs256NSFsid_nono,
34+
SynthesizerTrnMs768NSFsid,
35+
SynthesizerTrnMs768NSFsid_nono,
36+
)
3037
from i18n import I18nAuto
3138

3239
i18n = I18nAuto()
@@ -63,7 +70,7 @@ def __init__(
6370
)
6471
self.model = models[0]
6572
self.model = self.model.to(device)
66-
if(is_half==True):
73+
if is_half == True:
6774
self.model = self.model.half()
6875
else:
6976
self.model = self.model.float()
@@ -75,21 +82,25 @@ def __init__(
7582
self.version = cpt.get("version", "v1")
7683
if version == "v1":
7784
if if_f0 == 1:
78-
self.net_g = SynthesizerTrnMs256NSFsid(*cpt["config"], is_half=config.is_half)
85+
self.net_g = SynthesizerTrnMs256NSFsid(
86+
*cpt["config"], is_half=config.is_half
87+
)
7988
else:
8089
self.net_g = SynthesizerTrnMs256NSFsid_nono(*cpt["config"])
8190
elif version == "v2":
8291
if if_f0 == 1:
83-
self.net_g = SynthesizerTrnMs768NSFsid(*cpt["config"], is_half=config.is_half)
92+
self.net_g = SynthesizerTrnMs768NSFsid(
93+
*cpt["config"], is_half=config.is_half
94+
)
8495
else:
8596
self.net_g = SynthesizerTrnMs768NSFsid_nono(*cpt["config"])
8697
del self.net_g.enc_q
8798
print(self.net_g.load_state_dict(cpt["weight"], strict=False))
8899
self.net_g.eval().to(device)
89-
if(is_half==True):
90-
self.net_g=self.net_g.half()
100+
if is_half == True:
101+
self.net_g = self.net_g.half()
91102
else:
92-
self.net_g=self.net_g.float()
103+
self.net_g = self.net_g.float()
93104
except:
94105
print(traceback.format_exc())
95106

@@ -151,15 +162,18 @@ def infer(self, feats: torch.Tensor) -> np.ndarray:
151162

152163
####索引优化
153164
try:
154-
if hasattr(self, "index") and hasattr(self, "big_npy") and self.index_rate != 0:
165+
if (
166+
hasattr(self, "index")
167+
and hasattr(self, "big_npy")
168+
and self.index_rate != 0
169+
):
155170
npy = feats[0].cpu().numpy().astype("float32")
156171
score, ix = self.index.search(npy, k=8)
157172
weight = np.square(1 / score)
158173
weight /= weight.sum(axis=1, keepdims=True)
159-
npy = np.sum(
160-
self.big_npy[ix] * np.expand_dims(weight, axis=2), axis=1
161-
)
162-
if(is_half==True):npy=npy.astype("float16")
174+
npy = np.sum(self.big_npy[ix] * np.expand_dims(weight, axis=2), axis=1)
175+
if is_half == True:
176+
npy = npy.astype("float16")
163177
feats = (
164178
torch.from_numpy(npy).unsqueeze(0).to(device) * self.index_rate
165179
+ (1 - self.index_rate) * feats

i18n.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ def __init__(self, language=None):
1818
if not os.path.exists(f"./i18n/{language}.json"):
1919
language = "en_US"
2020
self.language = language
21-
#print("Use Language:", language)
21+
# print("Use Language:", language)
2222
self.language_map = load_language_list(language)
2323

2424
def __call__(self, key):
2525
return self.language_map.get(key, key)
26-
26+
2727
def print(self):
2828
print("Use Language:", self.language)

infer-web.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,8 @@ def change_info_(ckpt_path):
10691069

10701070

10711071
from infer_pack.models_onnx import SynthesizerTrnMsNSFsidM
1072+
1073+
10721074
def export_onnx(ModelPath, ExportedPath, MoeVS=True):
10731075
cpt = torch.load(ModelPath, map_location="cpu")
10741076
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk

infer_pack/models_onnx.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -633,14 +633,14 @@ def construct_spkmixmap(self, n_speaker):
633633
self.speaker_map = self.speaker_map.unsqueeze(0)
634634

635635
def forward(self, phone, phone_lengths, pitch, nsff0, g, rnd, max_len=None):
636-
if self.speaker_map is not None: # [N, S] * [S, B, 1, H]
636+
if self.speaker_map is not None: # [N, S] * [S, B, 1, H]
637637
g = g.reshape((g.shape[0], g.shape[1], 1, 1, 1)) # [N, S, B, 1, 1]
638638
g = g * self.speaker_map # [N, S, B, 1, H]
639-
g = torch.sum(g, dim=1) # [N, 1, B, 1, H]
640-
g = g.transpose(0, -1).transpose(0, -2).squeeze(0) # [B, H, N]
639+
g = torch.sum(g, dim=1) # [N, 1, B, 1, H]
640+
g = g.transpose(0, -1).transpose(0, -2).squeeze(0) # [B, H, N]
641641
else:
642642
g = g.unsqueeze(0)
643-
g = self.emb_g(g).transpose(1,2)
643+
g = self.emb_g(g).transpose(1, 2)
644644

645645
m_p, logs_p, x_mask = self.enc_p(phone, pitch, phone_lengths)
646646
z_p = (m_p + torch.exp(logs_p) * rnd) * x_mask

0 commit comments

Comments
 (0)