16
16
from i18n import I18nAuto
17
17
18
18
i18n = I18nAuto ()
19
- print (i18n .language_map )
20
19
device = torch .device ("cuda" if torch .cuda .is_available () else "cpu" )
21
20
22
21
@@ -33,10 +32,11 @@ def __init__(
33
32
self .f0_max = 1100
34
33
self .f0_mel_min = 1127 * np .log (1 + self .f0_min / 700 )
35
34
self .f0_mel_max = 1127 * np .log (1 + self .f0_max / 700 )
36
- self .index = faiss .read_index (index_path )
35
+ if index_rate != 0 :
36
+ self .index = faiss .read_index (index_path )
37
+ self .big_npy = np .load (npy_path )
38
+ print ('index search enabled' )
37
39
self .index_rate = index_rate
38
- """NOT YET USED"""
39
- self .big_npy = np .load (npy_path )
40
40
model_path = hubert_path
41
41
print ("load model(s) from {}" .format (model_path ))
42
42
models , saved_cfg , task = checkpoint_utils .load_model_ensemble_and_task (
@@ -112,8 +112,8 @@ def infer(self, feats: torch.Tensor) -> np.ndarray:
112
112
113
113
####索引优化
114
114
if (
115
- isinstance (self . index , type ( None )) == False
116
- and isinstance (self . big_npy , type ( None )) == False
115
+ hasattr (self , 'index' )
116
+ and hasattr (self , 'big_npy' )
117
117
and self .index_rate != 0
118
118
):
119
119
npy = feats [0 ].cpu ().numpy ().astype ("float32" )
@@ -123,6 +123,8 @@ def infer(self, feats: torch.Tensor) -> np.ndarray:
123
123
torch .from_numpy (npy ).unsqueeze (0 ).to (device ) * self .index_rate
124
124
+ (1 - self .index_rate ) * feats
125
125
)
126
+ else :
127
+ print ('index search FAIL or disabled' )
126
128
127
129
feats = F .interpolate (feats .permute (0 , 2 , 1 ), scale_factor = 2 ).permute (0 , 2 , 1 )
128
130
torch .cuda .synchronize ()
0 commit comments