From b5419d37895f2962df765f21c50bff1f925aa64f Mon Sep 17 00:00:00 2001 From: wataru Date: Wed, 24 May 2023 15:09:25 +0900 Subject: [PATCH] recunstruct npy --- client/demo/dist/assets/gui_settings/RVC.json | 8 ------- .../demo/public/assets/gui_settings/RVC.json | 8 ------- server/voice_changer/RVC/RVC.py | 2 +- server/voice_changer/RVC/pipeline/Pipeline.py | 24 ++++++++++++++----- .../RVC/pipeline/PipelineGenerator.py | 20 ++++++---------- 5 files changed, 26 insertions(+), 36 deletions(-) diff --git a/client/demo/dist/assets/gui_settings/RVC.json b/client/demo/dist/assets/gui_settings/RVC.json index 3eda5b63..f24b3845 100644 --- a/client/demo/dist/assets/gui_settings/RVC.json +++ b/client/demo/dist/assets/gui_settings/RVC.json @@ -55,14 +55,6 @@ "fileKind": "rvcModel" } }, - { - "name": "commonFileSelect", - "options": { - "title": "feature(.npy)", - "acceptExtentions": ["npy"], - "fileKind": "rvcFeature" - } - }, { "name": "commonFileSelect", "options": { diff --git a/client/demo/public/assets/gui_settings/RVC.json b/client/demo/public/assets/gui_settings/RVC.json index 3eda5b63..f24b3845 100644 --- a/client/demo/public/assets/gui_settings/RVC.json +++ b/client/demo/public/assets/gui_settings/RVC.json @@ -55,14 +55,6 @@ "fileKind": "rvcModel" } }, - { - "name": "commonFileSelect", - "options": { - "title": "feature(.npy)", - "acceptExtentions": ["npy"], - "fileKind": "rvcFeature" - } - }, { "name": "commonFileSelect", "options": { diff --git a/server/voice_changer/RVC/RVC.py b/server/voice_changer/RVC/RVC.py index 9e2f9020..deafe0a2 100644 --- a/server/voice_changer/RVC/RVC.py +++ b/server/voice_changer/RVC/RVC.py @@ -418,7 +418,7 @@ class RVC: self.currentSlot = self.settings.modelSlotIndex def update_model_default(self): - print("[voiceeeeee] UPDATE MODEL DEFAULT!!") + print("[Voice Changer] UPDATE MODEL DEFAULT!!") slotDir = os.path.join( self.params.model_dir, RVC_MODEL_DIRNAME, str(self.currentSlot) ) diff --git a/server/voice_changer/RVC/pipeline/Pipeline.py b/server/voice_changer/RVC/pipeline/Pipeline.py index 3e3b4fc4..fad1b634 100644 --- a/server/voice_changer/RVC/pipeline/Pipeline.py +++ b/server/voice_changer/RVC/pipeline/Pipeline.py @@ -24,7 +24,8 @@ class Pipeline(object): pitchExtractor: PitchExtractor index: Any | None - feature: Any | None + big_npy: Any | None + # feature: Any | None targetSR: int device: torch.device @@ -36,7 +37,7 @@ class Pipeline(object): inferencer: Inferencer, pitchExtractor: PitchExtractor, index: Any | None, - feature: Any | None, + # feature: Any | None, targetSR, device, isHalf, @@ -46,7 +47,10 @@ class Pipeline(object): self.pitchExtractor = pitchExtractor self.index = index - self.feature = feature + self.big_npy = ( + index.reconstruct_n(0, index.ntotal) if index is not None else None + ) + # self.feature = feature self.targetSR = targetSR self.device = device @@ -133,12 +137,20 @@ class Pipeline(object): raise e # Index - feature抽出 - if self.index is not None and self.feature is not None and index_rate != 0: + # if self.index is not None and self.feature is not None and index_rate != 0: + if self.index is not None and self.big_npy is not None and index_rate != 0: npy = feats[0].cpu().numpy() if self.isHalf is True: npy = npy.astype("float32") - D, I = self.index.search(npy, 1) - npy = self.feature[I.squeeze()] + # D, I = self.index.search(npy, 1) + # npy = self.feature[I.squeeze()] + + score, ix = self.index.search(npy, k=8) + weight = np.square(1 / score) + weight /= weight.sum(axis=1, keepdims=True) + + npy = np.sum(self.big_npy[ix] * np.expand_dims(weight, axis=2), axis=1) + if self.isHalf is True: npy = npy.astype("float16") diff --git a/server/voice_changer/RVC/pipeline/PipelineGenerator.py b/server/voice_changer/RVC/pipeline/PipelineGenerator.py index 922ffbbd..ddb39f2a 100644 --- a/server/voice_changer/RVC/pipeline/PipelineGenerator.py +++ b/server/voice_changer/RVC/pipeline/PipelineGenerator.py @@ -1,6 +1,5 @@ import os import traceback -import numpy as np import faiss from voice_changer.RVC.ModelSlot import ModelSlot @@ -47,14 +46,13 @@ def createPipeline(modelSlot: ModelSlot, gpu: int, f0Detector: str): pitchExtractor = PitchExtractorManager.getPitchExtractor(f0Detector) # index, feature - index, feature = _loadIndex(modelSlot) + index = _loadIndex(modelSlot) pipeline = Pipeline( embedder, inferencer, pitchExtractor, index, - feature, modelSlot.samplingRate, dev, half, @@ -67,23 +65,19 @@ def _loadIndex(modelSlot: ModelSlot): # Indexのロード print("[Voice Changer] Loading index...") # ファイル指定がない場合はNone - if modelSlot.featureFile is None or modelSlot.indexFile is None: + if modelSlot.indexFile is None: print("[Voice Changer] Index is None, not used") - return None, None + return None # ファイル指定があってもファイルがない場合はNone - if ( - os.path.exists(modelSlot.featureFile) is not True - or os.path.exists(modelSlot.indexFile) is not True - ): - return None, None + if os.path.exists(modelSlot.indexFile) is not True: + return None try: index = faiss.read_index(modelSlot.indexFile) - feature = np.load(modelSlot.featureFile) except: print("[Voice Changer] load index failed. Use no index.") traceback.print_exc() - return None, None + return None - return index, feature + return index