Skip to content

Commit 88a43e1

Browse files
Add non-search inference support. (#82)
Co-authored-by: 源文雨 <[email protected]>
1 parent b0f8a4c commit 88a43e1

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

gui.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from i18n import I18nAuto
1717

1818
i18n = I18nAuto()
19-
print(i18n.language_map)
2019
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
2120

2221

@@ -33,10 +32,11 @@ def __init__(
3332
self.f0_max = 1100
3433
self.f0_mel_min = 1127 * np.log(1 + self.f0_min / 700)
3534
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')
3739
self.index_rate = index_rate
38-
"""NOT YET USED"""
39-
self.big_npy = np.load(npy_path)
4040
model_path = hubert_path
4141
print("load model(s) from {}".format(model_path))
4242
models, saved_cfg, task = checkpoint_utils.load_model_ensemble_and_task(
@@ -112,8 +112,8 @@ def infer(self, feats: torch.Tensor) -> np.ndarray:
112112

113113
####索引优化
114114
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')
117117
and self.index_rate != 0
118118
):
119119
npy = feats[0].cpu().numpy().astype("float32")
@@ -123,6 +123,8 @@ def infer(self, feats: torch.Tensor) -> np.ndarray:
123123
torch.from_numpy(npy).unsqueeze(0).to(device) * self.index_rate
124124
+ (1 - self.index_rate) * feats
125125
)
126+
else:
127+
print('index search FAIL or disabled')
126128

127129
feats = F.interpolate(feats.permute(0, 2, 1), scale_factor=2).permute(0, 2, 1)
128130
torch.cuda.synchronize()

0 commit comments

Comments
 (0)