增加向量模型转化成安卓可运行模型的程序
This commit is contained in:
@@ -267,8 +267,11 @@ class FAISSIndexBuilder:
|
||||
|
||||
# 保存标签映射
|
||||
labels_path = os.path.join(output_dir, 'labels.pkl')
|
||||
labels_json_path = os.path.join(output_dir, 'labels.json')
|
||||
with open(labels_path, 'wb') as f:
|
||||
pickle.dump(self.labels, f)
|
||||
with open(labels_json_path, "w", encoding="utf-8") as f:
|
||||
json.dump(self.labels, f, ensure_ascii=False)
|
||||
print(f"标签映射已保存到: {labels_path}")
|
||||
|
||||
# 保存类别信息
|
||||
@@ -288,8 +291,16 @@ class FAISSIndexBuilder:
|
||||
|
||||
# 保存特征向量(可选,用于调试)
|
||||
embeddings_path = os.path.join(output_dir, 'embeddings.npy')
|
||||
embeddings_json_path = os.path.join(output_dir, 'embeddings.json')
|
||||
embeddings_array = np.array(self.embeddings)
|
||||
np.save(embeddings_path, embeddings_array)
|
||||
|
||||
# 转成 Python 列表(JSON 不支持 numpy.array 直接序列化)
|
||||
embeddings_list = embeddings_array.tolist()
|
||||
# 保存成 JSON 文件
|
||||
with open(embeddings_json_path, "w", encoding="utf-8") as f:
|
||||
json.dump(embeddings_list, f, ensure_ascii=False)
|
||||
|
||||
print(f"特征向量已保存到: {embeddings_path}")
|
||||
|
||||
def build_complete_index(self, train_dir: str, output_dir: str,
|
||||
|
||||
Reference in New Issue
Block a user