16
16
sys .path .append (now_dir )
17
17
from config import Config as MyConfig
18
18
19
- is_half = MyConfig (). is_half
19
+ Config = Config ()
20
20
import PySimpleGUI as sg
21
21
import sounddevice as sd
22
22
import noisereduce as nr
@@ -71,7 +71,7 @@ def __init__(
71
71
)
72
72
self .model = models [0 ]
73
73
self .model = self .model .to (device )
74
- if is_half == True :
74
+ if Config . is_half :
75
75
self .model = self .model .half ()
76
76
else :
77
77
self .model = self .model .float ()
@@ -81,25 +81,24 @@ def __init__(
81
81
cpt ["config" ][- 3 ] = cpt ["weight" ]["emb_g.weight" ].shape [0 ] # n_spk
82
82
self .if_f0 = cpt .get ("f0" , 1 )
83
83
self .version = cpt .get ("version" , "v1" )
84
-
85
84
if self .version == "v1" :
86
85
if self .if_f0 == 1 :
87
86
self .net_g = SynthesizerTrnMs256NSFsid (
88
- * cpt ["config" ], is_half = self . config .is_half
87
+ * cpt ["config" ], is_half = Config .is_half
89
88
)
90
89
else :
91
90
self .net_g = SynthesizerTrnMs256NSFsid_nono (* cpt ["config" ])
92
91
elif self .version == "v2" :
93
92
if self .if_f0 == 1 :
94
93
self .net_g = SynthesizerTrnMs768NSFsid (
95
- * cpt ["config" ], is_half = self . config .is_half
94
+ * cpt ["config" ], is_half = Config .is_half
96
95
)
97
96
else :
98
97
self .net_g = SynthesizerTrnMs768NSFsid_nono (* cpt ["config" ])
99
98
del self .net_g .enc_q
100
99
print (self .net_g .load_state_dict (cpt ["weight" ], strict = False ))
101
100
self .net_g .eval ().to (device )
102
- if is_half == True :
101
+ if Config . is_half :
103
102
self .net_g = self .net_g .half ()
104
103
else :
105
104
self .net_g = self .net_g .float ()
@@ -160,7 +159,7 @@ def infer(self, feats: torch.Tensor) -> np.ndarray:
160
159
torch .cuda .synchronize ()
161
160
with torch .no_grad ():
162
161
logits = self .model .extract_features (** inputs )
163
- feats = model .final_proj (logits [0 ]) if self .version == "v1" else logits [0 ]
162
+ feats = self . model .final_proj (logits [0 ]) if self .version == "v1" else logits [0 ]
164
163
165
164
####索引优化
166
165
try :
@@ -174,7 +173,7 @@ def infer(self, feats: torch.Tensor) -> np.ndarray:
174
173
weight = np .square (1 / score )
175
174
weight /= weight .sum (axis = 1 , keepdims = True )
176
175
npy = np .sum (self .big_npy [ix ] * np .expand_dims (weight , axis = 2 ), axis = 1 )
177
- if is_half == True :
176
+ if Config . is_half :
178
177
npy = npy .astype ("float16" )
179
178
feats = (
180
179
torch .from_numpy (npy ).unsqueeze (0 ).to (device ) * self .index_rate
@@ -220,7 +219,7 @@ def infer(self, feats: torch.Tensor) -> np.ndarray:
220
219
return infered_audio
221
220
222
221
223
- class Config :
222
+ class GUIConfig :
224
223
def __init__ (self ) -> None :
225
224
self .hubert_path : str = ""
226
225
self .pth_path : str = ""
@@ -240,7 +239,7 @@ def __init__(self) -> None:
240
239
241
240
class GUI :
242
241
def __init__ (self ) -> None :
243
- self .config = Config ()
242
+ self .config = GUIConfig ()
244
243
self .flag_vc = False
245
244
246
245
self .launcher ()
0 commit comments