Faiss in python and GPU报错:NotImplementedError: Wrong number or type of arguments for overloaded function 'new_GpuIndexFlatL2'.

Recently, when I was playing faiss, I got an error when I ran this code:

res = faiss.StandardGpuResources()
flat_config = 0
index = faiss.GpuIndexFlatL2(res,d,flat_config)

See above for the error message:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "swigfaiss_gpu.py", line 2958, in __init__
this = _swigfaiss_gpu.new_GpuIndexFlatL2(*args)
NotImplementedError: Wrong number or type of arguments for overloaded function 'new_GpuIndexFlatL2'.
Possible C/C++ prototypes are:
faiss::gpu::GpuIndexFlatL2::GpuIndexFlatL2(faiss::gpu::GpuResources *,faiss::IndexFlatL2 *,faiss::gpu::GpuIndexFlatConfig)
faiss::gpu::GpuIndexFlatL2::GpuIndexFlatL2(faiss::gpu::GpuResources *,faiss::IndexFlatL2 *)
faiss::gpu::GpuIndexFlatL2::GpuIndexFlatL2(faiss::gpu::GpuResources *,int,faiss::gpu::GpuIndexFlatConfig)
faiss::gpu::GpuIndexFlatL2::GpuIndexFlatL2(faiss::gpu::GpuResources *,int)

I suspected it at first because I had installed faiss with conda before, so I simply uninstalled faiss-gpu with conda. Still getting an error after uninstalling.

After searching for a long time, I couldn't find any information. Finally, I looked at the underlying code to solve it.

Now that it's solved, I'll share it with you:

The solution is:

flat_config = faiss.GpuIndexFlatConfig()
flat_config.device = 0

index = faiss.GpuIndexFlatL2(res, d, flat_config)

 

The reason is that the API interface has changed, and the way to specify the GPU card number is different.

in addition:

To install faiss, just download the source code and install it. No need for conda to install the Python version.

When installing, you need to install swig in advance.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325519084&siteId=291194637