Faiss: TypeError: in method 'IndexFlat_add', argument 3 of type 'float const *'

Created on 26 May 2018  路  1Comment  路  Source: facebookresearch/faiss

Summary

While following the tutorial (linked below), I encountered the following error while trying to add to index.

These are my dimensions for the query and database. They are read from .h5 format to numpy ndarrays.

Shape of Database : (5000000, 512)
Shape of Queries : (42055, 512)

The following is the error.

untitled

These are the relevent lines of code in swigfaiss_gpu.py:
def add(self, n, x):
return _swigfaiss_gpu.IndexFlat_add(self, n, x)

_swigfaiss_gpu is a module imported from a .so file. What is wrong with my installation?

Platform

OS: Ubuntu 14.04.5 LTS
Faiss version: 1.2.1-py36_cuda8.0.61_2 pytorch

Faiss compilation options: -c pytorch

Running on :

  • [ ] CPU
  • [x] GPU

Reproduction instructions

Link to tutorial: https://github.com/facebookresearch/faiss/wiki/Getting-started

You can use any numpy ndarrays of the specified dimensions for this. I used conda install to install faiss on python3.6. swig version is 4.0.0.

After loading the ndarrays,

d = 512
nb = db.shape[0]
nq = queries.shape[0]

index = faiss.IndexFlatL2(d) # build the index
print(index.is_trained)
sys.stdout.flush()
index.add(db) # add vectors to the index <-- ERROR HERE
print(index.ntotal)

Nvidia-smi output

untitled

Most helpful comment

TypeError: ndarrays must be of numpy.float32, and not float64.

Closing issue.

>All comments

TypeError: ndarrays must be of numpy.float32, and not float64.

Closing issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

0DF0Arc picture 0DF0Arc  路  3Comments

Ljferrer picture Ljferrer  路  3Comments

mylyu picture mylyu  路  3Comments

linghuang picture linghuang  路  3Comments

Tony-Hou picture Tony-Hou  路  3Comments