2023-04-15 13:44:24 +02:00
|
|
|
|
"""
|
2023-03-31 11:49:09 +02:00
|
|
|
|
格式:直接cid为自带的index位;aid放不下了,通过字典来查,反正就5w个
|
2023-04-15 13:44:24 +02:00
|
|
|
|
"""
|
2024-01-26 09:10:04 +01:00
|
|
|
|
|
2023-08-28 09:08:31 +02:00
|
|
|
|
import os
|
2023-09-01 09:18:08 +02:00
|
|
|
|
import logging
|
2023-09-02 05:50:52 +02:00
|
|
|
|
|
2023-09-01 09:18:08 +02:00
|
|
|
|
logger = logging.getLogger(__name__)
|
2023-08-28 09:08:31 +02:00
|
|
|
|
|
|
|
|
|
import faiss
|
|
|
|
|
import numpy as np
|
2023-03-31 11:49:09 +02:00
|
|
|
|
|
|
|
|
|
# ###########如果是原始特征要先写save
|
2023-04-15 13:44:24 +02:00
|
|
|
|
inp_root = r"E:\codes\py39\dataset\mi\2-co256"
|
|
|
|
|
npys = []
|
2023-03-31 11:49:09 +02:00
|
|
|
|
for name in sorted(list(os.listdir(inp_root))):
|
2023-04-15 13:44:24 +02:00
|
|
|
|
phone = np.load("%s/%s" % (inp_root, name))
|
2023-03-31 11:49:09 +02:00
|
|
|
|
npys.append(phone)
|
2023-04-15 13:44:24 +02:00
|
|
|
|
big_npy = np.concatenate(npys, 0)
|
2023-09-01 09:18:08 +02:00
|
|
|
|
logger.debug(big_npy.shape) # (6196072, 192)#fp32#4.43G
|
2023-04-15 13:44:24 +02:00
|
|
|
|
np.save("infer/big_src_feature_mi.npy", big_npy)
|
2023-03-31 11:49:09 +02:00
|
|
|
|
|
|
|
|
|
##################train+add
|
|
|
|
|
# big_npy=np.load("/bili-coeus/jupyter/jupyterhub-liujing04/vits_ch/inference_f0/big_src_feature_mi.npy")
|
2023-09-01 09:18:08 +02:00
|
|
|
|
logger.debug(big_npy.shape)
|
2023-04-15 13:44:24 +02:00
|
|
|
|
index = faiss.index_factory(256, "IVF512,Flat") # mi
|
2023-09-01 09:18:08 +02:00
|
|
|
|
logger.info("Training...")
|
2023-04-15 13:44:24 +02:00
|
|
|
|
index_ivf = faiss.extract_index_ivf(index) #
|
2023-03-31 11:49:09 +02:00
|
|
|
|
index_ivf.nprobe = 9
|
|
|
|
|
index.train(big_npy)
|
2023-04-15 13:44:24 +02:00
|
|
|
|
faiss.write_index(index, "infer/trained_IVF512_Flat_mi_baseline_src_feat.index")
|
2023-09-01 09:18:08 +02:00
|
|
|
|
logger.info("Adding...")
|
2023-03-31 11:49:09 +02:00
|
|
|
|
index.add(big_npy)
|
2023-04-15 13:44:24 +02:00
|
|
|
|
faiss.write_index(index, "infer/added_IVF512_Flat_mi_baseline_src_feat.index")
|
|
|
|
|
"""
|
2023-03-31 11:49:09 +02:00
|
|
|
|
大小(都是FP32)
|
|
|
|
|
big_src_feature 2.95G
|
|
|
|
|
(3098036, 256)
|
|
|
|
|
big_emb 4.43G
|
|
|
|
|
(6196072, 192)
|
|
|
|
|
big_emb双倍是因为求特征要repeat后再加pitch
|
|
|
|
|
|
2023-04-15 13:44:24 +02:00
|
|
|
|
"""
|