我正在创建反向图像搜索算法,并且正在使用Facebook的FAISS进行相似性搜索。训练后如何将搜索索引保存到文件中?
我尝试了以下代码段:
with open('index', 'a') as file:
file.read('File saved!')
我没有得到所需的结果。
#training the index to create nlist number of clusters so tht vectors are added to these clusters
print(index.is_trained) # False the index has not been trained
index.train(db_vectors) # train on the database vectors
print(index.ntotal) # 0
index.add(db_vectors) # add the vectors and update the index
print(index.is_trained) # True
print(index.ntotal) # 200
with open('index', 'a') as file:
file.write('File saved!')
我希望将索引保存后保存到文件中。