From 9be80483021be52fa9e8b81d355d0fe509330532 Mon Sep 17 00:00:00 2001 From: RVC-Boss <129054828+RVC-Boss@users.noreply.github.com> Date: Wed, 26 Apr 2023 19:13:54 +0800 Subject: [PATCH] Total_fea not needed. Better and faster retrieval performance Total_fea not needed now. Better and faster retrieval performance. --- vc_infer_pipeline.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/vc_infer_pipeline.py b/vc_infer_pipeline.py index f85f355..1db5e56 100644 --- a/vc_infer_pipeline.py +++ b/vc_infer_pipeline.py @@ -119,8 +119,15 @@ class VC(object): npy = feats[0].cpu().numpy() if self.is_half: npy = npy.astype("float32") - _, I = index.search(npy, 1) - npy = big_npy[I.squeeze()] + + # _, I = index.search(npy, 1) + # npy = big_npy[I.squeeze()] + + score, ix = index.search(npy, k=8) + weight = np.square(1 / score) + weight /= weight.sum(axis=1, keepdims=True) + npy = np.sum(big_npy[ix] * np.expand_dims(weight, axis=2), axis=1) + if self.is_half: npy = npy.astype("float16") feats = ( @@ -172,21 +179,23 @@ class VC(object): f0_up_key, f0_method, file_index, - file_big_npy, + # file_big_npy, index_rate, if_f0, f0_file=None, ): + print(file_index!= "",os.path.exists(file_index) == True,index_rate != 0) if ( - file_big_npy != "" - and file_index != "" - and os.path.exists(file_big_npy) == True + file_index != "" + # and file_big_npy != "" + # and os.path.exists(file_big_npy) == True and os.path.exists(file_index) == True and index_rate != 0 ): try: index = faiss.read_index(file_index) - big_npy = np.load(file_big_npy) + # big_npy = np.load(file_big_npy) + big_npy = index.reconstruct_n(0, index.ntotal) except: traceback.print_exc() index = big_npy = None