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

猜你喜欢

转载自blog.csdn.net/xiaqinnnn/article/details/83783204