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
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
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?
In C++ you can access pq.centroids directly. See https://github.com/facebookresearch/faiss/blob/master/impl/ProductQuantizer.h#L54
How can I have the centroid of Ivf in c++?
Most helpful comment
You can get the centroids via
And restore with
Note that there are also the functions
read_ProductQuantizer/write_ProductQuantizerfor I/O.