Faiss: How can I save centroid of ProductQuantizer in Python ?

Created on 30 Aug 2018  路  5Comments  路  Source: facebookresearch/faiss

My Problem

I want to save the model of ProductQuantizer for further use, As I understand that means saving centroids of the ProductQuantizer. But can't find a way to do it in Python.

print pq.centroids
print type(pq.centroids)

got these

>

pq.centroids[0] raise exception

TypeError: 'FloatVector' object does not support indexing

My Question

How can I get these data out of faiss.swigfaiss.FloatVector, And how can I read these data and set it back?

Any help would be appreciated

question

Most helpful comment

You can get the centroids via

centroids = faiss.vector_to_array(pq.centroids).reshape(pq.M, pq.ksub, pq.dsub)

And restore with

pq2 = faiss.ProductQuantizer(pq.d, pq.M, pq.nbits)
faiss.copy_array_to_vector(centroids.ravel(), pq2.centroids)

Note that there are also the functions read_ProductQuantizer / write_ProductQuantizer for I/O.

All 5 comments

You can get the centroids via

centroids = faiss.vector_to_array(pq.centroids).reshape(pq.M, pq.ksub, pq.dsub)

And restore with

pq2 = faiss.ProductQuantizer(pq.d, pq.M, pq.nbits)
faiss.copy_array_to_vector(centroids.ravel(), pq2.centroids)

Note that there are also the functions read_ProductQuantizer / write_ProductQuantizer for I/O.

Closing as the issue seems to be resolved.

what about save centroid of ivf in C++,please?

How can I have the centroid of Ivf in c++?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hipitt picture hipitt  路  3Comments

mylyu picture mylyu  路  3Comments

cherryPotter picture cherryPotter  路  3Comments

brunodoamaral picture brunodoamaral  路  3Comments

lukedeo picture lukedeo  路  3Comments