简体   繁体   English

在 Google Colaboratory 上运行 faiss

[英]Running faiss on Google Colaboratory

I am trying to run the simple examples of Faiss on Google Colab but keep get kernel crash and restart.我正在尝试在 Google Colab 上运行 Faiss 的简单示例,但不断导致内核崩溃并重新启动。 The error in the log is : Intel MKL FATAL ERROR: Cannot load libmkl_avx2.so or libmkl_def.so.日志中的错误是:英特尔 MKL 致命错误:无法加载 libmkl_avx2.so 或 libmkl_def.so。 This happens when using both CPU or GPU versions.使用 CPU 或 GPU 版本时会发生这种情况。 Here is the way I installed Faiss on Google collab这是我在 Google collab 上安装 Faiss 的方式

!wget  https://anaconda.org/pytorch/faiss-cpu/1.5.1/download/linux-64/faiss-cpu-1.5.1-py36h6bb024c_1.tar.bz2
!tar xvjf faiss-cpu-1.5.1-py36h6bb024c_1.tar.bz2
!cp -r lib/python3.6/site-packages/* /usr/local/lib/python3.6/dist-packages/
!pip install mkl

The code that I am trying to run is :我试图运行的代码是:

 import numpy as np
    d = 64                           # dimension
    nb = 100000                      # database size
    nq = 10000                       # nb of queries
    np.random.seed(1234)             # make reproducible
    xb = np.random.random((nb, d)).astype('float32')
    xb[:, 0] += np.arange(nb) / 1000.
    xq = np.random.random((nq, d)).astype('float32')
    xq[:, 0] += np.arange(nq) / 1000

import faiss                   # make faiss available
index = faiss.IndexFlatL2(d)   # build the index
print(index.is_trained)
index.add(xb)                  # add vectors to the index
print(index.ntotal)

k = 4                          # we want to see 4 nearest neighbors
D, I = index.search(xb[:5], k) # sanity check
print(I)
print(D)
D, I = index.search(xq, k)     # actual search
print(I[:5])                   # neighbors of the 5 first queries
print(I[-5:])  

The crash happened on this line.车祸发生在这条线上。

D, I = index.search(xq, k)     # actual search

Any ideas?有任何想法吗?

Solution which worked for me:对我有用的解决方案:

!apt install libomp-dev
!python -m pip install --upgrade faiss faiss-gpu
import faiss

I took this code from here我从这里拿了这个代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM