1. 程式人生 > >centos7 安裝faiss_cpu版本

centos7 安裝faiss_cpu版本

開發環境  centos7 64位

1.安裝Anaconda

wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda2-4.3.0-Linux-x86_64.sh
# 修改許可權
chmod +x Anaconda2-4.3.0-Linux-x86_64.sh
# 執行預設安裝,一路Enter鍵。
bash Anaconda2-4.3.0-Linux-x86_64.sh
# 檢測1
conda list 
出現 N多Python依賴包
# 檢測2
python --version
出現帶Anaconda標記的Python,如下:
Python 2.7.13 :: Anaconda custom (64-bit)

2.更新 conda

conda update conda

3.安裝mkl

conda install mkl

4.安裝faiss-cpu

conda install faiss-cpu -c pytorch

5.測試是否安裝成功

python -c "import faiss"

6.官方demo

import numpy as np
import faiss                   # make faiss available
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.

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(xq, k)     # actual search
print(I[:5])                   # neighbors of the 5 first queries
print(D[-5:])                  # neighbors of the 5 last queries

相關網站:https://blog.csdn.net/kanbuqinghuanyizhang/article/details/80774609