Python faiss.IndexIVFPQ() Examples
The following are 3
code examples of faiss.IndexIVFPQ().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
faiss
, or try the search function
.
Example #1
Source File: run_index.py From denspi with Apache License 2.0 | 6 votes |
def train_index(data, quantizer_path, trained_index_path, fine_quant='SQ8', cuda=False): quantizer = faiss.read_index(quantizer_path) if fine_quant == 'SQ8': trained_index = faiss.IndexIVFScalarQuantizer(quantizer, quantizer.d, quantizer.ntotal, faiss.METRIC_L2) elif fine_quant.startswith('PQ'): m = int(fine_quant[2:]) trained_index = faiss.IndexIVFPQ(quantizer, quantizer.d, quantizer.ntotal, m, 8) else: raise ValueError(fine_quant) if cuda: if fine_quant.startswith('PQ'): print('PQ not supported on GPU; keeping CPU.') else: res = faiss.StandardGpuResources() gpu_index = faiss.index_cpu_to_gpu(res, 0, trained_index) gpu_index.train(data) trained_index = faiss.index_gpu_to_cpu(gpu_index) else: trained_index.train(data) faiss.write_index(trained_index, trained_index_path)
Example #2
Source File: reranking.py From Landmark2019-1st-and-3rd-Place-Solution with Apache License 2.0 | 5 votes |
def __init__(self, database, method, M=128, nbits=8, nlist=316, nprobe=32): super().__init__(database, method) self.quantizer = {'cosine': faiss.IndexFlatIP, 'euclidean': faiss.IndexFlatL2}[method](self.D) self.index = faiss.IndexIVFPQ(self.quantizer, self.D, nlist, M, nbits) samples = database[np.random.permutation(np.arange(self.N))[:self.N]] print("[ANN] train") self.index.train(samples) self.add() self.index.nprobe = nprobe
Example #3
Source File: knn.py From diffusion with MIT License | 5 votes |
def __init__(self, database, method, M=128, nbits=8, nlist=316, nprobe=64): super().__init__(database, method) self.quantizer = {'cosine': faiss.IndexFlatIP, 'euclidean': faiss.IndexFlatL2}[method](self.D) self.index = faiss.IndexIVFPQ(self.quantizer, self.D, nlist, M, nbits) samples = database[np.random.permutation(np.arange(self.N))[:self.N // 5]] print("[ANN] train") self.index.train(samples) self.add() self.index.nprobe = nprobe