recunstruct npy
This commit is contained in:
parent
ba650f9be2
commit
b5419d3789
@ -55,14 +55,6 @@
|
|||||||
"fileKind": "rvcModel"
|
"fileKind": "rvcModel"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "commonFileSelect",
|
|
||||||
"options": {
|
|
||||||
"title": "feature(.npy)",
|
|
||||||
"acceptExtentions": ["npy"],
|
|
||||||
"fileKind": "rvcFeature"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "commonFileSelect",
|
"name": "commonFileSelect",
|
||||||
"options": {
|
"options": {
|
||||||
|
@ -55,14 +55,6 @@
|
|||||||
"fileKind": "rvcModel"
|
"fileKind": "rvcModel"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "commonFileSelect",
|
|
||||||
"options": {
|
|
||||||
"title": "feature(.npy)",
|
|
||||||
"acceptExtentions": ["npy"],
|
|
||||||
"fileKind": "rvcFeature"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "commonFileSelect",
|
"name": "commonFileSelect",
|
||||||
"options": {
|
"options": {
|
||||||
|
@ -418,7 +418,7 @@ class RVC:
|
|||||||
self.currentSlot = self.settings.modelSlotIndex
|
self.currentSlot = self.settings.modelSlotIndex
|
||||||
|
|
||||||
def update_model_default(self):
|
def update_model_default(self):
|
||||||
print("[voiceeeeee] UPDATE MODEL DEFAULT!!")
|
print("[Voice Changer] UPDATE MODEL DEFAULT!!")
|
||||||
slotDir = os.path.join(
|
slotDir = os.path.join(
|
||||||
self.params.model_dir, RVC_MODEL_DIRNAME, str(self.currentSlot)
|
self.params.model_dir, RVC_MODEL_DIRNAME, str(self.currentSlot)
|
||||||
)
|
)
|
||||||
|
@ -24,7 +24,8 @@ class Pipeline(object):
|
|||||||
pitchExtractor: PitchExtractor
|
pitchExtractor: PitchExtractor
|
||||||
|
|
||||||
index: Any | None
|
index: Any | None
|
||||||
feature: Any | None
|
big_npy: Any | None
|
||||||
|
# feature: Any | None
|
||||||
|
|
||||||
targetSR: int
|
targetSR: int
|
||||||
device: torch.device
|
device: torch.device
|
||||||
@ -36,7 +37,7 @@ class Pipeline(object):
|
|||||||
inferencer: Inferencer,
|
inferencer: Inferencer,
|
||||||
pitchExtractor: PitchExtractor,
|
pitchExtractor: PitchExtractor,
|
||||||
index: Any | None,
|
index: Any | None,
|
||||||
feature: Any | None,
|
# feature: Any | None,
|
||||||
targetSR,
|
targetSR,
|
||||||
device,
|
device,
|
||||||
isHalf,
|
isHalf,
|
||||||
@ -46,7 +47,10 @@ class Pipeline(object):
|
|||||||
self.pitchExtractor = pitchExtractor
|
self.pitchExtractor = pitchExtractor
|
||||||
|
|
||||||
self.index = index
|
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.targetSR = targetSR
|
||||||
self.device = device
|
self.device = device
|
||||||
@ -133,12 +137,20 @@ class Pipeline(object):
|
|||||||
raise e
|
raise e
|
||||||
|
|
||||||
# Index - feature抽出
|
# 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()
|
npy = feats[0].cpu().numpy()
|
||||||
if self.isHalf is True:
|
if self.isHalf is True:
|
||||||
npy = npy.astype("float32")
|
npy = npy.astype("float32")
|
||||||
D, I = self.index.search(npy, 1)
|
# D, I = self.index.search(npy, 1)
|
||||||
npy = self.feature[I.squeeze()]
|
# 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:
|
if self.isHalf is True:
|
||||||
npy = npy.astype("float16")
|
npy = npy.astype("float16")
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
import traceback
|
import traceback
|
||||||
import numpy as np
|
|
||||||
import faiss
|
import faiss
|
||||||
|
|
||||||
from voice_changer.RVC.ModelSlot import ModelSlot
|
from voice_changer.RVC.ModelSlot import ModelSlot
|
||||||
@ -47,14 +46,13 @@ def createPipeline(modelSlot: ModelSlot, gpu: int, f0Detector: str):
|
|||||||
pitchExtractor = PitchExtractorManager.getPitchExtractor(f0Detector)
|
pitchExtractor = PitchExtractorManager.getPitchExtractor(f0Detector)
|
||||||
|
|
||||||
# index, feature
|
# index, feature
|
||||||
index, feature = _loadIndex(modelSlot)
|
index = _loadIndex(modelSlot)
|
||||||
|
|
||||||
pipeline = Pipeline(
|
pipeline = Pipeline(
|
||||||
embedder,
|
embedder,
|
||||||
inferencer,
|
inferencer,
|
||||||
pitchExtractor,
|
pitchExtractor,
|
||||||
index,
|
index,
|
||||||
feature,
|
|
||||||
modelSlot.samplingRate,
|
modelSlot.samplingRate,
|
||||||
dev,
|
dev,
|
||||||
half,
|
half,
|
||||||
@ -67,23 +65,19 @@ def _loadIndex(modelSlot: ModelSlot):
|
|||||||
# Indexのロード
|
# Indexのロード
|
||||||
print("[Voice Changer] Loading index...")
|
print("[Voice Changer] Loading index...")
|
||||||
# ファイル指定がない場合はNone
|
# ファイル指定がない場合はNone
|
||||||
if modelSlot.featureFile is None or modelSlot.indexFile is None:
|
if modelSlot.indexFile is None:
|
||||||
print("[Voice Changer] Index is None, not used")
|
print("[Voice Changer] Index is None, not used")
|
||||||
return None, None
|
return None
|
||||||
|
|
||||||
# ファイル指定があってもファイルがない場合はNone
|
# ファイル指定があってもファイルがない場合はNone
|
||||||
if (
|
if os.path.exists(modelSlot.indexFile) is not True:
|
||||||
os.path.exists(modelSlot.featureFile) is not True
|
return None
|
||||||
or os.path.exists(modelSlot.indexFile) is not True
|
|
||||||
):
|
|
||||||
return None, None
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
index = faiss.read_index(modelSlot.indexFile)
|
index = faiss.read_index(modelSlot.indexFile)
|
||||||
feature = np.load(modelSlot.featureFile)
|
|
||||||
except:
|
except:
|
||||||
print("[Voice Changer] load index failed. Use no index.")
|
print("[Voice Changer] load index failed. Use no index.")
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return None, None
|
return None
|
||||||
|
|
||||||
return index, feature
|
return index
|
||||||
|
Loading…
x
Reference in New Issue
Block a user