recunstruct npy
This commit is contained in:
parent
ba650f9be2
commit
b5419d3789
@ -55,14 +55,6 @@
|
||||
"fileKind": "rvcModel"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "commonFileSelect",
|
||||
"options": {
|
||||
"title": "feature(.npy)",
|
||||
"acceptExtentions": ["npy"],
|
||||
"fileKind": "rvcFeature"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "commonFileSelect",
|
||||
"options": {
|
||||
|
@ -55,14 +55,6 @@
|
||||
"fileKind": "rvcModel"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "commonFileSelect",
|
||||
"options": {
|
||||
"title": "feature(.npy)",
|
||||
"acceptExtentions": ["npy"],
|
||||
"fileKind": "rvcFeature"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "commonFileSelect",
|
||||
"options": {
|
||||
|
@ -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)
|
||||
)
|
||||
|
@ -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")
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user